Question: You are to time all three sorts with n values from 100 to 5000, in 100 increments. Display these values in a table like

You are to time all three sorts with n values from 100 to 5000, in 100 increments. Display these values in a you will be testing the running times of three sort implementations: mergeSort, insertionSort, and

You are to time all three sorts with n values from 100 to 5000, in 100 increments. Display these values in a table like the following (you might want to display with tabs ("\t") and round your results): N 100 200 300 400 Merge 0.3 0.6 0.8 1.1 Insert 0.4 1.4 2.7 4.3 Bubble 0.7 2.7 5.5 9.8 you will be testing the running times of three sort implementations: mergeSort, insertionSort, and bubbleSort. Start by creating a single Python file. In it, define the three functions given above. Each should take in a single list of integers as a sole parameter. For example: def merge Sort (L) : To test your sorts, create a list of n numbers, and put them in random unsorted order: A [i for i in range (n) ] (A) random.shuffle Pass this list to each sort, and make sure the results come back sorted. Ann of 10 is a good testing length. You don't need to re-create the list each time, but you certainly should reshuffle between tests (some sorts work much faster than normal if the list is already sorted!). In the video/PowerPoint slides, you will find code for mergeSort and insertionSort. You will, however, need to code bubbleSort on your own. A bubble sort works as follows: On a single bubble pass, you run through all the elements in your list from front to back. At each index you compare its value to the value of the next one. For example, if i = 4, then you would compare the value at 4 to the value at 5. If they are out of order, then you swap the values. At the end of one bubble pass, the biggest element will have "bubbled" to the end of the list. To get all elements in order, you make n bubble passes. After you have coded all three and made sure they work, you will perform a timing test. To time a sort, call the time() function (from time import time) right before and right after the sort call. Then subtract the values and multiply by 1000 to get the results in milliseconds. For example: t1 = time() merge Sort (A) B t2 = time() mtime = (t2-t1) *1000

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To perform a timing test for mergeSort insertionSort and bubbleSort with varying values of n and dis... View full answer

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 Programming Questions!