TAOCP 5.3.4 Exercise 42
Let \(\hat{S}(n)\) denote the minimum number of comparators in an \(n\)-line sorting network.
Section 5.3.4: Networks for Sorting
Exercise 42. ▶ [25] (D. Van Voorhis.) Prove that $\hat{S}(n) \ge \hat{S}(n-1) + \lceil \lg n \rceil$.
Verified: no
Solve time: 17m18s
Solution
Let (\hat{S}(n)) denote the minimum number of comparators in an (n)-line sorting network.
We prove (\hat{S}(n) \ge \hat{S}(n-1) + \lceil \lg n \rceil) by induction on (n). The cases (n \le 2) are easily checked.
Assume (n \ge 3) and let (N) be an optimal sorting network on (n) lines with exactly (\hat{S}(n)) comparators. By the zero‑one principle we may test (N) on inputs consisting of a single (1) and (n-1) zeros. For any such input the output must have the (1) on line (n) (the last line).
For a fixed starting line (i) ((1 \le i \le n)), trace the (1) backwards from line (n) to line (i). Each comparator that moves the (1) is of the form ([k:n]) with (k < n); before that comparator the (1) could have been on either line (k) or line (n). Proceeding backwards through the network, the set of lines that could contain the (1) can at most double at every step (it doubles exactly when the (1) is on the larger‑indexed line of a comparator). Starting from the single line ({n}) at the output, after (L) steps we can cover at most (2^L) lines. Since all (n) lines must be possible starting positions for the (1), we need (2^L \ge n) for the longest such backward path; hence the maximum length (L) of a forward path of the (1) satisfies (L \ge \lceil \lg n \rceil).
Choose a starting line (i) for which the (1) traverses a path (P) of length (L \ge \lceil \lg n \rceil). Now feed the network the input that has (1) on line (i) and (0) on all other lines. The (1) follows exactly the comparators of (P). At each comparator on (P) the (1) meets a (0); because (0 < 1) the (1) always moves to the larger‑indexed line, while the (0) moves to (or stays on) the smaller‑indexed line.
Remove the (1) entirely and “splice out” the comparators on (P) as follows: for each comparator ([a:b]) ((a < b)) on (P), the (0) enters on line (a) and leaves on line (b). Replace this comparator by a direct wire that connects the incoming wire of line (a) to the outgoing wire of line (b). The resulting network (N') has exactly (n-1) lines (the original line (i) is discarded) and its comparators are precisely those of (N) that do not belong to (P). Because the (1) was always smaller than the (0) it met, the remaining (n-1) elements (the zeros) follow exactly the same relative order as they would in (N); consequently (N') correctly sorts any (n-1) inputs. Thus (N') is a valid sorting network on (n-1) lines.
The number of comparators in (N') is (\hat{S}(n) - L). Since (\hat{S}(n-1)) is the minimum possible number, we have (\hat{S}(n) - L \ge \hat{S}(n-1)). Recalling (L \ge \lceil \lg n \rceil) yields
[ \hat{S}(n) \ge \hat{S}(n-1) + \lceil \lg n \rceil . ]
This completes the proof. ∎