A visualization of the invocation tree of the recursive quicksort()
function can help understand how it works:
import invocation_tree as ivt
def quicksort(data):
if (len(data) < 2):
return data
pivot = data[0]
return quicksort([i for i in data[1:] if i < pivot]) + \
[pivot] + \
quicksort([i for i in data[1:] if i >= pivot])
data = [49, 97, 53, 5, 33, 65, 62, 51, 100, 38]
tree = ivt.blocking()
print( tree(quicksort, data) )
Visualization made using invocation_tree, I'm the developer. (remove this line if considered self promotion)