Question: Write both insertion sort and merge sort programs in Python and follow the instructions below to test the programs with all data sets provided below.

Write both insertion sort and merge sort programs in Python and follow the instructions below to test the programs with all data sets provided below. You may reuse any existing insertion and recursive merge sorting algorithms available out there without specifying the references.
2-1) Using your time efficiency function from HW1, Measure the execution times of both insertion and merge sorting algorithms using the 6 data files.
2-2) Count the total number of comparisons for the completion of each sorting algorithm.
Here are the set pdf data files you should use for your testing:
1,000,000 integers are in rand1000000.txt (the largest)
Download rand1000000.txt (the largest)
1,000 integers are in rand1000.txt
Download rand1000.txt (for the initial testing purpose)
Other data sets.
rand10000.txt
Download rand10000.txt
rand100000.txt
Download rand100000.txt
rand250000.txt
Download rand250000.txt
rand500000.txt
Download rand500000.txt
2-3) Record the execution time with each data size and display the results in a graph using any Python data visualization library. (matplotlib, plotly, ...).
NOTE 1: For counting the number of comparisons in a mergesort that employs recursive function calls, using a global variable might be more practical, and one of those cases where using a global variable makes more sense.
NOTE 2: Ensure you read the data as integers, not as strings.
NOTE 3: Ensure the second algorithm works with the initial unsorted dataset, not the result dataset sorted by the other algorithm.
NOTE 4: You may add the following lines to test all the data sizes in one test run
fileNames =["rand1000.txt", "rand10000.txt", "rand100000.txt", "rand250000.txt", "rand500000.txt", "rand1000000.txt"]
for name in fileNames :
[your codes ...]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!