Sort list of numbers from lowest number to greatest number using merge sort.
Algorithm:
- Find middle point
- Split unsorted list into two lists (using middle point)
- Split lists until each list has single element (a list containing one element is considered sorted)
- Merge sub-lists to produce new sorted sub-lists until there is only one sub-list remaining. This will be the sorted list.
Sort [5, 1, 4, 2]
[5, 1, 4, 2] Split
[5, 1] [4, 2] Split
[5] [1] [4] [2] All lists are sorted
[1, 5] [2,4] Merge
[1, 2, 4, 5] Merge