Question: In python 3 I need help to time the execution of a sort according to user input. I have the following code, but something it
In python 3
I need help to time the execution of a sort according to user input. I have the following code, but something it wrong because it is taking a really long time to print out the run time when I know it is being sorted a lot fast than that. This is the output I get for sorting an array of size 5 for example:
This is my code:
def insertionSort(arr): # Traverse through 1 to len(arr) for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key Enter a Value to sort between -10,000 and 10,000: 100 Count 100 Your Values Are: [3190, 5993, 7063, -7268, -5327, -9789, 1347, Your Sorted Values Are: [-9789, -9481, -9427, -9199, -9167, -91 Running Time For Input w/ Insertion Sort: 21.377032813 Process finished with exit code 0 Dimport random import timeit =defminsertionSort(arrli # Traverse through 1 to len(arr) for i in range(1, len(arr)): key = arr[i] = i - 1 while j >= 0 and key
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
