Pure Programmer
Blue Matrix


Cluster Map

Project: Merge Sort

The [[Merge sort]] is very efficient sort that was first introduced by [[John von Neumann]] in 1945. It can be implemented very easily using recursion. Write a function that takes a list of integers and sorts the list without modifying it, returning a sorted list, using a merge sort. Test the function by creating a random list of integers, print the random list, sort the list, then print out the sorted list. Accept the number of integers to put in the list and the maximum integer to randomly generate on the command line. What is the worst case performance of the Merge sort?

Output
$ python3 MergeSort.py 10 10 Random List [2, 9, 6, 8, 6, 5, 8, 3, 3, 8] Sorted List [2, 3, 3, 5, 6, 6, 8, 8, 8, 9] $ python3 MergeSort.py 20 100 Random List [92, 50, 34, 75, 34, 14, 48, 49, 85, 3, 24, 5, 20, 1, 12, 44, 77, 96, 98, 94] Sorted List [1, 3, 5, 12, 14, 20, 24, 34, 34, 44, 48, 49, 50, 75, 77, 85, 92, 94, 96, 98]

Solution