Compare how pivot selection and data order affect the number of comparisons
First-element pivot on random data — balanced partitions
First-element pivot on reverse-sorted data — maximally unbalanced
When the pivot splits the array roughly in half each time, we get
log n levels of recursion. Each level does n
comparisons total across all partitions.
With 8 elements: log₂(8) = 3 levels × 8 ≈ ~16 comparisons.
When the pivot is always the smallest (or largest) element, one
partition has n−1 elements and the other has 0.
This gives n levels of recursion.
With 8 elements: 7+6+5+4+3+2+1 = 28 comparisons.