Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Efficiency of sorting algorithms You are to create a program that enables you to

ID: 3835314 • Letter: E

Question

Efficiency of sorting algorithms You are to create a program that enables you to measure the execution times of various sorting algorithms to better understand their efficiency characteristics. For each sorting algorithm, you are to measure and record the execution times for various lists of randomly generated integers. The list sizes used for the test cases should start at 10,000, and go up by 10,000 for each test until the execution time for the test exceeds 60 seconds. The algorithms for which you are to run the tests are: Selection sort Bubble sort Merge sort Tree sort You are to report the execution times obtained for the algorithms in a table with the following format: Execution times in seconds (use 2 decimal digits) List size Selection Sort Bubble sort Merge sort Tree sort 10,000 20,000 30,000

Explanation / Answer

selection sort:

def selectionsort( aList ):

  for i in range( len( aList ) ):

    least = i

    for k in range( i + 1 , len( aList ) ):

      if aList[k] < aList[least]:

        least = k

    swap( aList, least, i )

def swap( A, x, y ):

  tmp = A[x]

  A[x] = A[y]

  A[y] = tmp

Bubble sort:

def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp

alist = [54,26,93,17,77,31,44,55,20]
bubbleSort(alist)
print(alist)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote