LOGBOOK

HELP

Quiz Entry - updated: 2026.12.02

How does quick-sort sort a sequence $S$?

Divide: pick an element $x$ of $S$, the pivot, and split $S$ into $L$ (smaller than $x$), $E$ (equal to $x$) and $G$ (greater than $x$). Recur: sort $L$ and $G$. Conquer: concatenate $L$, $E$ and $G$.

The split creates the property everything else relies on: afterwards every element of $L$ is smaller than every element of $E$, and those are smaller than every element of $G$. Once $L$ and $G$ are sorted on their own, writing them one after the other with $E$ in between gives the sorted sequence, so the conquer step needs no comparisons at all.

$E$ is never sorted again: all its elements are equal, so it is sorted already, and it contains at least the pivot itself. That guarantees progress: $L$ and $G$ together are always at least one element shorter than $S$, so the recursion ends.

In the basic version the pivot is picked at random. That choice decides whether quick-sort is fast or slow: a pivot near the median splits $S$ into two halves, an extreme one splits off nothing.

Go deeper:

From Quiz: ADS / Merge-Sort and Quick-Sort | Updated: Dec 02, 2026