Comparison Sorts
Updated 2026-08-17
Summary
Comparison sorts order data using only pairwise comparisons, and the information-theoretic lower bound shows that any such algorithm needs about n log n comparisons.
Definition
Comparison sorts are algorithms that determine order solely by asking whether one element is less than another. Quicksort, devised by Tony Hoare in 1959, merge sort, described by John von Neumann in 1945, and heapsort, published by J. W. J. Williams in 1964, are the standard examples. A decision-tree argument shows that distinguishing all n! possible orderings requires at least a number of comparisons proportional to n log n, so no comparison sort can beat that bound in the worst case. The bound applies only to comparison-based methods: counting sort and radix sort sidestep it by using the values themselves as addresses.
Introduction
How to use
- Algorithm choice: Check whether values can be used as addresses before defaulting to a comparison sort. - Cost estimate: Use the n log n bound to sanity-check whether a sorting step can fit your budget. - Data-shape check: Ask whether the input is nearly sorted or adversarially ordered before picking an implementation.
Mechanism
Each comparison yields at most one bit of information, because it can only answer yes or no. There are n factorial possible orderings, so identifying the correct one requires at least log base two of n factorial comparisons, and Stirling's approximation turns that into a bound proportional to n log n. Any comparison-based algorithm therefore has to spend at least that many comparisons in the worst case, no matter how cleverly it chooses which pair to compare.
Practice
In progress 0/1Practice this model in one real situation:
Cases
- Quicksort, published by Tony Hoare in 1961, is the default in many standard libraries because of its low overhead on typical inputs.
- Merge sort's guaranteed n log n behaviour makes it the choice for external sorting, where data streams from disk and worst cases must be bounded.
- Database engines often sort by integer keys with radix techniques, avoiding the comparison bound entirely when the key domain is small.
Common pitfalls
- The n log n bound applies only to comparison-based methods, so citing it to reject counting or radix sort is a misreading.
- Choosing purely on average complexity misleads, since quicksort degrades to quadratic time on adversarial input while merge sort needs extra memory.
- The bound is a worst-case statement about comparisons, so it says nothing about constant factors or cache behaviour, which often dominate in practice.
Sources
Source support: Explicit
- github.comhttps://github.com/kcchien/model-thinkingverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS