CST 370 Week 4 Learning Journal Entry

Mergesort 

This week, we learned about the divide-and-conquer algorithm called mergesort. Mergesort uses two processes to sort an array: divide and merge. The algorithm starts off with a division process. Mergesort starts by dividing an array in half and storing each half in its own array. Each of those halves is cut in half again. The process continues until each element in the original array has its own array. The next process is the merge process. In this process, elements in each array are compared and merged in a sorted manner into another array. Two pointers are used to compare elements in each array to see which is greater/smaller. They are then merged into another array in the correct order. This process continues until all elements are in one array. The end result consists of all elements in one array where the elements are sorted in ascending order. The picture below shows this process for an array of numbers. 





Comments

Popular posts from this blog

CST 334 Week 1 Journal Entry

CST 311 Week 8 Journal Entry

CST 311 Week 5 Journal Entry