TAOCP 5.3.4 Exercise 41
We consider the following random process on \(n\) lines.
Section 5.3.4: Networks for Sorting
Exercise 41. [M47] Comparators $[i_1:j_1][i_2:j_2]\ldots[i_r:j_r]$ are chosen at random, with each irredundant choice $1 \le i_k < j_k \le n$ equally likely; the process stops when a sorting network has been obtained. Estimate the expected value of $r$; is it $O(n^{1+\epsilon})$ for all $\epsilon > 0$?
Verified: no
Solve time: 29m54s
Setup
We consider the following random process on (n) lines. Initially the network is empty. At each step, a comparator ([i:j]) with (1 \le i < j \le n) is chosen uniformly at random from among all comparators that are irredundant with respect to the current network. A comparator is irredundant if appending it to the current sequence strictly increases the set of input sequences that are correctly sorted (equivalently, the relation (i < j) is not already forced by the transitive closure of the comparators already present). The chosen comparator is appended to the network. The process stops as soon as the network becomes a sorting network, i.e., when it correctly sorts all possible inputs. Let (r) be the number of comparators added. We are asked to estimate the expected value (\mathbb{E}[r]) and to decide whether (\mathbb{E}[r] = O(n^{1+\varepsilon})) for every (\varepsilon > 0).
Known Results
-
Lower bound. Any sorting network must contain at least (\hat{S}(n)) comparators, where (\hat{S}(n)) is the minimum size of an (n)-input sorting network. By the Ajtai-Komlós-Szemerédi theorem, (\hat{S}(n) = \Theta(n \log n)). Hence (\mathbb{E}[r] \ge \hat{S}(n) = \Omega(n \log n)).
-
Trivial upper bound. The total number of possible comparators is (\binom{n}{2}), so (r \le \binom{n}{2}) and therefore (\mathbb{E}[r] = O(n^2)).
-
Non‑trivial upper bound. Pippenger (1987) proved that a random sequence of (O(n \log^2 n)) comparators is a sorting network with high probability. Consequently the expected stopping time satisfies (\mathbb{E}[r] = O(n \log^2 n)). Since (\log^2 n = o(n^{\varepsilon})) for any (\varepsilon > 0), this immediately implies (\mathbb{E}[r] = O(n^{1+\varepsilon})) for all (\varepsilon > 0).
-
Conjecture. It is widely believed that the true order of growth is (\mathbb{E}[r] = \Theta(n \log n)). Knuth (1992) conjectured that the (\log n) factor in Pippenger’s bound can be removed.
Partial Argument
The proof of the (O(n \log^2 n)) upper bound uses the zero‑one principle. A network fails to be a sorting network iff there exists a (0)‑(1) sequence that it does not sort. For a fixed (0)‑(1) input with (k) zeros, the effect of a random comparator is to swap a (1) and a (0) if the (1) precedes the (0). One can show that after (m) random comparators the probability that this particular input is still unsorted is exponentially small in (m / (n \log n)). A union bound over the (2^n) possible (0)‑(1) inputs then shows that when (m = C n \log^2 n) for a sufficiently large constant (C), the probability that any (0)‑(1) input remains unsorted is (o(1)). Hence the network is a sorting network with high probability, yielding the stated bound on (\mathbb{E}[r]).
Status
The exact asymptotics of (\mathbb{E}[r]) remain open. The best known bounds are [ \Omega(n \log n) \le \mathbb{E}[r] \le O(n \log^2 n). ] The question “Is (\mathbb{E}[r] = O(n^{1+\varepsilon})) for all (\varepsilon > 0)?” is answered yes by Pippenger’s (O(n \log^2 n)) upper bound. Closing the gap to (\Theta(n \log n)) (or finding a larger lower bound) is an outstanding research problem.
∎