First, I create 6 lists of random numbers, where each list has a different length:
arr = [random.randint(1,15000) for _ in range(1000)]
numbersList = [10,100,500,1000,5000,8000]
numbersForBenchmark = []
for i in range(len(numbersList)):
arr = [random.randint(1,15000) for _ in range(numbersList[i])]
numbersForBenchmark.append(arr)
print(numbersForBenchmark)
recursionTimeArray = []
Now I have a recursion QuickSort:
def partition(lst, start, end):
pos = start
for i in range(start, end):
if lst[i] < lst[end]:
lst[i],lst[pos] = lst[pos],lst[i]
pos += 1
lst[pos],lst[end] = lst[end],lst[pos]
return pos
def quick_sort_recursive(lst, start, end):
if start < end:
pos = partition(lst, start, end)
quick_sort_recursive(lst, start, pos - 1)
quick_sort_recursive(lst, pos + 1, end)
And then driver working on all of arrays:
for i in range(len(numbersForBenchmark)):
arrRe = numbersForBenchmark[i]
try:
n = len(arrRe)
start = time.time()
quick_sort_recursive(arrRe,0,n-1)
end = time.time()
rekTime = end - start
recursionTimeArray.append(rekTime)
except RecursionError as re:
print('Problem with recursive depth!)
So as you can see, I measure the time
and put the time into an array. But I need 6 results (I have 6 arrays), but in two examples, I got an error two times:
print('Problem with recursive depth!)
I tried to handle it with:
import sys
sys.setrecursionlimit(1500)
But program finishes somewhere in midde, and I don't get any results.
How Can I fix this?