Quicksort

Also known as: Quick sort, Partition sort

Quicksort picks a pivot, partitions so smaller keys go left and larger go right, then recursively sorts the two sides. It is divide and conquer without a merge step; the work is in the partition.

Average time $O(n \log n)$ with excellent locality; worst case $O(n^2)$ on bad pivots (already sorted with a naive first/last pivot). Randomized or median-of-three pivots, plus a heap-sort fallback (introsort), make worst-case rare in practice. Typical in-place forms are not stable.

Default choice inside many language runtimes for primitives. For guaranteed $O(n \log n)$ and stability, prefer merge sort / timsort.

← Back to CS Glossary