30.2 Quicksort Algorithm

The figure below shows a partition performed on the pivot of 5. Notice how 5 in its “proper place” (in other words, it’s exactly where it should be if the entire array was sorted).

This suggests that the partition procedure can be used recursively on the two halves to the left and to the right of the pivot element.

The properties that partitioning provides inspires Tony Hoare’s Quicksort algorithm.

Quicksort Algorithm

To quicksort N items:

  1. Partition on the leftmost item as the pivot.

  2. Recursively quicksort the left half.

  3. Recursively quicksort the right half.

Last updated