Math 2.0

Computer science Algorithms as mathematical objects Theorem

Comparison sort lower bound

Builds on Sorting algorithmDecision tree modelBinary treeStirling's formulaPermutation

Statement

Let n≥1n \ge 1, and let 𝒜\mathcal{A} be a deterministic comparison sort. Then there is an input of nn distinct elements on which 𝒜\mathcal{A} performs at least ⌈log⁡2(n!)⌉\ceil{\log_2 (n!)} comparisons. Moreover, if the input is a uniformly random ordering of nn distinct elements, the expected number of comparisons of 𝒜\mathcal{A} is at least log⁡2(n!)\log_2 (n!). Since log⁡2(n!)=nlog⁡2n−nlog⁡2e+O(log⁡n)\log_2(n!) = n \log_2 n - n \log_2 e + O(\log n), both bounds are Ω(nlog⁡n)\Omega(n \log n).

Remarks

The proof models 𝒜\mathcal{A} on inputs of size nn as a decision tree: a binary tree whose internal nodes are comparisons and whose leaves are outputs. The n!n! orderings of distinct elements need n!n! different outputs, so the tree has at least n!n! leaves. A binary tree of height hh has at most 2h2^h leaves, so h≥log⁡2(n!)h \ge \log_2(n!), and the height is the worst-case number of comparisons. For the average, a binary tree with LL leaves has average leaf depth at least log⁡2L\log_2 L. The estimate of log⁡2(n!)\log_2(n!) follows from Stirling's formula.

Example: for n=3n = 3, ⌈log⁡26⌉=3\ceil{\log_2 6} = 3, so no comparison sort sorts every list of 33 distinct items with 22 comparisons; 22 comparisons give only 44 possible outcomes, fewer than the 66 orderings. Merge sort uses O(nlog⁡n)O(n \log n) comparisons, so the bound is optimal up to a constant factor.

The hypothesis that only comparisons are used is necessary. Counting sort sorts nn integers in {1,…,k}\set{1, \dots, k} in O(n+k)O(n + k) steps, which is O(n)O(n) when k=O(n)k = O(n), by using the values themselves as array indices.

Going deeper

For a student

This is the standard example of a lower bound in a restricted model of computation, the decision tree model. It shows that merge sort and heapsort are asymptotically optimal among comparison sorts. The average case of randomized quicksort, about 1.39 nlog⁡2n1.39\, n \log_2 n comparisons, is within a constant factor of optimal. The same counting argument shows that finding an element in a sorted list by comparisons needs about log⁡2n\log_2 n steps, matching binary search.

Reading path

To understand this page from the ground up, read these 84 pages in order. The foundations come first.

  1. Big O notation definition
  2. Binary tree concept
  3. Decision tree model concept
  4. Limit point of a set definition
  5. Local maximum definition
  6. Partition of an interval definition
  7. Permutation concept
  8. Sequence definition
  9. Sorting algorithm concept
  10. Little o notation definition
  11. Limit of a function definition
  12. Local minimum definition
  13. Mesh of a partition definition
  14. Riemann sum definition
  15. Real sequence definition
  16. Subsequence definition
  17. Asymptotic equivalence definition
  18. Continuity at a point definition
  19. Derivative definition
  20. Riemann integrable function definition
  21. Bounded sequence definition
  22. Cauchy sequence definition
  23. Geometric sequence definition
  24. Limit of a sequence definition
  25. Monotone sequence definition
  26. Series definition
  27. Continuous function definition
  28. Differentiable function definition
  29. Fermat's theorem on stationary points statement
  30. Limit superior definition
  31. Cauchy sequences are bounded statement
  32. Sum of a finite geometric series statement
  33. Monotone convergence theorem for sequences statement
  34. Convergent sequence definition
  35. Every sequence has a monotone subsequence statement
  36. Pointwise convergence definition
  37. Squeeze theorem statement
  38. Partial sum definition
  39. Power series definition
  40. Intermediate value theorem statement
  41. Differentiable functions are continuous statement
  42. Derivative function definition
  43. Bolzano–Weierstrass theorem statement
  44. The sequence r^n tends to zero for |r| < 1 example
  45. Radius of convergence definition
  46. Convergent series definition
  47. Uniform convergence definition
  48. Sine and cosine definition
  49. Boundedness theorem statement
  50. Product rule statement
  51. Higher derivative definition
  52. Cauchy criterion for sequences statement
  53. Uniform convergence on a set definition
  54. Absolute convergence definition
  55. A series of nonnegative terms converges iff its partial sums are bounded statement
  56. Series of functions definition
  57. Sum of a series definition
  58. Extreme value theorem statement
  59. Continuously differentiable function definition
  60. Uniformly Cauchy sequence of functions definition
  61. Geometric series example
  62. Comparison test statement
  63. Rolle's theorem statement
  64. Root test statement
  65. Ratio test statement
  66. Weierstrass M-test statement
  67. Mean value theorem statement
  68. Cauchy–Hadamard theorem statement
  69. Ratio formula for the radius of convergence statement
  70. Power series converge uniformly on smaller discs inside the radius of convergence statement
  71. Second fundamental theorem of calculus statement
  72. Uniform convergence of derivatives allows term-by-term differentiation statement
  73. The exponential series has infinite radius of convergence statement
  74. Integration by parts statement
  75. Term-by-term differentiation statement
  76. Exponential function definition
  77. Reduction formula concept
  78. e object
  79. Power series are differentiable inside the radius of convergence statement
  80. Derivative of cosine statement
  81. Wallis product statement
  82. pi object
  83. Stirling's formula statement
  84. Comparison sort lower bound statement

Further reading

  1. Web https://en.wikipedia.org/wiki/Comparison_sort
About this page
TagGJTE7GGJ7B
URIm2://GJTE7GGJ7B
Kindstatement, theorem
WritingW0 stub
MSC68P10, 68Q25, 68W40
StatusThis copy of the site has no build data. Run m2 status GJTE7GGJ7B.
AboutSorting algorithm
UsesSorting algorithm, Decision tree model, Binary tree, Stirling's formula, Permutation
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.