Practice Discrete Math

Algorithms / Quicksort Partition

Least You Need to Know: Quicksort Partition Intuition and Pivot Invariants

Quicksort relies on a partition step that rearranges elements around a pivot so recursive calls can sort the left and right sides independently. The key reasoning tools are pivot invariants, the role of balanced partitions in expected speed, and the fact that unlucky pivots can still create quadratic worst-case behavior.

The least you need to know

Key notation

pivot the chosen element used to split the array
partition invariant a maintained statement about which region contains smaller, equal, or larger elements
three-way partition split into `< pivot`, `= pivot`, and `> pivot` regions

Tiny worked example

  • Choose a pivot.
  • Reorder the array so smaller elements go left and larger elements go right.
  • Once partition finishes, the pivot has the correct relative position between the two sides.
  • Then recurse on the left and right subarrays.

Common mistakes

How to recognize this kind of problem

Start practice