Question
(1) Merge Sort and Insertion Sort Programs Implement merge sort and insertion sort to sort an array of integers. You may implement the algorithms in
(1) Merge Sort and Insertion Sort Programs
Implement merge sort and insertion sort to sort an array of integers. You may implement the algorithms in Python, name the programsmergesort and insertsort. Your programs should be able to read inputs from a file called data.txt where the first value of each line is the number of integers that need to be sorted, followed by the integers.
Example values for data.txt:
4 19 2 5 11
8 1 2 3 4 5 6 1 2
The output will be displayed to the terminal.
For the above example the output would be:
2 5 11 19
1 1 2 2 3 4 5 6 8
(2) Merge Sort vs Insertion Sort Running time analysis
Modify code-Now that you have verified that your code runs correctly using the data.txt input file, you can modify the code to collect running time data. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for ten different values of n for example: n = 5000, 10000, 15000, 20,000, ..., 50,000. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data(do not collect times over a minute). Output to the terminal the array size n and time to sort. Name these new programs insertTime and mergeTime.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started