Question: Problem 1 In the programming language of your choice, implement both Insertion Sort and Merge Sort as described in class. Feel free base your code




Problem 1 In the programming language of your choice, implement both Insertion Sort and Merge Sort as described in class. Feel free base your code on implementations that you find online, just ensure that both operate on similar objects and properly cite your sources. Add code to both algorithms that tracks the time it takes to process an input. Please recall our in class discussion about the pseudo-code the book provides for merge sort. The pseudo-code for merge sort that the book provides uses a lot of memory. Why? If you look at it, the function mergeSort () creates copies of the arrays. How many times is mergeSort() called recursively? Quite a bit. If any copies have to be made, it would be much more memory efficient to make those copies in the merge function instead. You will also need to create a method that generates arrays of integers of various sizes and orderings. (a) [10 points ] Run your algorithms on various sized lists of random integers and graph the running time. Does your graph match the theoretical analysis we did in class, explain why or why not? (Try to get to the point where the slower of the two algorithms finishes in more than one second.) (b) [10 points ] Repeat part (a) using already sorted lists of integers. Graph and explain your results. (c) [10 points ] Choose a list size and experimentally determine the numer of array elements that can be out of order before Insertion sort is not longer the faster option. Graph and explain your results. (d) [10 points ] Include your source code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
