Question: Using this code from PYTHON: Attached you will find a pre-writtenPython program called Sort Timer and an Excel spreadsheet called Sort Compare. Modify the Sort
Using this code from PYTHON: Attached you will find a pre-writtenPython program called "Sort Timer" and an Excel spreadsheet called "Sort Compare". Modify the "Sort Timer" program to collect the data to complete the spreadsheet. Adjust the "size" variable in the program to the sizes indicated in the spreadsheet. Replace the Selection sort method in the program with the code for the other sort methods as needed. REMEMBER, you do not need to write or retype the various sort methods. All of the sort methods except for the Radix sort are provided in the zip file of the sample programs for the book (in the "Getting Started" section of the course). The Radix sort will be developed in the weekly discussion. Round all times to the nearest second.
import random import time import sys
sys.setrecursionlimit(2000)
def main():
size = 500 list = [] for i in range(size): list.append(random.randint(0, 100000 - 1))
print("Starting Sort ...") startTime = time.time() selectionSort(list) endTime = time.time() print("Exection time for Selection Sort with", size, "values is: ", endTime - startTime)
# The function for sorting the numbers def selectionSort(list): for i in range(len(list) - 1): # Find the minimum in the list[i..len(list)-1] currentMin = list[i] currentMinIndex = i
for j in range(i + 1, len(list)): if currentMin > list[j]: currentMin = list[j] currentMinIndex = j
# Swap list[i] with list[currentMinIndex] if necessary; if currentMinIndex != i: list[currentMinIndex] = list[i] list[i] = currentMin
main()
The Excel spreadsheet named Sort Compare.xlsx looks as follows:
Sort Methods
| Array size | selection | bubble | merge | quick | heap | raidx | |
| 5,000 | |||||||
| 10,000 | |||||||
| 15,000 | |||||||
| 20,000 | |||||||
| 25,000 | |||||||
| 30,000 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
