Definition · Adversary argumentAn adversary argument proves a lower bound on the number of comparisons any algorithm needs. The adversary answers each comparison the algorithm makes, without fixing the input in advance, subject only to consistency: there must always remain at least one input agreeing with every answer given. If, after fewer than B comparisons, two different answers are still consistent with everything said, the algorithm cannot have determined the result, so B is a lower bound.
Theorem · Finding the maximum needs n − 1 comparisonsAny comparison-based algorithm that reports the maximum of n elements makes at least n − 1 comparisons in the worst case.
Call an element unbeaten if it has not yet lost a comparison. Initially all n are unbeaten. The algorithm can only report a maximum when exactly one element is unbeaten: if two were, the adversary could consistently make either of them the largest, so the reported answer would not be determined.
The adversary answers every comparison between two unbeaten elements arbitrarily but consistently, and every other comparison in whatever way keeps its options open. Each comparison eliminates at most one element from the unbeaten set, since only the loser leaves it.
Going from n unbeaten elements to one therefore takes at least n − 1 comparisons. A single scan makes exactly that many, so the bound is tight.
□
Theorem · Both ends together need ⌈3n/2⌉ − 2Finding the minimum and the maximum of n elements requires at least ⌈3n/2⌉ − 2 comparisons in the worst case, and an algorithm achieves it.
The algorithm is the more instructive half. Pair the elements and compare within each pair, which costs ⌊n/2⌋ comparisons and settles, for each pair, which member can still be the minimum and which can still be the maximum. Then find the minimum among the ⌈n/2⌉ losers and the maximum among the winners, at ⌈n/2⌉ − 1 comparisons each. A pair therefore costs three comparisons for two ends rather than four, and at n = 8 the total is 4 + 3 + 3 = 10 against the 14 of two independent scans.
Theorem · The second largest needs n + ⌈log₂ n⌉ − 2Any algorithm reporting the second largest of n elements makes at least n + ⌈log₂ n⌉ − 2 comparisons in the worst case, and the tournament meets it.
The second largest must have lost to the maximum, because it lost to nobody else. So the algorithm has to find the maximum first, at n − 1 comparisons, and then find the largest among those the maximum beat. A knockout tournament beats the fewest possible: the winner plays ⌈log₂ n⌉ rounds, so only ⌈log₂ n⌉ elements ever lost to it, and picking the best of those costs ⌈log₂ n⌉ − 1 more. At n = 8 that is 7 + 3 − 1 = 9, which is the lab's measured count, and it never exceeds it on any of the 40 320 arrangements the sweep runs.
The misconception the tournament breaks is the natural one: scan the array keeping the best two, which compares each new element with the second best and sometimes with the best as well, and costs up to 2n − 3 — 13 at n = 8, measured at 11 on the lab's array. The tournament's saving is structural rather than clever: it remembers who lost to the winner, so the candidate set is ⌈log₂ n⌉ instead of n − 1.
One row of the lab's table is different in kind from every other figure on this course. At sizes up to eight it runs the tournament on every arrangement of 1 … n — 40 320 of them at n = 8 — and reports the worst count found, whether any exceeded the bound, and whether any returned the wrong element. None exceeded and none was wrong, and the worst equals the bound. That is a claim about every input of that size, which is as close to a quantifier as a measurement gets, and it is still not a claim about every algorithm.
The bound this course cites and does not reprove
Discrete Mathematics' “Searching and Sorting” proves that sorting n elements by comparisons needs at least ⌈log₂ n!⌉ of them, by counting the leaves a decision tree must have. That is the same kind of statement as the three above and it is used here as a thing to reduce to rather than reproved: every panel on this course prints it beside a measured count, and Geometric Algorithms will later reduce sorting to convex hull in order to inherit it.