1. Gyanastra
  2. Algorithms
  3. UGC NET: Lower Bounds and Complexity Theory
  4. Lower Bounds and Comparison Trees
Free lesson, no account needed 12 min read 10 practice questions after it
Asked in past papers4 times
  • GATE CSE202119991990
  • UGC NET2018

Algorithms · UGC NET: Lower Bounds and Complexity Theory

Lower Bounds and Comparison Trees

Overview

A lower bound is the minimum amount of work that any algorithm for a problem must do in the worst case.
In the comparison model, algorithms learn about input elements only by pairwise comparisons, so each algorithm can be drawn as a binary decision tree. This lesson studies how decision-tree height, leaf counting, information-theoretic arguments and adversary arguments prove lower bounds for sorting, searching, selecting maximum/minimum, finding the second smallest, and merging sorted lists.
You need basic binary trees, logarithms, Stirling’s approximation, and the standard algorithms for sorting, scanning and merging before studying this topic.

Key concepts

  • Lower bound of a problem: the minimum number of comparisons any correct algorithm must use for that problem, usually in the worst case. It is not the running time of one particular algorithm.
  • Upper bound: the number of comparisons used by a specific algorithm. When lower and upper bounds have the same order, the bound is tight up to constants.
  • Comparison model: the only allowed operation is comparing two elements. Branching has two outcomes, for example ai<aja_i < a_j or ai>aja_i > a_j for distinct keys.
  • Comparison tree / decision tree: a binary tree whose internal nodes are comparisons, whose branches are comparison outcomes, and whose leaves are possible outputs or permutations.
    Its height equals the worst-case number of comparisons.
  • Reachable leaves: leaves that can actually occur for some valid input. In sorting nn distinct elements, at least n!n! reachable leaves are necessary because there are n!n! possible input orderings.
  • Leaf-height rule: a binary tree of height hh has at most 2h2^h leaves. Therefore, if at least LL leaves are needed, then h≥⌈log⁡2L⌉h \ge \lceil \log_2 L \rceil.
  • Information-theoretic lower bound: count the number of possible outputs or input orders, say LL. Then any comparison tree needs height at least ⌈log⁡2L⌉\lceil \log_2 L \rceil.
  • Adversary argument: an imaginary adversary answers each comparison so as to keep as many candidate answers alive as possible, forcing any algorithm to make many comparisons.
    This often gives a tighter bound than simple output counting.
  • Finding the maximum of nn distinct elements needs exactly n−1n-1 comparisons: every non-maximum must lose at least one comparison.
  • Finding both maximum and minimum: the exact worst-case number is ⌈3n/2⌉−2\lceil 3n/2 \rceil - 2 comparisons. Pair elements, compare within each pair, then send the larger of each pair to the maximum tournament and the smaller to the minimum tournament.
  • Second smallest / second largest: the exact tight worst-case bound is n+⌈log⁡2n⌉−2n+\lceil \log_2 n\rceil-2 comparisons, using a balanced knockout tournament and then checking only the elements that lost directly to the winner.
  • Merging two sorted lists of lengths mm and nn: the exact worst-case lower bound is m+n−1m+n-1 comparisons; for two lists of nn elements each it is 2n−12n-1.
  • Sorting lower bound: comparison-based sorting of nn distinct elements has height at least ⌈log⁡2(n!)⌉\lceil \log_2(n!)\rceil, which is Ω(nlog⁡n)\Omega(n\log n).
  • Non-comparison sorts such as counting sort, radix sort and bucket sort can beat Ω(nlog⁡n)\Omega(n\log n) because they do not rely only on pairwise comparisons.
  • External path length: sum of depths of all leaves, with root depth 00. For LL leaves, a balanced full binary tree minimises this sum.

How it works

  1. Model an algorithm by a decision tree.
    Fix a comparison-based algorithm. Draw each comparison as an internal node. The two answers form two branches. A leaf records the algorithm’s final output. The worst-case number of comparisons is the tree height.

  2. Count the number of possible outputs.
    If the problem has LL distinguishable final outcomes, the tree must have at least LL reachable leaves. A binary tree with height hh cannot have more than 2h2^h leaves, so 2h≥L2^h \ge L and h≥⌈log⁡2L⌉h \ge \lceil \log_2 L \rceil.

  3. Apply this to sorting.
    For nn distinct elements there are n!n! permutations. Hence height h≥⌈log⁡2(n!)⌉h \ge \lceil \log_2(n!)\rceil. By Stirling’s approximation, log⁡2(n!)=Ω(nlog⁡n)\log_2(n!)=\Omega(n\log n). Merge sort uses O(nlog⁡n)O(n\log n) comparisons, so comparison sorting is Θ(nlog⁡n)\Theta(n\log n) in the comparison model.

  4. Use an adversary argument when output counting is not enough.
    The adversary maintains a set of inputs consistent with the answers already given. On each comparison, it answers so that the algorithm cannot eliminate too many candidates. For maximum-finding, each comparison can eliminate at most one element from being maximum, so at least n−1n-1 comparisons are needed.

  5. Find maximum and minimum together.
    Pair the elements: compare each pair once, and label the larger as a “high” and the smaller as a “low”. Find the maximum among the highs, and the minimum among the lows.
    For n=2mn=2m, this uses m+(m−1)+(m−1)=3m−2m+(m-1)+(m-1)=3m-2 comparisons.
    For n=2m+1n=2m+1, use the leftover element as an initial high and low: m+m+m=3mm+m+m=3m comparisons.
    Both cases equal ⌈3n/2⌉−2\lceil 3n/2\rceil-2.

  6. Find the second smallest by a knockout tournament.
    Use n−1n-1 comparisons to find the minimum. Record every element that lost directly to the minimum. The second smallest must be the smallest among these direct losers; any element that lost to someone other than the minimum cannot be second smallest. In a balanced tournament tree, the minimum has at most ⌈log⁡2n⌉\lceil \log_2 n\rceil direct losers. Finding the smallest among them needs ⌈log⁡2n⌉−1\lceil \log_2 n\rceil-1 more comparisons. Total: n+⌈log⁡2n⌉−2n+\lceil \log_2 n\rceil-2.

  7. Merge two sorted lists.
    If one list has mm elements and the other has nn, the exact worst-case lower bound is m+n−1m+n-1. An adversary can answer comparisons so that one list is not exhausted until that many comparisons have been made. The information-theoretic number of interleavings is (m+nm)\binom{m+n}{m}, giving only the weaker bound ⌈log⁡2(m+nm)⌉\lceil \log_2\binom{m+n}{m}\rceil.

  8. Handle the sorted-block variant.
    Suppose nn elements are split into n/kn/k blocks of kk elements each, and all elements of an earlier block are already known to be smaller than all elements of a later block. Then only each block of size kk must be sorted internally. Each block has k!k! possible internal orders, so at least (k!)n/k(k!)^{n/k} leaves are needed. Hence height is at least log⁡2((k!)n/k)=(n/k)log⁡2(k!)=Ω(nlog⁡k)\log_2((k!)^{n/k}) = (n/k)\log_2(k!) = \Omega(n\log k).

Figure. Notice the chain: model the algorithm as a binary decision tree, count L required leaves, use at most 2^h leaves, then conclude h ≥ ceil(log2 L).

Formulas

  • Leaf-height relation: if a binary decision tree has LL reachable leaves and height hh, then 2h≥L2^h \ge L, so h≥⌈log⁡2L⌉h \ge \lceil \log_2 L \rceil.
  • Sorting nn distinct elements: L≥n!L \ge n!, so h≥⌈log⁡2(n!)⌉=Ω(nlog⁡n)h \ge \lceil \log_2(n!)\rceil = \Omega(n\log n).
  • Stirling form: log⁡2(n!)=nlog⁡2n−nlog⁡2e+O(log⁡2n)\log_2(n!) = n\log_2 n - n\log_2 e + O(\log_2 n).
  • Maximum only: n−1n-1 comparisons.
  • Both maximum and minimum: ⌈3n/2⌉−2\lceil 3n/2\rceil-2 comparisons. Some texts write ⌊3n/2⌋−2\lfloor 3n/2\rfloor-2 when assuming nn is even; the exact all-nn formula uses the ceiling.
  • Second smallest or second largest: n+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2 comparisons.
  • Merge mm and nn sorted elements: exact worst case m+n−1m+n-1; equal lengths n,nn,n: 2n−12n-1.
  • Merge interleavings: (m+nm)\binom{m+n}{m} possible merges, so information-theoretic bound is ⌈log⁡2(m+nm)⌉\lceil \log_2\binom{m+n}{m}\rceil. For n=5n=5, (105)=252\binom{10}{5}=252, and ⌈log⁡2252⌉=8\lceil \log_2 252\rceil=8.
  • Search in an ordered array: if “not found” is an outcome, n+1n+1 leaves give lower bound ⌈log⁡2(n+1)⌉\lceil\log_2(n+1)\rceil; for successful search only, nn leaves give ⌈log⁡2n⌉\lceil\log_2 n\rceil.
  • Minimum external path length for LL leaves: let q=⌊log⁡2L⌋q=\lfloor\log_2 L\rfloor and r=L−2qr=L-2^q. Then the balanced tree has 2q−r2^q-r leaves at depth qq and 2r2r leaves at depth q+1q+1, so EPLmin⁡=(2q−r)q+2r(q+1).\text{EPL}_{\min}=(2^q-r)q+2r(q+1).

Worked examples

Example 1. Geeta has 99 distinct marks and wants both the maximum and minimum.
Using the optimal pairwise method: n=9=2(4)+1n=9=2(4)+1. Compare 44 pairs: 44 comparisons. Compare the 44 pair-highs and the leftover to find the maximum: 44 comparisons. Compare the 44 pair-lows and the leftover to find the minimum: 44 comparisons. Total =4+4+4=12=4+4+4=12.
Formula: ⌈3(9)/2⌉−2=⌈13.5⌉−2=14−2=12\lceil 3(9)/2\rceil-2=\lceil 13.5\rceil-2=14-2=12.
Answer: 1212 comparisons.

Example 2. Harish has 1010 distinct marks and wants the second smallest.
Find the smallest by a balanced knockout tournament: 10−1=910-1=9 comparisons. The winner has directly beaten at most ⌈log⁡210⌉=4\lceil\log_2 10\rceil=4 elements. The second smallest is the smallest among these 44 elements, needing 4−1=34-1=3 comparisons. Total =9+3=12=9+3=12.
Formula: 10+⌈log⁡210⌉−2=10+4−2=1210+\lceil\log_2 10\rceil-2=10+4-2=12.
Answer: 1212 comparisons.

Example 3. Merge two sorted arrays of 77 elements each.
Exact tight worst-case bound: 7+7−1=137+7-1=13.
Information-theoretic check: number of interleavings is (147)=3432\binom{14}{7}=3432. Since 211=2048<3432≤4096=2122^{11}=2048<3432\le4096=2^{12}, the information bound is 1212. The exact adversary bound 1313 is stronger.
Answer: exact tight lower bound =13=13; information-theoretic lower bound =12=12.

Example 4. Match List-I with List-II.

List-IList-II
A. Finding maximum of nn elements1. Ω(nlog⁡n)\Omega(n\log n)
B. Finding second largest of nn elements2. n−1n-1
C. Comparison sorting of nn distinct elements3. 2n−12n-1
D. Merging two sorted lists of nn elements each4. n+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2

Matching: A-2, B-4, C-1, D-3.
Reason: maximum needs n−1n-1; second largest uses tournament bound; sorting has information-theoretic height Ω(nlog⁡n)\Omega(n\log n); merging equal-length lists has exact bound 2n−12n-1.

Example 5. A full binary comparison tree has 1111 reachable leaves. Find the minimum possible total external path length.
Here L=11L=11, q=⌊log⁡211⌋=3q=\lfloor\log_2 11\rfloor=3, r=11−8=3r=11-8=3.
Balanced tree: 2q−r=8−3=52^q-r=8-3=5 leaves at depth 33, and 2r=62r=6 leaves at depth 44.
External path length =5⋅3+6⋅4=15+24=39=5\cdot3+6\cdot4=15+24=39.
Answer: 3939.

Comparison

ConceptMeaningExample
Lower boundMinimum comparisons any correct algorithm must useComparison sorting is Ω(nlog⁡n)\Omega(n\log n)
Upper boundComparisons used by a particular algorithmMerge sort uses O(nlog⁡n)O(n\log n)
Tight boundLower and upper bounds have the same orderComparison sorting is Θ(nlog⁡n)\Theta(n\log n)
TechniqueMain ideaStrength and trap
Information-theoretic boundCount possible outputs LL, then use ⌈log⁡2L⌉\lceil\log_2 L\rceilEasy but may be weaker than exact bound
Adversary argumentAnswer comparisons to keep many candidates aliveOften gives exact tight worst-case bound
Decision-tree leaf countA height-hh binary tree has at most 2h2^h leavesWorks only in the comparison model
ProblemExact or asymptotic boundStandard method
Maximum onlyn−1n-1Linear scan
Both maximum and minimum⌈3n/2⌉−2\lceil 3n/2\rceil-2Pair elements, then separate tournaments
Second smallest or second largestn+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2Knockout tournament
Merge mm and nn sorted elementsm+n−1m+n-1Standard merge
Compare-based sortingΩ(nlog⁡n)\Omega(n\log n)Decision tree with n!n! leaves
Search ordered array with “not found”⌈log⁡2(n+1)⌉\lceil\log_2(n+1)\rceilBinary search tree

Revision summary

  • Decision tree: internal nodes are comparisons; leaves are outputs; height is worst-case comparisons.
  • A binary tree of height hh has at most 2h2^h leaves, so h≥⌈log⁡2L⌉h\ge\lceil\log_2 L\rceil.
  • Sorting nn distinct elements needs at least n!n! reachable leaves.
  • Comparison sorting lower bound is Ω(nlog⁡n)\Omega(n\log n); merge sort matches it in order.
  • Non-comparison sorts can beat Ω(nlog⁡n)\Omega(n\log n) because they do not use only pairwise comparisons.
  • Maximum and minimum together: exact bound ⌈3n/2⌉−2\lceil 3n/2\rceil-2; for even nn, this equals ⌊3n/2⌋−2\lfloor 3n/2\rfloor-2.
  • Second smallest or second largest: n+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2.
  • Merging two sorted lists of lengths m,nm,n: exact worst case m+n−1m+n-1; equal n,nn,n gives 2n−12n-1.
  • Information bound for merging is ⌈log⁡2(m+nm)⌉\lceil\log_2\binom{m+n}{m}\rceil, often weaker than the exact adversary bound.
  • Searching an ordered array with “not found” has n+1n+1 outcomes.
  • External path length is the sum of leaf depths; a balanced full binary tree minimises it.
  • Lower bound belongs to the problem; upper bound belongs to a specific algorithm.

Previous-year exam insights

  • Direct concept questions ask for the height of any decision tree that sorts nn elements: the answer is Ω(nlog⁡n)\Omega(n\log n), and the leaf count is n!n!.
  • Numeric questions give nn and ask for ⌈log⁡2(n!)⌉\lceil\log_2(n!)\rceil or compare n!n! with powers of 22.
  • Exact-comparison questions ask for maximum/minimum together or second smallest/largest.
    Check whether nn is even or odd.
  • A common exam option writes ⌊3n/2⌋−2\lfloor 3n/2\rfloor-2 for maximum and minimum.
    For even nn this matches the exact bound; for odd nn the exact all-nn bound is ⌈3n/2⌉−2\lceil 3n/2\rceil-2.
  • Match-the-list questions pair maximum with n−1n-1, second largest with n+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2, sorting with Ω(nlog⁡n)\Omega(n\log n), and merging with 2n−12n-1.
  • Adversary-argument questions expect the idea of answering comparisons to keep many candidates possible, not a specific algorithm trace.
  • Trap: the sorting lower bound Ω(nlog⁡n)\Omega(n\log n) applies only to comparison-based sorting; counting sort and radix sort are not counterexamples.
  • Trap: for merging, the information-theoretic bound can be smaller than the exact tight worst-case bound; do not confuse the two.
  • Check whether the question asks for “necessary” comparisons, meaning a lower bound, or “algorithm uses”, meaning an upper bound.

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  1. Define lower bound, upper bound, comparison tree, decision tree and reachable leaves precisely.
  2. Draw a small comparison tree and count its leaves and height for a given problem.
  3. Prove the comparison-sorting lower bound using n!n! permutations and Stirling’s approximation.
  4. Compute the exact worst-case bound for finding both maximum and minimum, including odd and even nn.
  5. Explain the knockout-tournament method for second smallest and compute n+⌈log⁡2n⌉−2n+\lceil\log_2 n\rceil-2.
  6. Use an adversary argument to justify the m+n−1m+n-1 merging lower bound.
  7. Compute the information-theoretic lower bound for merging and compare it with the exact bound.
  8. Calculate minimum external path length for a given number of leaves.
  9. Solve statement-type and match-the-list questions on maximum, second largest, sorting, searching and merging bounds.
  10. Identify the common traps involving non-comparison sorts, floor versus ceiling, and weak information bounds.

Attempt the sub-topic test first, then the subject test.

Pages 1–2 of 2