79601154

Date: 2025-04-30 22:02:57
Score: 0.5
Natty:
Report link

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) )

quicksort invocation tree

Visualization made using invocation_tree, I'm the developer. (remove this line if considered self promotion)

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: bterwijn