Page tags

Add a new page

Definition

Merge sort sorts an array based on a divide, conquer, and combine strategy. We know that an array of size one is always sorted. We also know that it is trivial to combine two already sorted arrays into one larger array (merge). We can therefore recursively divide the array in half until we reach arrays of size one. Since they are sorted we can consider them conquered because they are sorted. We can now combine them to complete the sorted array.

Algorithm

- Divide your unsorted array in two
- Keep on dividing your arrays until each are of length 1
- Start putting the arrays together in the opposite order. Check to see if the first number in one array is smaller than the first in the other. Whichever is smaller set the first number in the combined array to it and go to the next digit in which you placed in the array and repeat until the array is finished. Once one array is completed fill in the rest of the numbers with the other array.