I have recently been refreshing my knowledge about the quick-sort algorithm. I am aware that a list (Python) is passed by reference so that any changes made to its entries are reflected outside the function call. The algorithm uses recursion without a return statement. I want to know what happens after the function reaches the end of its body. The return statement, if present, passes a value back to the immediate caller before "popping" off the stack (correct me if i am wrong). This continues to happen until the last caller is reached. If there is no return call, then does the aforementioned process happen?
def quick_sort(arr,low,high):
# the Breaking statement
if (low < high):
# Partitoning
div = partition(arr,low,high)
quick_sort(arr,low,div)
quick_sort(arr,div+1,high)
def partition(arr,low,high):
pivot = arr[low]
minIndex = low;
for i in range(low+1,high):
if arr[i] <= pivot:
minIndex += 1
arr[minIndex],arr[i] = arr[i],arr[minIndex]
arr[minIndex],arr[low] = pivot,arr[minIndex];
return minIndex