import random import time def quick_sort(alist): quick_sort_helper(alist,0,len(alist)-1) # a recursive quick sort method def quick_sort_helper(alist,first,last): if first<last: splitpoint = partition(alist,first,last) quick_sort_helper(alist,first,splitpoint-1) quick_sort_helper(alist,splitpoint+1,last) # to partition the given list by # (1) picking the first int as the pivot value # (2) re-arrange all integers accoding to the pivot value def partition(alist,first,last): pivotvalue = alist[first] leftmark = first+1 rightmark = last done = False while not done: while leftmark <= rightmark and \ alist[leftmark] <= pivotvalue: leftmark = leftmark + 1 while alist[rightmark] >= pivotvalue and \ rightmark >= leftmark: rightmark = rightmark -1 if rightmark < leftmark: done = True else: # exchange integers pointed by the # leftmark and rightmarks temp = alist[leftmark] alist[leftmark] = alist[rightmark] alist[rightmark] = temp temp = alist[first] alist[first] = alist[rightmark] alist[rightmark] = temp return rightmark def bubble_sort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: alist[i],alist[i+1] = alist[i+1],alist[i] def do_quick_sort(alist): integer = random.randint(0, 1000) quick_sort(alist) def do_bubble_sort(seq): integer = random.randint(0, 1000) bubble_sort(alist) def main(): alist=list(range(1,1000)) start1=time.time() quick=do_quick_sort(alist) end1=time.time() time_interval1=end1-start1 print("Quick sort:",time_interval1) start2=time.time() bubble=do_bubble_sort(alist) end2=time.time() time_interval2=end2-start2 print("Bubble sort:",time_interval2) main()

So im trying to test which sorting method is better but its not working.

I keep getting this error: builtins.RuntimeError: maximum recursion depth exceeded in comparison because of this line quick=do_quick_sort(alist) and this line bubble=do_bubble_sort(alist)

Can I please get some help.

I dont know if this will help be these are the steps I was given:

1. Generate a list with n randomly chosen integers by using

random.randint(x,y)

2. Use list2 = list(list1) to reproduce the list you got from step 1.

3. Use the code we give on next page to count the runtime of each

sorting function.

4. Print the runtime for each sorting function on screen.

5. Change n to some different values and redo this experiment.