Pretty vague because I checked the correct inference for reasonably small test sites (N = 20). I'm trying to make N = 10,000 numbers, and the program just freezes, and I donβt understand why ... I implemented the algorithm as simple as possible.
Also, the call sorted(data)on my N = 10k list seems almost instantaneous. Therefore, I am convinced that my algorithm just got stuck somewhere.
Here is the code:
def QuickSort(array):
qsort(array, 0, len(array))
def qsort(arr, left, right):
if ((right - left) < 2):
return
pivotIndex = choosePivot0(arr, left, right)
newPivotIndex = partition(arr, pivotIndex, left, right)
qsort(arr, 0, newPivotIndex)
qsort(arr, newPivotIndex + 1, right)
def partition(arr, pivotIndex, left, right):
swap(arr, pivotIndex, left)
pivot = arr[left]
i = left + 1
for j in range(left+1, right):
if (arr[j] < pivot):
swap(arr, i, j)
i = i + 1
swap(arr, left, i-1)
return (i-1)
def swap(array, i, j):
temp = array[i]
array[i] = array[j]
array[j] = temp
def choosePivot0(array, left, right):
return randint(left, right-1)
So, I pretty much lost why this could happen. Thanks for any help.