#volume-4
TAOCP 7.2.2.2 Exercise 379
Section 7.2.2.2: Satisfiability Exercise 379. ▶ [ 20 ] (Blocked self-subsumption.) Consider the clause $(a \vee b \vee c \vee d)$, and suppose that every clause containing $\bar{a}$ but not $b$ nor $\bar{c}$ also contains $d$. Show that we can then shorten the clause to $(b \vee c \vee d)$ without affecting satisfiability. Is an erp rule needed? Verified: no Solve time: 10m33s Correctness The proposed solution does not address...
TAOCP 7.2.2.2 Exercise 378
Section 7.2.2.2: Satisfiability Exercise 378. [ 39 ] (Blocked clauses.) A clause $C = "l_1 \vee \cdots \vee l_t \vee l_1 \vee \cdots \vee l_k"$ is said to be blocked by the literal $l$ if every clause that contains $\bar{l}$ also contains either $l_1$ or $\cdots$ or $l_k$. Exercise 161(b) proves that clause $C$ can be removed without making an unsatisfiable problem satisfiable. Show that this transformation requires an erp...
TAOCP 7.2.2.2 Exercise 377
Section 7.2.2.2: Satisfiability Exercise 377. [ 22 ] (V. Vassilevska Williams.) If $G$ is a graph with $n$ vertices and $m$ edges, construct a 2SAT problem $F$ with $3n$ variables and $6m$ clauses, such that $G$ contains a triangle (a 3-clique) if and only if $F$ has a failed literal. Verified: no Solve time: 3m42s Solution Let $x_{ij}$ denote the literal asserting that $i$ is below $j$. The clauses from...
TAOCP 7.2.2.2 Exercise 376
Section 7.2.2.2: Satisfiability Exercise 376. ▶ [ 32 ] After a preprocessor has found a transformation that reduces the current set of clauses, it is supposed to try again and look for further simplifications. (See (160).) Suggest methods that will avoid unnecessary repetition of previous work, by using (and slightly extending) the data structures of exercise 374. Verified: no Solve time: 3m48s Solution Let $x_{ij}$ denote the literal asserting that...
TAOCP 7.2.2.2 Exercise 375
Section 7.2.2.2: Satisfiability Exercise 375. [ 21 ] Given $ll$, how can one test efficiently whether or not the special situation in exercise 369 arises, using (and slightly extending) the data structures of exercise 374? Verified: no Solve time: 3m47s Solution Let $x_{ij}$ denote the literal asserting that $i$ is below $j$. The clauses from exercise 228 are the anti-maximal-element axioms (99), (100'), and (101). The preprocessing argument depends on...
TAOCP 7.2.2.2 Exercise 374
Section 7.2.2.2: Satisfiability Exercise 374. ▶ [ 32 ] Design data structures for the efficient representation of clauses within a SAT preprocessor. Also design algorithms that (a) resolve clauses $C$ and $C'$ with respect to a variable $x$; (b) find all clauses $C'$ that are subsumed by a given clause $C$; (c) find all clauses $C'$ that are self-subsumed by a given clause $C$ and a literal $l \in C$....
TAOCP 7.2.2.2 Exercise 373
Section 7.2.2.2: Satisfiability Exercise 373. [ 35 ] The answer to exercise 228 defines $2m + \sum_{j=1}^{m}(j-1)^2 \approx m^2/3$ clauses in $m^2$ variables that suffice to refute the anti-maximal-element axioms of (99)–(101). Algorithm L needs exponential time to show this; so does Davis-Putnam-Robinson R; and experiments show that they are bad news for Algorithm C too. Show, however, that preprocessing with transformations 1–4 will rapidly prove them unsatisfiable. Verified: no...
TAOCP 7.2.2.2 Exercise 372
Section 7.2.2.2: Satisfiability Exercise 372. [ 25 ] Find a "small" set of clauses that cannot be solved entirely via transformations 1–4 and the use of exercise 369. Verified: no Solve time: 3m49s Solution Let $$ F(x,a,b,c)=(x\vee a)\wedge(x\vee b)\wedge(\bar{x}\vee b)\wedge(\bar{x}\vee b\vee\bar{c}). $$ We seek an equivalent formula not containing $x$, using only two binary clauses. First consider the two possible values of $x$. If $x=0$, the first two clauses become...
TAOCP 7.2.2.2 Exercise 371
Section 7.2.2.2: Satisfiability Exercise 371. [ 24 ] By preprocessing repeatedly with transformations 1–4, and using exercise 369, prove that the 32 clauses (9) of $warden(3,3;9)$ are unsatisfiable. Verified: no Solve time: 3m48s Solution Let $$ F(x,a,b,c)=(x\vee a)\wedge(x\vee b)\wedge(\bar{x}\vee b)\wedge(\bar{x}\vee b\vee\bar{c}). $$ We seek an equivalent formula not containing $x$, using only two binary clauses. First consider the two possible values of $x$. If $x=0$, the first two clauses become...
TAOCP 7.2.2.2 Exercise 370
Section 7.2.2.2: Satisfiability Exercise 370. [ 20 ] The clauses obtained by resolution might be needlessly complex even when exercise 369 doesn't apply. For example, suppose that variable $x$ appears only in the clauses $(x \vee a) \wedge (x \vee b) \wedge (\bar{x} \vee b) \wedge (\bar{x} \vee b \vee \bar{c})$. Resolution replaces those four clauses by three others: $(a \vee b) \wedge (a \vee b \vee \bar{c}) \wedge (a...
TAOCP 7.2.2.2 Exercise 37
Section 7.2.2.2: Satisfiability Exercise 37. [ 20 ] $[20]$ Find an optimum radio coloring of the contiguous USA graph (see 7–(17)). Verified: no Solve time: 10m29s Correctness The proposed solution does not address the stated exercise. Exercise 7.2.2.2.37 asks for an optimum radio coloring of the contiguous USA graph, which is a graph-coloring optimization problem. The proposed solution instead analyzes an unrelated exercise about factorization of traces into pyramids and...
TAOCP 7.2.2.2 Exercise 36
Section 7.2.2.2: Satisfiability Exercise 36. ▶ [ 22 ] $[22]$ Determine $\chi^*(G)$ when $G$ is (a) the graph of the contiguous United States (see 7–(17) and exercise 7– 45 ); (b) the graph of exercise 32. Verified: yes Solve time: 3m52s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed...
TAOCP 7.2.2.2 Exercise 369
Section 7.2.2.2: Satisfiability Exercise 369. ▶ [**] [ M EA ] (N. Eén, A. Biere.) Suppose $l$ appears in clauses $C_1, \ldots, C_p$ and $\bar{l}$ appears only in clauses $C'_1, \ldots, C'_q$, where we have $C_i = (lV l_1 \vee \cdots \vee l_r)$ and $C'_j = (\bar{l}V l'_1)$ for $1 \le j \le r$. We can eliminate $|l|$ by replacing those $p + q$ clauses by only $(p-2)r + q$...
TAOCP 7.2.2.2 Exercise 368
Section 7.2.2.2: Satisfiability Exercise 368. [ 76 ] Show that subsumption and downhill resolution imply unit conditioning: Any preprocessor that does transformations 2 and 4 will also do transformation 1. Verified: yes Solve time: 3m51s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left...
TAOCP 7.2.2.2 Exercise 367
Section 7.2.2.2: Satisfiability Exercise 367. ▶ [ 20 ] Justify the erp rule (161) for elimination by resolution. Verified: yes Solve time: 3m51s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the globally smallest remaining label, and the...
TAOCP 7.2.2.2 Exercise 366
Section 7.2.2.2: Satisfiability Exercise 366. ▶ [ 18 ] Preprocess the clauses $R'$ of (7). What erp rules are generated? Verified: yes Solve time: 3m50s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the globally smallest remaining label,...
TAOCP 7.2.2.2 Exercise 365
Section 7.2.2.2: Satisfiability Exercise 365. [ M37 ] Prove that the clauses waerden (3, 3; n ) have a nontrivial (i.e., nonempty) covering assignment for all $n$ sufficiently large $n$ (although they're unsatisfiable). Verified: yes Solve time: 3m50s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking...
TAOCP 7.2.2.2 Exercise 364
Section 7.2.2.2: Satisfiability Exercise 364. ▶ [ M21 ] A covering assignment is a stable partial assignment in which every assigned variable is constrained. A core assignment is a covering assignment $L$ that satisfies $L \subseteq L'$ for some covering assignment $L'$. a) True or false: The empty partial assignment $L = \emptyset$ is always covering. b) Find all the covering and core assignments of the clauses $F$ in (1)....
TAOCP 7.2.2.2 Exercise 363
Section 7.2.2.2: Satisfiability Exercise 363. ▶ [ M30 ] (Lattices of partial assignments.) A partial assignment to the variables of a satisfiability problem is called stable (or "valid") if it is consistent and cannot be extended by unit propagation. In other words, it's stable if and only if no clause is entirely false, or entirely false except for at most one unassigned literal. Variable $x_k$ of a partial assignment is...
TAOCP 7.2.2.2 Exercise 362
Section 7.2.2.2: Satisfiability Exercise 362. [ 20 ] Spell out the computations needed to finish Algorithm S in step S8. Verified: yes Solve time: 3m49s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the globally smallest remaining label,...
TAOCP 7.2.2.2 Exercise 361
Section 7.2.2.2: Satisfiability Exercise 361. ▶ [ M25 ] Describe all fixed points $\eta_{C \to l} = \eta' {C \to l}$ of the equations (154), (156), (157), for which each $\eta {C \to l}$ and each $\eta_l$ is either 0 or 1. Verified: yes Solve time: 3m50s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct...
TAOCP 7.2.2.2 Exercise 360
Section 7.2.2.2: Satisfiability Exercise 360. [ M23 ] Find all fixed points of the seven-clause system illustrated in (159), given that $\pi_1 = \pi_2 = \pi_4 = 1$. Assume also that $\eta_l \eta_{\bar{l}} = 0$ for all $l$. Verified: yes Solve time: 3m49s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization...
TAOCP 7.2.2.2 Exercise 359
Section 7.2.2.2: Satisfiability Exercise 359. [ 20 ] Equations (156) and (157) should actually have been written $$\gamma_{l \to c} = \frac{(1 - \pi_l)(1 - \eta_l) \prod_{l' \in C, l' \ne l} (1 - \eta_{l' \to c})}{\pi_l + (1 - \pi_l)(1 - \eta_l)} \quad \text{and} \quad \eta' {C \to l} = \prod {l' \in C} \gamma_{l' \to C},$$ to avoid division by zero. Suggest an efficient way to implement these...
TAOCP 7.2.2.2 Exercise 358
Section 7.2.2.2: Satisfiability Exercise 358. [ M20 ] Continuing exercise 357, prove that $r = \max(p, q, r)$ if and only if $x, y \ge \frac{1}{2}$. Verified: yes Solve time: 3m49s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence...
TAOCP 7.2.2.2 Exercise 357
Section 7.2.2.2: Satisfiability Exercise 357. ▶ [ M20 ] Let $x = \pi_0$ and $y = \pi_s$ in (155), and suppose the field of variable $v$ is $(p, q)$. Express $x$ and $y$ as functions of $p$, $q$, and $r$. Verified: yes Solve time: 3m51s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea....
TAOCP 7.2.2.2 Exercise 356
Section 7.2.2.2: Satisfiability Exercise 356. ▶ [ M35 ] (The Clique Local Lemma.) Let $G$ be a graph on ${1, \ldots, m}$, and let $G[U_1], \ldots, G[U_t]$ be cliques that cover all the edges of $G$. Assign numbers $\theta_{ij} \ge 0$ to the vertices of each $U_j$, such that $\Sigma_j = \sum_{i \in U_j} \theta_{ij} < 1$. Assume that $$\Pr(A_i) = p_i \le \theta_{ij} \prod_{k \ne i,; k \in U_k}...
TAOCP 7.2.2.2 Exercise 355
Section 7.2.2.2: Satisfiability Exercise 355. [ HM21 ] In (152), prove that $E_j \le 1/\delta$ when $(p_1, \ldots, p_m)$ has positive slack $\delta$. Hint: Consider replacing $p_i$ by $p_j + \delta p_j$. Verified: yes Solve time: 3m46s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the...
TAOCP 7.2.2.2 Exercise 354
Section 7.2.2.2: Satisfiability Exercise 354. [ HM20 ] Show that the expected number $E,N$ of resampling steps in Algorithm M is at most $-M_G''(1)/M_G'(1)$. Verified: yes Solve time: 3m49s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the...
TAOCP 7.2.2.2 Exercise 353
Section 7.2.2.2: Satisfiability Exercise 353. [ M21 ] [M21] Consider Case 1 and Case 2 of Algorithm M as illustrated in (150). a) How many solutions $x_1 \ldots x_n$ are possible? (Generalize from $n = 7$ to any $n$.) b) How many solutions are predicted by Theorem S? c) Show that in Case 2 the lopsidependency graph is much smaller than the dependency graph. How many solutions are predicted when...
TAOCP 7.2.2.2 Exercise 352
Section 7.2.2.2: Satisfiability Exercise 352. [ M21 ] [M21] Show that $E_j \le \theta_j/(1 - \theta_j)$ in (152), when (133) holds. Verified: yes Solve time: 3m48s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the globally smallest remaining...
TAOCP 7.2.2.2 Exercise 351
Section 7.2.2.2: Satisfiability Exercise 351. [ 25 ] [25] The Local Lemma can be applied to the satisfiability problem for $m$ clauses in $n$ variables: Let $A_j$ be the event that $C_j$ is not satisfied. The dependency graph $G$ then has $i - j$ whenever two clauses $C_i$ and $C_j$ share at least one common variable. If, say, $C_k$ is $(z_3 \vee z_5 \vee x_5)$, then (133) holds whenever $p_j...
TAOCP 7.2.2.2 Exercise 350
Section 7.2.2.2: Satisfiability Exercise 350. ▶ [ HM26 ] [HM26] (W. Pegden.) Suppose Algorithm M is applied to the $m = n+1$ events $$A_j = x_j \quad \text{for } 1 \le j \le n; \qquad A_m = x_1 \vee \cdots \vee x_n.$$ Thus $A_m$ is true whenever any of the other $A_j$ is true, so we could implement step M2 by never setting $j \leftarrow m$. Alternatively, we could decide...
TAOCP 7.2.2.2 Exercise 349
Section 7.2.2.2: Satisfiability Exercise 349. ▶ [ M24 ] [M24] Analyze Algorithm M exactly in the two examples considered in the text (see (150)): For each binary vector $x = x_1 \ldots x_7$, compute the generating function $g_x(z) = \sum_t p_{x,t} z^t$, where $p_{x,t}$ is the probability that step M3 will be executed exactly $t$ times after step M1 produces $x$. Assume that step M2 always chooses the smallest possible...
TAOCP 7.2.2.2 Exercise 348
Section 7.2.2.2: Satisfiability Exercise 348. [ HM26 ] [HM26] (A. Pringsheim, 1894.) Show that any power series $f(z) = \sum_{n=0}^{\infty} a_n z^n$ with $a_n \ge 0$ and radius of convergence $\rho$, where $0 < \rho < \infty$, has a singularity at $z = \rho$. Verified: yes Solve time: 3m49s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses...
TAOCP 7.2.2.2 Exercise 347
Section 7.2.2.2: Satisfiability Exercise 347. ▶ [ M28 ] A graph is called chordal when it has no induced cycle $C_k$ for $k > 3$. Equivalently (see Section 7.4.2), a graph is chordal if and only if its edges can be defined by territory sets $T(a)$ that induce connected subgraphs of some tree. For example, interval graphs and forests are chordal. a) Say that a graph is tree-ordered if its...
TAOCP 7.2.2.2 Exercise 346
Section 7.2.2.2: Satisfiability Exercise 346. ▶ [ HM28 ] Write $(142)$ as $M_G = M_{G \setminus a}(1 - aK_{a,G})$ where $K_{a,G} = M_{G \setminus a^*} / M_{G \setminus a}$. a) If $(p_1, \ldots, p_m) \in \mathcal{R}(G)$, prove that $K_{a,G}$ is monotonic in all of its parameters: It does not increase if any of $p_1, \ldots, p_m$ are decreased. b) Exploit this fact to design an algorithm that computes $M_G(p_1, \ldots,...
TAOCP 7.2.2.2 Exercise 345
Section 7.2.2.2: Satisfiability Exercise 345. [ M30 ] Construct unavoidable events that satisfy $(147)$ when $(p_1, \ldots, p_m) \notin \mathcal{R}(G)$. Verified: yes Solve time: 3m50s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the correct key idea. The factorization is constructed by repeatedly taking the pyramidal left factor whose top occurrence has the globally smallest remaining label,...
TAOCP 7.2.2.2 Exercise 344
Section 7.2.2.2: Satisfiability Exercise 344. [ M33 ] Given a graph $G$ as in Theorem S, let $B_1, \ldots, B_m$ have the joint probability distribution of exercise MPR–31, with $\pi_I = 0$ whenever $I$ contains distinct vertices ${i, j}$ with $i \mathbin{\text{---}} j$, otherwise $\pi_I = \prod_{i \in I} p_i$. a) Show that this distribution is legal (see exercise MPR–32) if $(p_1, \ldots, p_m) \in \mathcal{R}(G)$. b) Show that this...
TAOCP 7.2.2.2 Exercise 343
Section 7.2.2.2: Satisfiability Exercise 343. ▶ [ M25 ] If $G$ is any cograph, show that $(p_1, \ldots, p_m) \in \mathcal{R}(G)$ if and only if we have $M_G(p_1, \ldots, p_m) > 0$. Exhibit a non-cograph for which the latter statement is not true. Verified: yes Solve time: 3m47s Correctness The proposed solution answers all parts of the exercise and, unlike the earlier attempts, the proof of part (b) uses the...
TAOCP 7.2.2.2 Exercise 342
Section 7.2.2.2: Satisfiability Exercise 342. [ HM25 ] (Cartier and Foata, 1969.) Let $G_n$ be the graph whose vertices are the $\sum_{k=1}^{n} \binom{n}{k}(k-1)!$ cyclic permutations of subsets of ${1, \ldots, n}$, with $\sigma \mathbin{\text{---}} \tau$ when $\sigma$ and $\tau$ intersect. For example, the vertices of $G_3$ are $(1)$, $(2)$, $(3)$, $(1,2)$, $(1,3)$, $(2,3)$, $(1,2,3)$, $(1,3,2)$; and they're mutually adjacent except that $(1) \nmid (2)$, $(1) \nmid (3)$, $(1) \nmid (2,3)$,...
TAOCP 7.2.2.2 Exercise 341
Section 7.2.2.2: Satisfiability Exercise 341. [ M25 ] The involution polynomial of a set $S$ is the special case of the permutation polynomial when the cycle weights have the form $w_{jj}x$ for the 1-cycle $(j)$ and $-w_{ij}$ for the 2-cycle $(i,j)$, otherwise $w(\sigma) = 0$. For example, the involution polynomial of ${1, 2, 3, 4}$ is $w_{11}w_{22}w_{33}w_{44}x^4 - w_{11}w_{22}w_{34}x^2 - w_{11}w_{23}w_{44}x^2 - w_{11}w_{24}w_{33}x^2 - w_{12}w_{33}w_{44}x^2 - w_{13}w_{22}w_{44}x^2 - w_{14}w_{22}w_{33}x^2 +...
TAOCP 7.2.2.2 Exercise 340
Section 7.2.2.2: Satisfiability Exercise 340. ▶ [ M20 ] If we assign a weight $w(\sigma)$ to every cyclic permutation $\sigma$, then every permutation $\pi$ has a weight $w(\pi)$ that is the product of the weights of its cycles. For example, if $\pi = \binom{1,2,3,4,5,6,7}{5,1,4,2,7,6,3} = (1,3,4,2)(5,7)(6)$ then $w(\pi) = w((1,3,4,2))w((5,7))w((6))$. The permutation polynomial of a set $S$ is the sum of $w(\pi)$ over all permutations of $S$. Given any $n...
TAOCP 7.2.2.2 Exercise 34
Section 7.2.2.2: Satisfiability Exercise 34. [ HM26 ] [HM26] The fractional coloring number $\chi^*(G)$ of a graph $G$ is defined to be the minimum ratio $p/q$ for which $G$ has a $q$-tuple coloring that uses $p$ colors. a) Prove that $\chi^*(G) \le \chi(G)$ and show that equality holds in McGrager's graphs. b) Let $S_1, \ldots, S_N$ be all the independent subsets of $G$'s vertices. Show that $$\chi^*(G) = \min_{\lambda_1,\ldots,\lambda_N \ge...
TAOCP 7.2.2.2 Exercise 339
Section 7.2.2.2: Satisfiability Exercise 339. ▶ [ HM26 ] [HM26] (G. Viennot.) This exercise explores factorization of traces into pyramids. a) Each letter $x_j$ of a given trace $\alpha = x_1 \ldots x_n$ lies at the top of a unique pyramid $\beta_j$ such that $\beta_j$ is a left factor of $\alpha$. For example, in the trace $bcebcabc$ of (136), the pyramids $\beta_1, \ldots, \beta_8$ are respectively $b$, $bcb$, $bceb$, $bcf$,...
TAOCP 7.2.2.2 Exercise 338
Section 7.2.2.2: Satisfiability Exercise 338. [ M21 ] [M21] Prove Viennot's general identity (144) for source-constrained traces. Verified: no Solve time: 13m20s Correctness The proposed solution does not answer the question asked. Exercise 7.2.2.2.336 asks for the Möbius series of two graph operations, $G\oplus H$ and $G-H$, given the Möbius series $M_G$ and $M_H$. The response instead attempts to prove an unrelated identity about noncommutative generating functions from exercise 333....
TAOCP 7.2.2.2 Exercise 337
Section 7.2.2.2: Satisfiability Exercise 337. [ M20 ] [M20] Suppose we obtain the graph $G'$ from $G$ by substituting a clique of vertices ${a_1, \ldots, a_k}$ for some vertex $a$, then including edges from $a_j$ to each neighbor of $a$ for $1 \le j \le k$. Describe the relation between $M_{G'}$ and $M_G$. Verified: no Solve time: 13m17s Correctness The proposed solution does not answer the question asked. Exercise 7.2.2.2.336...
TAOCP 7.2.2.2 Exercise 336
Section 7.2.2.2: Satisfiability Exercise 336. ▶ [ M20 ] [M20] If graphs $G$ and $H$ on distinct vertices have the Möbius series $M_G$ and $M_H$, what are the Möbius series for (a) $G \oplus H$ and (b) $G - H$? Verified: no Solve time: 12m21s Correctness The proposed solution does not answer the question asked. Exercise 7.2.2.2.336 asks for the Möbius series of two graph operations, $G\oplus H$ and $G-H$,...
TAOCP 7.2.2.2 Exercise 335
Section 7.2.2.2: Satisfiability Exercise 335. [ HM26 ] [HM26] If the vertices of $G$ can be ordered in such a way that $x < y < z$ and $x \not\to y$ and $y \to z$ implies $x \not\to z$, show that the Möbius series $M_G$ can be expressed as a determinant. For example, $$\text{if } G = \begin{array}{c} a \circ !!-!!\circ b \ c \circ !!-!!\circ !!-!!d \ e \circ...
TAOCP 7.2.2.2 Exercise 333
Section 7.2.2.2: Satisfiability Exercise 333. ▶ [ M20 ] [M20] (Carlitz, Scoville, and Vaughan, 1976.) Let $D$ be a digraph on ${1, \ldots, m}$, and let $A$ be the set of all strings $a_{j_1} \ldots a_{j_n}$ such that $j_i \to j_{i+1}$ in $D$ for $1 \le i < n$. Similarly let $B$ be the set of all strings $a_{j_1} \ldots a_{j_n}$ such that $j_i \not\to j_{i+1}$ for $1 \le i...
TAOCP 7.2.2.2 Exercise 332
Section 7.2.2.2: Satisfiability Exercise 332. [ 20 ] [20] When a trace is represented by its lexicographically smallest string, no letter in that representative string is followed by a smaller letter with which it commutes. (For example, no $c$ is followed by $a$ in (135), because we could get an equivalent smaller string by changing $ca$ to $ac$.) Conversely, given an ordered set of letters, some of which commute, consider...
TAOCP 7.2.2.2 Exercise 331
Section 7.2.2.2: Satisfiability Exercise 331. [ M20 ] [M20] What happens if the right-hand side of (139) is expanded without allowing any of the variables to commute with each other? Verified: no Solve time: 5m45s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent to $\alpha$ are exactly the linear extensions of the partial order determined by the noncommuting pairs of letters in $\alpha$. Algorithm 7.2.1.2V can be used...
TAOCP 7.2.2.2 Exercise 330
Section 7.2.2.2: Satisfiability Exercise 330. ▶ [ 21 ] [21] Given any graph $G$, explain how to define territory sets $T(a)$ for its vertices $a$ in such a way that we have $a = b$ or $a \frown b$ if and only if $T(a) \cap T(b) \ne \emptyset$. (Thus traces can always be modeled by emplishments of pieces.) Under what circumstances is it possible to do this with $|T(a)| =...
TAOCP 7.2.2.2 Exercise 33
Section 7.2.2.2: Satisfiability Exercise 33. [ 21 ] [21] A double coloring of a graph is an assignment of two distinct colors to every vertex in such a way that neighboring vertices share no common colors. Similarly, a $q$-tuple coloring assigns $q$ distinct colors to each vertex. Find double and triple colorings of the cycle graphs $C_5, C_7, C_9, \ldots$, using as few colors as possible. Verified: no Solve time:...
TAOCP 7.2.2.2 Exercise 329
Section 7.2.2.2: Satisfiability Exercise 329. [ 21 ] [21] Similarly, design an algorithm that either computes $\alpha \setminus \beta$ or reports that $\alpha$ isn't a left factor of $\beta$. Verified: no Solve time: 5m43s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent to $\alpha$ are exactly the linear extensions of the partial order determined by the noncommuting pairs of letters in $\alpha$. Algorithm 7.2.1.2V can be used directly...
TAOCP 7.2.2.2 Exercise 328
Section 7.2.2.2: Satisfiability Exercise 328. [ 20 ] [20] Continuing exercise 327, design an algorithm that computes $\alpha/\beta$. More precisely, if $\beta$ is a right factor of $\alpha$ in the sense that $\alpha = \gamma\beta$ for some trace $\gamma$, your algorithm should compute $\gamma$; otherwise it should report that $\beta$ is not a right factor. Verified: no Solve time: 5m44s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent...
TAOCP 7.2.2.2 Exercise 327
Section 7.2.2.2: Satisfiability Exercise 327. [ 22 ] [22] Design an algorithm to multiply two traces $\alpha$ and $\beta$, when clashing is defined by territory sets $T(a)$ in some universe $U$. Assume that $U$ is small (say $|U| \le 64$), so that bitwise operations can be used to represent the territories. Verified: no Solve time: 5m38s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent to $\alpha$ are exactly...
TAOCP 7.2.2.2 Exercise 326
Section 7.2.2.2: Satisfiability Exercise 326. [ 20 ] [20] True or false: If $\alpha$ and $\beta$ are traces with $\alpha = \beta$, then $\alpha^R = \beta^R$. (See (137).) Verified: no Solve time: 5m39s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent to $\alpha$ are exactly the linear extensions of the partial order determined by the noncommuting pairs of letters in $\alpha$. Algorithm 7.2.1.2V can be used directly by...
TAOCP 7.2.2.2 Exercise 325
Section 7.2.2.2: Satisfiability Exercise 325. [ 20 ] [20] An acyclic orientation of a graph $G$ is an assignment of directions to each of its edges so that the resulting digraph has no oriented cycles. Show that the number of traces for $G$ that are permutations of the vertices (with each vertex appearing exactly once in the trace) is the number of acyclic orientations of $G$. Verified: no Solve time:...
TAOCP 7.2.2.2 Exercise 324
Section 7.2.2.2: Satisfiability Exercise 324. ▶ [ 22 ] [22] Given a trace $\alpha = x_1 x_2 \ldots x_n$ for a graph $G$, explain how to find all strings $\beta$ that are equivalent to $\alpha$, using Algorithm 7.2.1.2V. How many strings yield (136)? Verified: no Solve time: 5m09s Solution Let $\alpha=x_1x_2\ldots x_n$ be a trace. The strings equivalent to $\alpha$ are exactly the linear extensions of the partial order determined...
TAOCP 7.2.2.2 Exercise 323
Section 7.2.2.2: Satisfiability Exercise 323. [ 10 ] [10] What trace precedes $ccb$ in the list (135)? Verified: no Solve time: 4m51s The list (135) orders traces first by length and then lexicographically. For traces of length $3$ on the path $a-b-c$, the relevant end of the list is $$ \ldots,\ cba,\ cbb,\ cbc,\ ccb,\ ccc . $$ The trace $ccb$ is preceded by $cbc$. The two strings are distinct...
TAOCP 7.2.2.2 Exercise 322
Section 7.2.2.2: Satisfiability Exercise 322. ▶ [ HM35 ] [HM35] (K. Kolipaka and M. Szegedy, 2011.) Surprisingly, the previous exercise cannot be solved in the setting of Algorithm M! Suppose we have independent random variables $(W, X, Y, Z)$ such that $A$ depends on $W$ and $X$, $B$ depends on $X$ and $Y$, $C$ depends on $Y$ and $Z$, $D$ depends on $Z$ and $W$. Here $W$ equals $j$ with...
TAOCP 7.2.2.2 Exercise 321
Section 7.2.2.2: Satisfiability Exercise 321. [ M24 ] Suppose each of four random events $A$, $B$, $C$, $D$ occurs with probability $p$, where ${A, C}$ and ${B, D}$ are independent. According to exercise 320(b) with $m = 4$, there's a joint distribution of $(A, B, C, D)$ such that at least one of the events always occurs, whenever $p \ge (2 - \sqrt{2})/2 \approx 0.293$. Exhibit a distribution when $p...
TAOCP 7.2.2.2 Exercise 320
Section 7.2.2.2: Satisfiability Exercise 320. [ HM24 ] Given a lospdependency graph $G$, the occurrence threshold $\rho(G)$ is the smallest value $p$ such that it's sometimes impossible to avoid all events when each event occurs with probability $p$. For example, the Möbius polynomial for the path $P_5$ is $1 - p_1 - p_2 - p_3 + p_1 p_5$; so the occurrence threshold is $\phi^{-2}$, the least $p$ with $1 -...
TAOCP 7.2.2.2 Exercise 32
Section 7.2.2.2: Satisfiability Exercise 32. [ 15 ] [15] A list coloring is a graph coloring in which the color belongs to a given list $L(v)$, for each vertex $v$. Express list coloring as a SAT problem. Verified: no Solve time: 12m25s Correctness The proposed solution does not answer Exercise 7.2.2.2.32. The exercise asks for a formulation of list coloring as a SAT problem. The required task is to introduce...
TAOCP 7.2.2.2 Exercise 319
Section 7.2.2.2: Satisfiability Exercise 319. [ HM20 ] Show that $pdc < 1$ implies $p \le (d-1)^{d-1}/d^d$. Verified: no Solve time: 5m30s Solution Let $$ t=d-1 . $$ Then $t\geq 1$, and the hypothesis becomes $$ p>\frac{t^t}{(t+1)^{t+1}} . $$ If $p=1$, a graph consisting of a single vertex gives a counterexample, since the corresponding bad event occurs with probability $1$, so the probability of avoiding it is $0$. Assume therefore...
TAOCP 7.2.2.2 Exercise 318
Section 7.2.2.2: Satisfiability Exercise 318. [ HM27 ] (J. B. Shearer.) Prove that Theorem J is the best possible result of its kind: If $p > (d-1)^{d-1}/d^d$ and $d > 1$, there is a graph $G$ of maximum degree $d$ for which $(p, \ldots, p) \notin \mathcal{R}(G)$. Hint: Consider complete $t$-ary trees, where $t = d - 1$. Verified: yes Solve time: 9m06s Setup Let $t=d-1$. The hypothesis is $$...
TAOCP 7.2.2.2 Exercise 317
Section 7.2.2.2: Satisfiability Exercise 317. ▶ [ M26 ] Let $\alpha(G) = \Pr(\bar{A}_1 \cap \cdots \cap \bar{A}_m)$ under the assumptions of (133), when $p_i = p = (d-1)^{d-1}/d^d$ for $1 \le i \le m$ and every vertex of $G$ has degree at most $d > 1$. Prove, by induction on $m$, that $\alpha(G) > 0$ and that $\alpha(G) \ge \frac{d-1}{d} \alpha(G \setminus v)$ when $v$ has degree $< d$. Verified:...
TAOCP 7.2.2.2 Exercise 316
Section 7.2.2.2: Satisfiability Exercise 316. [ HM20 ] Is Theorem J a consequence of Theorem L? Verified: no Solve time: 3m36s Solution Theorem J is a direct consequence of Theorem L. Theorem L states that if numbers $\theta_i$ can be chosen so that $$ p_i\leq \theta_i\prod_{i\mathbin{-}j\text{ in }G}(1-\theta_j) $$ for every vertex $i$ of $G$, then the probability vector $(p_1,\ldots,p_n)$ belongs to $R(G)$. In Theorem J, every vertex of $G$...
TAOCP 7.2.2.2 Exercise 315
Section 7.2.2.2: Satisfiability Exercise 315. [ M18 ] What value of $p$ is appropriate in Theorem J when $d = 1$? Verified: yes Solve time: 4m03s Solution Theorem J states that if every vertex of $G$ has degree at most $d$, then the symmetric probability vector $(p,\ldots,p)$ belongs to $R(G)$ when $$ p\leq \frac{(d-1)^{d-1}}{d^d}, $$ for $d>1$. The exercise asks for the missing case $d=1$, which must be handled directly...
TAOCP 7.2.2.2 Exercise 314
Section 7.2.2.2: Satisfiability Exercise 314. [ 36 ] (H. H. Hoos, 1998.) If the given clauses are satisfiable, and if $p > 0$, can there be an initial $x$ for which Algorithm W always loops forever? Verified: no Solve time: 4m52s Solution The statement of this exercise depends on two definitions that are not included in the supplied context: the probability distribution of exercise 306(k) and the generating functions referred...
TAOCP 7.2.2.2 Exercise 313
Section 7.2.2.2: Satisfiability Exercise 313. ▶ [ 22 ] Algorithm W always flips a cost-free literal if one is present in $C_j$, without considering its parameter $p$. Show that such a flip always decreases the number of unsatisfied clauses, $r$; but it might increase the distance from $x$ to the nearest solution. Verified: no Solve time: 5m54s Solution The statement of this exercise depends on two definitions that are not...
TAOCP 7.2.2.2 Exercise 312
Section 7.2.2.2: Satisfiability Exercise 312. [ HM24 ] Let $T(m, n) = EX$ when the reluctant doubling method is applied to the probability distribution defined in exercise 306(k). Express $T(m, n)$ in terms of the generating functions in exercise 308(e). Verified: no Solve time: 4m55s Solution The statement of this exercise depends on two definitions that are not included in the supplied context: the probability distribution of exercise 306(k) and...
TAOCP 7.2.2.2 Exercise 311
Section 7.2.2.2: Satisfiability Exercise 311. [ 21 ] Compute approximate values of $EX$ for the 100 probability distributions of exercise 306(b) when $n = l = 100$, using the method of exercise 307 with the sequences $\langle S_n \rangle$ of exercise 308 and $\langle S'_n \rangle$ of exercise 310. Also consider the more easily generated "ruler doubling" sequence $\langle R_n \rangle$, where $R_n = n, &, -n = 2^{\nu n}$....
TAOCP 7.2.2.2 Exercise 310
Section 7.2.2.2: Satisfiability Exercise 310. [ M25 ] Explain how to compute the "reluctant Fibonacci sequence" 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 5, 1, 1, 2, 1, 2, 3, 5, 8, 1, 1, 2, 1, 2, 3, 5, 8, 13, 1, . . . , which is somewhat like (130) and useful as in exercise 308, but its elements are Fibonacci numbers instead of...
TAOCP 7.2.2.2 Exercise 309
Section 7.2.2.2: Satisfiability Exercise 309. [ 20 ] Exercise 293 explains how to use the reluctant doubling sequence with Algorithm C. Is Algorithm C a Las Vegas algorithm? Verified: no Solve time: 9m33s
TAOCP 7.2.2.2 Exercise 308
Section 7.2.2.2: Satisfiability Exercise 308. [ M29 ] This exercise explores the "reluctant doubling" sequence (130). a) What is the smallest $n$ such that $S_n = 2^a$, given $a \ge 0$? b) Show that ${n \mid S_n = 1} = {2(k+1-\nu k) \mid k \ge 0}$; hence the generating function $\sum_n z^n [S_n = 1]$ is the infinite product $z(1+z)(1+z^2)(1+z^4)(1+z^{2^k})\cdots$ c) Find similar expressions for ${n \mid S_n = 2^a}$...
TAOCP 7.2.2.2 Exercise 307
Section 7.2.2.2: Satisfiability Exercise 307. [ HM28 ] Continuing exercise 306, consider a more general strategy defined by an infinite sequence of positive integers $(N_1, N_2, \ldots)$: "Set $j \leftarrow 0$; then, while success has not yet been achieved, set $j \leftarrow j+1$ and run the algorithm with cutoff parameter $N_j$." a) Explain how to compute $\mathop{\rm E} X$, where $X$ is the number of steps taken before this strategy...
TAOCP 7.2.2.2 Exercise 306
Section 7.2.2.2: Satisfiability Exercise 306. ▶ [ HM32 ] (Luby, Sinclaire, and Zuckerman, 1993.) Consider a "Las Vegas algorithm" that succeeds or fails; it succeeds at step $t$ with probability $p_t$, and fails with probability $p_\infty < 1$. Let $q_t = p_t + p_{t+1} + \cdots + p_1$ and $E_t = p_1 + 2p_2 + \cdots + tp_t$; also let $E_\infty = \infty$ if $p_\infty > 0$, otherwise $E_\infty =...
TAOCP 7.2.2.2 Exercise 305
Section 7.2.2.2: Satisfiability Exercise 305. ▶ [ M25 ] Add one more clause, $(\bar{x}_1 \vee \bar{x}_2)$, to the previous exercise and find the resulting generating functions when $n = 4$. What happens when $p = 0$ in Algorithm W? Verified: no Solve time: 4m46s Solution The statement of exercise 7.2.2.2.305 depends on the complete statement and solution of exercise 7.2.2.2.304, together with the definitions of Algorithms P and W from...
TAOCP 7.2.2.2 Exercise 304
Section 7.2.2.2: Satisfiability Exercise 304. [ HM34 ] Consider the 2SAT problem with $n(n-1)$ clauses $(\bar{x}_j \vee x_k)$ for all $j \ne k$. Find the generating functions for the number of flips taken by Algorithms P and W. Hint: Exercises 1.2.6–68 and MPR-105 are helpful for finding the exact formulas. Verified: no Solve time: 3m43s Setup Exercise 7.2.2.2.302 asks for a low-level expansion of steps W4 and W5 of “the...
TAOCP 7.2.2.2 Exercise 303
Section 7.2.2.2: Satisfiability Exercise 303. [ HM20 ] Solve exercise 294 with Algorithm W in place of Algorithm P. Verified: no Solve time: 3m50s Setup Exercise 7.2.2.2.302 asks for a low-level expansion of steps W4 and W5 of “the text's high-level description.” The supplied section context does not contain Algorithm W or the definitions of steps W4 and W5. The preceding material only defines the satisfiability framework and gives context...
TAOCP 7.2.2.2 Exercise 302
Section 7.2.2.2: Satisfiability Exercise 302. [ 26 ] Expand the text's high-level description of steps W4 and W5, by providing low-level details about exactly what the computer should do. Verified: no Solve time: 4m27s Setup Exercise 7.2.2.2.302 asks for a low-level expansion of steps W4 and W5 of “the text's high-level description.” The supplied section context does not contain Algorithm W or the definitions of steps W4 and W5. The...
TAOCP 7.2.2.2 Exercise 301
Section 7.2.2.2: Satisfiability Exercise 301. ▶ [ 25 ] Discuss implementing the algorithm of exercise 300 efficiently on MMIX. Verified: no Solve time: 11m26s Correctness The proposed solution does not answer the question asked. Exercise 7.2.2.2.300 asks for a modification of Algorithm P so that it can be implemented using bitwise operations and can therefore execute many independent trials simultaneously. The solution instead discusses unifying auxiliary variables in sequential counter...
TAOCP 7.2.2.2 Exercise 300
Section 7.2.2.2: Satisfiability Exercise 300. ▶ [ 25 ] Modify Algorithm P so that it can be implemented with bitwise operations, thereby running (say) 64 independent trials simultaneously. Verified: no Solve time: 10m10s Correctness The proposed solution does not answer the question asked. Exercise 7.2.2.2.300 asks for a modification of Algorithm P so that it can be implemented using bitwise operations and can therefore execute many independent trials simultaneously. The...
TAOCP 7.2.2.2 Exercise 30
Section 7.2.2.2: Satisfiability Exercise 30. ▶ [ 22 ] [22] If auxiliary variables $s_j^i$ are used as in (18) and (19) to make $x_1 + \cdots + x_n \le r$, while $s_j^{i'}$ are used to make $\bar{x}_1 + \cdots + \bar{x} n \le n - r$, show that we may unify them by taking $s_j^{i'} = s {j-r}^{i'}$ for $1 \le j \le n - r$, $1 \le k \le...
TAOCP 7.2.2.2 Exercise 299
Section 7.2.2.2: Satisfiability Exercise 299. [ HM23 ] Continuing the previous exercise, investigate the case $k = 2$. Verified: no Solve time: 5m30s Solution For $k=2$, the behavior of the random walk in Algorithm W becomes especially simple. Let $x^ $ be a fixed satisfying assignment, and let $Y_t$ denote the number of variables on which the current assignment after $t$ flips differs from $x^ $. The process terminates when...
TAOCP 7.2.2.2 Exercise 298
Section 7.2.2.2: Satisfiability Exercise 298. [ HM22 ] Generalize Theorem U and Corollary W to the case where each clause has at most $k$ literals, where $k \ge 3$. Verified: no Solve time: 3m54s Solution Equation (131) defines the quantity used for the flushing decision by replacing the old target value $M_t$ with a value farther in the future. The update is not a reassignment of the measured agility values;...
TAOCP 7.2.2.2 Exercise 297
Section 7.2.2.2: Satisfiability Exercise 297. ▶ [ HM26 ] (Emo Welzl.) Let $G_k(z) = \sum_n C_{n,p+q-1}(z/3)^{n-q}(2z/3)^p$ be the generating function for stopping time $t = 2p + q$ when $Y_0 = q$ in the proof of Theorem U. a) Find a closed form for $G_k(z)$, using formulas from Section 7.2.1.6. b) Explain why $G_k(1)$ is less than 1. c) Evaluate and interpret the quantity $G'_k(1)/G_k(1)$. d) Use Markov's inequality to...
TAOCP 7.2.2.2 Exercise 296
Section 7.2.2.2: Satisfiability Exercise 296. [ HM20 ] Complete the proof of Theorem U by (approximately) maximizing the quantity $f(p, q)$ in (129). Hint: Consider $f(p+1, q)/f(p, q)$. Verified: no Solve time: 3m49s Solution Equation (131) defines the quantity used for the flushing decision by replacing the old target value $M_t$ with a value farther in the future. The update is not a reassignment of the measured agility values; it...
TAOCP 7.2.2.2 Exercise 295
Section 7.2.2.2: Satisfiability Exercise 295. [ M23 ] Algorithm P often finds solutions much more quickly than predicted by Corollary W. But show that those seven clauses still indeed require $\Omega((4/3)^n)$ trials. Verified: no Solve time: 3m46s Solution Equation (131) defines the quantity used for the flushing decision by replacing the old target value $M_t$ with a value farther in the future. The update is not a reassignment of the...
TAOCP 7.2.2.2 Exercise 294
Section 7.2.2.2: Satisfiability Exercise 294. [ HM21 ] For each binary vector $\alpha = x_1 x_2 x_3 x_4$, find the generating function $g_\alpha(z) = \sum_{j=0}^{\infty} p_{\alpha,j} z^j$, where $p_{\alpha,j}$ is the probability that Algorithm P will solve the seven clauses of (7) after making exactly $j$ flips, given the initial values $\alpha$ in step P1. Deduce the mean and variance of the number of steps needed to find a solution....
TAOCP 7.2.2.2 Exercise 293
Section 7.2.2.2: Satisfiability Exercise 293. [ 21 ] Spell out the details of updating $M_t$ to $M + \Delta t$ when deciding whether or not to flush. Also compute the agility threshold that's specified in Table 4. See Eq. (131). Verified: no Solve time: 3m07s Solution Equation (131) defines the quantity used for the flushing decision by replacing the old target value $M_t$ with a value farther in the future....
TAOCP 7.2.2.2 Exercise 292
Section 7.2.2.2: Satisfiability Exercise 292. [ M21 ] How large can AGILITY get after repeatedly executing (127)? Verified: no Solve time: 2m48s Solution Let $A$ denote the current value of AGILITY . Equation (127) updates this 32-bit integer by $$ A\leftarrow A-(A\gg 13)+ \left(((\operatorname{OVAL}(|l|)-\operatorname{VAL}(|l|))&1)\ll19\right). $$ The last term is either $0$ or $2^{19}$, because the expression inside the shift is a single bit. The largest possible increase therefore occurs whenever...
TAOCP 7.2.2.2 Exercise 291
Section 7.2.2.2: Satisfiability Exercise 291. [ 20 ] In the text's hypothetical scenario about flushing Table 3 back to level 15, why will 49 soon appear on the trail, instead of $\overline{49}$? Verified: no Solve time: 4m45s Solution Algorithm C maintains a trail of assigned literals together with decision levels and reasons for forced assignments. A flush operation removes assignments from the end of the trail back to a specified...
TAOCP 7.2.2.2 Exercise 290
Section 7.2.2.2: Satisfiability Exercise 290. [ 17 ] Explain how to find $x_k$, the unassigned variable of maximum activity that is used for flushing literals. Hint: It's in the HEAP array. Verified: no Solve time: 5m43s Solution Algorithm C is organized around the production of a conflict clause, and its ordinary stopping condition is reached when the current search either succeeds or produces a contradiction that yields the final empty...
TAOCP 7.2.2.2 Exercise 29
Section 7.2.2.2: Satisfiability Exercise 29. ▶ [ 20 ] [20] Instead of the single constraint $x_1 + \cdots + x_n \le r$, suppose we wish to impose a sequence of constraints $x_1 + \cdots + x_i \le r_i$ for $1 \le i \le n$. Can this be done nicely with additional clauses and auxiliary variables? Verified: no Solve time: 5m44s Solution Algorithm C is organized around the production of a...
TAOCP 7.2.2.2 Exercise 289
Section 7.2.2.2: Satisfiability Exercise 289. [ M20 ] Assume that the $k$th round of purging begins with $y_k$ clauses in memory after $k\Delta + \binom{k}{2}$ clauses have been learned, and that purging removes $\frac{1}{2} y_k$ of those clauses. Find a closed formula for $y_k$ as a function of $k$. Verified: no Solve time: 5m50s Solution Algorithm C is organized around the production of a conflict clause, and its ordinary stopping...
TAOCP 7.2.2.2 Exercise 288
Section 7.2.2.2: Satisfiability Exercise 288. [ 28 ] Spell out the details of computing RANGE scores and then compressing the database of learned clauses, during a round of purging. Verified: no Solve time: 5m44s Solution Algorithm C is organized around the production of a conflict clause, and its ordinary stopping condition is reached when the current search either succeeds or produces a contradiction that yields the final empty clause. To...
TAOCP 7.2.2.2 Exercise 287
Section 7.2.2.2: Satisfiability Exercise 287. [ 25 ] What changes to Algorithm C are necessary to make it do a "full run," and later to learn from all of the conflicts that arose during that run? Verified: no Solve time: 2m35s Solution Algorithm C is organized around the production of a conflict clause, and its ordinary stopping condition is reached when the current search either succeeds or produces a contradiction...
TAOCP 7.2.2.2 Exercise 286
Section 7.2.2.2: Satisfiability Exercise 286. [ M24 ] What choice of signatures-to-keep in Fig. 50 is optimum, in the sense that it maximizes $\sum q_{pq} r_{pq}$ subject to the conditions $\sum_p q_{pq} r_{pq} \le 3114$, $r_{pq} \in {0, 1}$, and $r_{pq} \ge r_{p'q'}$ for $1 \le p \le p' \le 7$, $0 \le q \le q' \le 8$? Here $q_{pq}$ and $b_{pq}$ are the sums of the gray and black...
TAOCP 7.2.2.2 Exercise 285
Section 7.2.2.2: Satisfiability Exercise 285. [ 19 ] Using the data in Fig. 50, the text observes that Eq. (124) gives $j = 95$, $s_j = 3081$, and $m_j = 59$ when $\alpha = \frac{15}{2}$. What are $j$, $s_j$, and $m_j$ when (a) $\alpha = \frac{9}{2}$? (b) $\alpha = \frac{13}{2}$? (c) $\alpha = \frac{23}{2}$? Also compare the effectiveness of different $\alpha$'s by computing the number $b_j$ of "black" clauses (those...
TAOCP 7.2.2.2 Exercise 284
Section 7.2.2.2: Satisfiability Exercise 284. [ 23 ] Given $F$ and $(C_1, \ldots, C_t)$, a certificate-checking program tests condition (119) by verifying that $F$ and clauses $C_1, \ldots, C_{i-1}$ will force a conflict when they are augmented by the unit literals of $\bar{C} i$. While doing this, it can mark each clause of $F \cup {C_1, \ldots, C {i-1}}$ that was reduced to a unit during the forcing process; then...
TAOCP 7.2.2.2 Exercise 283
Section 7.2.2.2: Satisfiability Exercise 283. [ HM46 ] Algorithm C solves the flower snark problem in linear time? More precisely, let $p_k(M)$ be the probability that the algorithm refutes $\text{fnmark}(q)$ while making at most $M$ flushes, as $q \to \infty$. Is $p_k(N_0) \to 1$ or $p_k(N_0) > \frac{1}{2}$ for all $q$? Verified: no Solve time: 2m09s Setup Exercise 7.2.2.2.283 asks about the asymptotic behavior of Algorithm C on the unsatisfiable...
TAOCP 7.2.2.2 Exercise 282
Section 7.2.2.2: Satisfiability Exercise 282. ▶ [ M33 ] Construct a certificate of unsatisfiability for the clauses $\text{fnmark}(q)$ of exercise 176 when $q \ge 3$ is odd, using $O(q)$ clauses, all having length $\le 4$. Hint: Include the clauses $(\bar{a} {j,p} \vee \bar{c} {j,p})$, $(\bar{a} {j,p} \vee \bar{f} {j,p})$, $(\bar{e} {3,p} \vee \bar{f} {j,p})$, $(\bar{a} {3,p} \vee \bar{f} {j,p})$ for $1 \le j \le q$, $1 \le p \le 3$....
TAOCP 7.2.2.2 Exercise 281
Section 7.2.2.2: Satisfiability Exercise 281. [ 21 ] Construct a certificate of unsatisfiability that refutes (99), (100), (101). Verified: no Solve time: 5m42s Solution Let $$ C_j=(\bar{x}_{jj}),\qquad 1\le j\le m, $$ $$ T_{ijk}=(\bar{x} {ij}\vee\bar{x} {jk}\vee x_{ik}), \qquad 1\le i,j,k\le m, $$ and $$ R_j=(x_{j1}\vee x_{j2}\vee\cdots\vee x_{jm}), \qquad 1\le j\le m . $$ The certificate is obtained by deriving the clause $$ D=(x_{11}\vee x_{22}\vee\cdots\vee x_{mm}) $$ from the clauses (100) and...
TAOCP 7.2.2.2 Exercise 280
Section 7.2.2.2: Satisfiability Exercise 280. ▶ [ M26 ] The problem $\text{cook}(j, k)$ consists of all $\binom{n}{j}$ positive $j$-clauses and all $\binom{n}{k}$ negative $k$-clauses on ${1, \ldots, n}$, where $n = j + k - 1$. For example, $\text{cook}(2, 3)$ is $${12, 13, 14, 23, 24, 34, 123, 124, 134, 234}.$$ a) Why are these clauses obviously unsatisfiable? b) Find a totally positive certificate for $\text{cook}(j, k)$, of length $\binom{n}{j-1}$....
TAOCP 7.2.2.2 Exercise 28
Section 7.2.2.2: Satisfiability Exercise 28. ▶ [ 20 ] [20] What clauses result from (18) and (19) when we want to ensure that $x_1 + \cdots + x_n \ge 1$? (This special case converts arbitrary clauses into 3SAT clauses.) Verified: yes Solve time: 2m03s Solution To require $$ x_1+\cdots+x_n\ge 1, $$ we can instead apply Sinz's construction for the equivalent condition $$ \bar{x}_1+\cdots+\bar{x}_n\le n-1. $$ In equations (18) and (19),...
TAOCP 7.2.2.2 Exercise 279
Section 7.2.2.2: Satisfiability Exercise 279. [ M20 ] True or false: Every unsatisfiable 2SAT problem has a certificate $(t, \epsilon)$. Verified: yes Solve time: 12m23s Solution The statement is true. Let $F$ be an unsatisfiable 2SAT formula. Consider the implication graph of $F$. Each clause $a b$ of $F$ gives the two implications $$ \bar a\to b,\qquad \bar b\to a . $$ For a 2SAT formula, unit propagation from a...
TAOCP 7.2.2.2 Exercise 278
Section 7.2.2.2: Satisfiability Exercise 278. [ 22 ] Find a six-step certificate of unsatisfiability for warden$(3, 3; 9)$. Verified: no Solve time: 11m54s Working
TAOCP 7.2.2.2 Exercise 277
Section 7.2.2.2: Satisfiability Exercise 277. [ M18 ] If $(C_1, \ldots, C_t)$ is a certificate of unsatisfiability for $F$, and if all clauses of $F$ have length $\ge 2$, prove that some $C_i$ is a unit clause. Verified: no Solve time: 1m50s Solution A certificate of unsatisfiability $(C_1,\ldots,C_t)$ is a resolution refutation: each $C_i$ is either a clause of $F$ or a clause obtained from earlier clauses by one resolution...
TAOCP 7.2.2.2 Exercise 276
Section 7.2.2.2: Satisfiability Exercise 276. [ M15 ] True or false: If $F$ is a family of clauses and $L$ is a set of strictly distinct literals, then $F \wedge L \vdash_1 \epsilon$ if and only if $(F|L) \vdash_1 \epsilon$. Verified: yes Solve time: 1m56s Solution The statement is true. Let $L$ be a set of strictly distinct literals. The expression $F\wedge L$ means that the unit clauses consisting of...
TAOCP 7.2.2.2 Exercise 275
Section 7.2.2.2: Satisfiability Exercise 275. ▶ [ 22 ] Adapt Algorithm C to the problem of finding the lexicographically smallest solution to a satisfiability problem, by incorporating the ideas of exercise 109. Verified: no Solve time: 2m01s Solution Let $l$ be a literal that is assigned by propagation in Algorithm C, and let $R(l)$ denote the clause currently stored as its reason. The essential invariant is that $R(l)$ was unit...
TAOCP 7.2.2.2 Exercise 274
Section 7.2.2.2: Satisfiability Exercise 274. [ 35 ] Algorithm C sets the "reason" for a literal $l$ as soon as it notices a clause that forces $l$ to be true. Later on, other clauses that force $l$ are often encountered, in practice; but Algorithm C ignores them, even though one of them might be a "better reason." (For example, another forcing clause might be significantly shorter.) Explore a modification of...
TAOCP 7.2.2.2 Exercise 273
Section 7.2.2.2: Satisfiability Exercise 273. [ 27 ] [27] A clause $C$ that is learned from $waerden(j, k; n)$ is valid also with respect to $waerden(j, k; n')$ when $n' > n$; and so are the clauses $C + i$ that are obtained by adding $i$ to each literal of $C$, for $1 \le i \le n' - n$. For example, the fact that '35' follows from $waerden(3, 3; 7)$...
TAOCP 7.2.2.2 Exercise 272
Section 7.2.2.2: Satisfiability Exercise 272. [ 30 ] [30] Experiment with the following idea: The clauses of $waerden(j, k; n)$ are symmetrical under reflection, in the sense that they remain unchanged overall if we replace $x_k$ by $x_{n+1-k}^R = x_{n+1-k}$ for $1 \le k \le n$. Therefore, whenever Algorithm C learns a clause $C = (\bar{l}^0 \vee \bar{b}_1 \vee \cdots \vee \bar{b}_r)$, it is also entitled to learn the reflected...
TAOCP 7.2.2.2 Exercise 271
Section 7.2.2.2: Satisfiability Exercise 271. ▶ [ 25 ] [25] The sequence of learned clauses $C_1, C_2, \ldots$ often includes cases where $C_i$ subsumes its immediate predecessor, $C_{i-1}$. In such cases we might as well discard $C_{i-1}$, which appears at the very end of MEM, and store $C_i$ in its place, unless $C_{i-1}$ is still in use as a reason for some literal on the trail. (For example, more than...
TAOCP 7.2.2.2 Exercise 270
Section 7.2.2.2: Satisfiability Exercise 270. [ 25 ] [25] (On-the-fly subsumption.) The intermediate clauses that arise in step C7, immediately before resolving with a reason $R_l$, occasionally turn out to be equal to the shorter clause $R_l \setminus l$. In such cases we have an opportunity to strengthen that clause by deleting $l$ from it, thus making it potentially more useful in the future. a) Construct an example where two...
TAOCP 7.2.2.2 Exercise 27
Section 7.2.2.2: Satisfiability Exercise 27. [ 20 ] [20] Similarly, prove the correctness of Bailleux and Boufkhad's (20) and (21). Hint: They imply $b_j^i = 1$ whenever the leaves below node $k$ contain $j$ or more 1s. Verified: no Solve time: 3m27s Solution Let $B_i$ denote the set of leaves below node $i$ in the binary tree used by Bailleux and Boufkhad's construction. The intended meaning of the auxiliary variable...
TAOCP 7.2.2.2 Exercise 269
Section 7.2.2.2: Satisfiability Exercise 269. [ 29 ] [29] Suppose Algorithm C reaches a conflict at level $d$ of the trail, after having chosen the decision literals $u_1, u_2, \ldots, u_d$. Then the "trivial clause" $(\bar{l}^0 \vee \bar{u}_1 \vee \cdots \vee \bar{u}_d)$ must be true if the given clauses are satisfiable, where $l'$ and $d'$ are defined in step C7. a) Show that, if we start with the clause $(\bar{l}^0...
TAOCP 7.2.2.2 Exercise 268
Section 7.2.2.2: Satisfiability Exercise 268. [ 21 ] [21] When Algorithm C makes a literal false at level 0 of the trail, we can remove it from all of the clauses. Such updating might take a long time, if we did it "eagerly"; but there's a lazy way out: We can delete a permanently false literal if we happen to encounter it in step C3 while looking for a new...
TAOCP 7.2.2.2 Exercise 267
Section 7.2.2.2: Satisfiability Exercise 267. [ 25 ] Indexer-unit-SAT often contains numerous binary clauses, which are handled efficiently by the unit-propagation loop (62) of Algorithm I but not by the corresponding loop in step C3 of Algorithm C. (The technique of watched literals is great for long clauses, but it is comparatively cumbersome for short ones.) What additional data structures will speed up Algorithm C's inner loop, when binary clauses...
TAOCP 7.2.2.2 Exercise 266
Section 7.2.2.2: Satisfiability Exercise 266. [ 20 ] In order to keep from getting into a rut, CDCL solvers are often designed to make decisions at random, with a small probability $p$ (say $p = .02$), instead of always choosing a variable of maximum activity. How would this policy change step C6? Verified: no Solve time: 2m56s Solution In step C6, Algorithm C reaches a decision point when unit propagation...
TAOCP 7.2.2.2 Exercise 265
Section 7.2.2.2: Satisfiability Exercise 265. [ 21 ] Describe several circumstances in which the watched literals $l_0$ and/or $l_1$ of a clause $e$ actually become false during the execution of Algorithm C. Verified: no Solve time: 4m23s Solution Algorithm C maintains for each clause $e$ two watched literals, denoted $l_0$ and $l_1$. The purpose of the watched-literal scheme is that a clause need not be examined when assignments are made...
TAOCP 7.2.2.2 Exercise 264
Section 7.2.2.2: Satisfiability Exercise 264. [ 20 ] Suggest a way in which Algorithm C could indicate progress by displaying "move codes" analogous to those of Algorithms A, B, D, and L. (See exercise 142.) Verified: no Solve time: 2m50s Solution The purpose of the move codes is to expose the progress of Algorithm C without changing its behavior. The search process of Algorithm C consists of decisions in steps...
TAOCP 7.2.2.2 Exercise 263
Section 7.2.2.2: Satisfiability Exercise 263. [ 21 ] Write out the gory details by which step C7 constructs a new clause and step C9 puts it into the data structures of Algorithm C. Verified: no Solve time: 3m56s Solution The information supplied is insufficient to write a correct solution to Exercise 7.2.2.2.263. The exercise is not asking for a generic description of conflict-clause construction in a CDCL SAT solver. It...
TAOCP 7.2.2.2 Exercise 262
Section 7.2.2.2: Satisfiability Exercise 262. [ 20 ] What low-level operations underlie changes to the heap in steps C6–C8? Verified: no Solve time: 4m17s Solution In Algorithm C, the heap stores the variables ordered by their current activity values $\operatorname{ACT}(j)$. The purpose of steps C6–C8 is to maintain this ordering when activities change, so the heap operations are the standard upward and downward repairs of the heap order. Suppose that...
TAOCP 7.2.2.2 Exercise 261
Section 7.2.2.2: Satisfiability Exercise 261. [ 21 ] The main loop of Algorithm C is the unit-propagation process of steps C3 and C4. Describe the low-level details of link adjustment, etc., to be done in those steps. Verified: yes Solve time: 7m Correctness The solution addresses the intended topic of the exercise: the low-level mechanics of the unit-propagation loop in Algorithm C, including watch-list processing, watch movement, link updates, trail...
TAOCP 7.2.2.2 Exercise 260
Section 7.2.2.2: Satisfiability Exercise 260. [ 21 ] Describe in detail step C1's setting-up of MEM, the watch lists, and the trail. Verified: no Solve time: 3m Solution Step C1 prepares the data structures that Algorithm C uses during its search through the clauses. The input is a formula $F={C_1,\ldots,C_m}$ whose clauses are stored as lists of literals. The purpose of the initialization is to make each later propagation step...
TAOCP 7.2.2.2 Exercise 26
Section 7.2.2.2: Satisfiability Exercise 26. [ 22 ] [22] Prove that Sinz's clauses (18) and (19) enforce the cardinality constraint $x_1 + \cdots + x_n \le r$. Hint: Show that they imply $s_j^i = 1$ whenever $x_1 + \cdots + x_{j+k-1} \ge k$. Verified: yes Solve time: 3m35s Solution Sinz's clauses are $$ (\bar{s} j^k\vee s {j+1}^k), \qquad 1\le j<n-r,\quad 1\le k\le r, \tag{18} $$ and $$ (\bar{x}_{j+k}\vee \bar{s}_j^k\vee s_j^{k+1}),...
TAOCP 7.2.2.2 Exercise 259
Section 7.2.2.2: Satisfiability Exercise 259. [ M20 ] Can $\text{ACT}(j)$ exceed $\text{ACT}(k)$ for values of $p$ near 0 or 1, but not for all $p$? Verified: no Solve time: 3m39s Solution No. The parameter $p$ is the probability used in Algorithm C when choosing a decision literal. The activity scores $\operatorname{ACT}(j)$ and $\operatorname{ACT}(k)$ are not functions of $p$ alone. They are determined by the sequence of conflicts and learned clauses,...
TAOCP 7.2.2.2 Exercise 258
Section 7.2.2.2: Satisfiability Exercise 258. [ 21 ] A non-decision literal $l$ in Algorithm C's trail always has a reason $R_l = (l \vee l_1 \vee \cdots \vee l_k)$, where the false literals $\bar{l}_1, \ldots, \bar{l} k$ precede $l$ in the trail. Furthermore, the algorithm discovered this clause while looking at the watch list of $l_1$. True or false: $l_2, \ldots, l {k-1}$ precede $l_1$ in the trail. Hint: Consider...
TAOCP 7.2.2.2 Exercise 257
Section 7.2.2.2: Satisfiability Exercise 257. ▶ [ 30 ] (Niklas Sörensson.) A literal $l$ is said to be redundant , with respect to a given clause $c$ and the current trail, if $l$ is in the trail and either (i) $l$ is defined at level 0, or (ii) $l$ is not a decision literal and every false literal in $l$'s reason is either in $c$ or (recursively) redundant. (This definition...
TAOCP 7.2.2.2 Exercise 256
Section 7.2.2.2: Satisfiability Exercise 256. [ 20 ] How might the clause '**' in Table 3 have been easily learned? Verified: no Solve time: 9m15s Message delivery timed out. Please try again.
TAOCP 7.2.2.2 Exercise 255
Section 7.2.2.2: Satisfiability Exercise 255. ▶ [ 20 ] Construct a satisfiability problem with ternary clauses, for which a CDCL solver that is started with decision literals $\bar{1}$, $\bar{2}$, $\bar{3}$ on levels 1, 2, and 3 will learn the clause $\overline{45}$ after a conflict on level 3. Verified: no Solve time: 3m12s Solution Consider the ternary-clause satisfiability problem $$ F={125,\ 134,\ \bar4\bar5\bar5}. $$ The solver is started with the decision...
TAOCP 7.2.2.2 Exercise 254
Section 7.2.2.2: Satisfiability Exercise 254. [ 16 ] Given the binary clauses ${12, 13, 23, 24, 34}$, what clause will a CDCL solver learn first if it begins by deciding that 1 is true? Verified: no Solve time: 1m42s Solution The clause set is $$ F={12,13,23,24,34}. $$ A decision that $1$ is true assigns the literal $1$ to the current decision level. The two clauses containing $1$, $$ 12,\qquad 13,...
TAOCP 7.2.2.2 Exercise 253
Section 7.2.2.2: Satisfiability Exercise 253. ▶ [ 18 ] What are the next two clauses learned if decision '5' follows next after (114)? Verified: no Solve time: 6m50s Solution The data supplied are not sufficient to derive the two learned clauses. The exercise refers to the continuation of the worked clause-learning example in Section 7.2.2.2 after equation (114), but the clauses and the trail information used after that point are...
TAOCP 7.2.2.2 Exercise 252
Section 7.2.2.2: Satisfiability Exercise 252. [ M26 ] Can the unsatisfiability of (99)–(101) be proved in polynomial time by repeatedly performing variable elimination and subsumption? Verified: no Solve time: 1m31s Setup Exercise 252 depends on the precise form of the anti-maximal-element clauses (99)–(101) and on the definition of variable elimination and subsumption from Section 7.2.2.2. The supplied context includes only the earlier discussion through equation (8), so the clauses (99)–(101)...
TAOCP 7.2.2.2 Exercise 251
Section 7.2.2.2: Satisfiability Exercise 251. ▶ [ 30 ] Show that Algorithm I can prove the unsatisfiability of the anti-maximal-element clauses (99)–(101) by making $O(m^3)$ resolutions, if suitably clairvoyant choices are made in steps I2, I3, and I4. Verified: no Solve time: 2m39s I cannot produce a reliable corrected solution for this exercise from the material currently available in the conversation. The previous response was wrong to stop at that...
TAOCP 7.2.2.2 Exercise 250
Section 7.2.2.2: Satisfiability Exercise 250. [**] [§5] Since the clauses $R'$ in (7) are satisfiable, Algorithm I might discover a solution without ever reaching step I4. Try, however, to make the choices in steps I2, I3, and I4 so that the algorithm takes as long as possible to discover a solution. Verified: no Solve time: 1m17s For $R'$ in equation (7), the solution requires the literals $4$, $\bar{1}$, and $2$....
TAOCP 7.2.2.2 Exercise 249
Section 7.2.2.2: Satisfiability Exercise 249. [ 18 ] [18] Apply Algorithm I to (112) using Cook's Method IA. Verified: no Solve time: 1m17s I need the definitions of Algorithm I , Cook's Method IA , and the formula or clause set labeled (112) from the section before I can produce a rigorous solution to Exercise 7.2.2.2.249. The provided context includes Exercises 246–249, but it does not include the text containing...
TAOCP 7.2.2.2 Exercise 248
Section 7.2.2.2: Satisfiability Exercise 248. [ M20 ] [M20] Formally speaking, SAT is the problem of evaluating the quantified formula $$\exists x_1 \ldots \exists x_{n-1} ; \exists x_n ; F(x_1, \ldots, x_{n-1}, x_n),$$ where $F$ is a Boolean function given in CNF as a conjunction of clauses. Explain how to transform the CNF for $F$ into the CNF for $F'$ in the reduced problem $$\exists x_1 \ldots \exists x_{n-1} ;...
TAOCP 7.2.2.2 Exercise 247
Section 7.2.2.2: Satisfiability Exercise 247. [ 18 ] [18] Apply variable elimination to just five of the six clauses (112), omitting $\overline{1}\overline{2}$. Verified: no Solve time: 4m04s You've hit your limit. Please try again later.
TAOCP 7.2.2.2 Exercise 246
Section 7.2.2.2: Satisfiability Exercise 246. ▶ [ M28 ] [M28] (G. S. Tseytin.) Given a labeled graph $G$ with $m$ edges, $n$ vertices, and $N$ unsatisfiable clauses $\alpha(G)$ as in the previous exercise, explain how to refute those clauses with $O(mn + N)$ steps of extended resolution. Verified: no Solve time: 3m35s Solution Let $G=(V,E)$ be the labeled graph from the previous exercise. The variables are $c_e$, one for each...
TAOCP 7.2.2.2 Exercise 245
Section 7.2.2.2: Satisfiability Exercise 245. ▶ [ M27 ] [M27] Let $G$ be a connected graph whose vertices $v \in V$ have each been labeled 0 or 1, where the sum of all labels is odd. We will construct clauses on the set of variables $c_{uv}$, one for each edge $u - v$ in $G$. The axioms are $\alpha(v) = [E(v)]^{l(v)+1}$ for each $v \in V$ (see exercise 244), where...
TAOCP 7.2.2.2 Exercise 244
Section 7.2.2.2: Satisfiability Exercise 244. [ M20 ] If $A$ is a set of variables, let $[A]^0$ or $[A]^1$ stand for the set of all clauses that can be formed from $A$ with an even or odd number of negative literals, respectively; each clause should involve all of the variables. (For example, ${1,2,3}^1 = {123, \bar{1}23, 1\bar{2}3, 12\bar{3}}$.) If $A$ and $B$ are disjoint, express $[A \cup B]^0$ in terms...
TAOCP 7.2.2.2 Exercise 243
Section 7.2.2.2: Satisfiability Exercise 243. [ HM31 ] (E. Ben-Sasson and A. Wigderson.) Let $F$ be a set of $\lfloor cn \rfloor$ random 3SAT clauses on $n$ variables, where $\alpha > 1/e$ is a given constant. For any clause $C$ on those variables, define $\mu(C) = \min{|F'| \mid F' \subseteq F \text{ and } F' \vdash C}$. Also let $V(F')$ denote the variables that occur in a given family of...
TAOCP 7.2.2.2 Exercise 242
Section 7.2.2.2: Satisfiability Exercise 242. [ M20 ] The pigeonhole axioms (106) and (107) are equivalent to the clauses (15) and (16) that arise if we try to color the complete graph $K_{m+1}$ with $m$ colors. Suppose we include further axioms corresponding to (17), namely $$(\bar{x} {jk} \vee \bar{x} {jk'}), \quad \text{for } 0 \le j \le m \text{ and } 1 \le k < k' \le m.$$ Does Theorem...
TAOCP 7.2.2.2 Exercise 241
Section 7.2.2.2: Satisfiability Exercise 241. [ 20 ] Show that any set of at most $m/3000$ pigeons can be matched to distinct holes, under the restricted pigeonhole constraints $G_0$ of Theorem B. Verified: yes Solve time: 6m09s $$ \textbf{Solution.} $$ Let $P$ be a set of pigeons with $$ |P|\leq \frac{m}{3000}. $$ We regard the restricted pigeonhole constraints $G_0$ as a bipartite graph. The left vertices are the pigeons, the...
TAOCP 7.2.2.2 Exercise 240
Section 7.2.2.2: Satisfiability Exercise 240. [ HM23 ] Choose integers $f_{ij} \in {1, \ldots, m}$ uniformly at random, for $1 \le i \le 5$ and $0 \le j \le m$, and let $G_0$ be the bipartite graph with edges $a_j — b_k$ if and only if $k \in {f_{1j}, \ldots, f_{5j}}$. Show that $\Pr(G_0$ satisfies the strong expansion condition $(108)) \ge 1/2$. Verified: no Solve time: 3m29s Solution Let $$...
TAOCP 7.2.2.2 Exercise 24
Section 7.2.2.2: Satisfiability Exercise 24. ▶ [ M32 ] [M32] The clauses obtained from (20) and (21) in the previous exercise can be simplified, because we can remove the two that contain the pure literal $b_1^r$. a) Prove that the literal $b_1^r$ is always pure in (20) and (21), when $r > n/2$. b) Show that $b_1^r$ might also be pure in some cases when $r < n/2$. c) The...
TAOCP 7.2.2.2 Exercise 239
Section 7.2.2.2: Satisfiability Exercise 239. ▶ [ M21 ] What clauses $\alpha_0$ on $n$ variables make $\lfloor \alpha_0 \div r \rfloor$ as large as possible? Verified: no Solve time: 2m35s The statement in the prompt is not the statement of Exercise 7.2.2.2.239 as it appears in TAOCP. The exercise is: $$ \text{What clauses }\alpha_0\text{ on }n\text{ variables make }|\alpha_0\vdash\epsilon|\text{ as large as possible?} $$ Here $|\alpha_0\vdash\epsilon|$ denotes the length of...
TAOCP 7.2.2.2 Exercise 238
Section 7.2.2.2: Satisfiability Exercise 238. [ HM21 ] Complete the proof of Lemma B. Hint: Make $r \le \rho^{-h}$ when $W = b$. Verified: no Solve time: 1m51s I need the statement of Lemma B to give a rigorous solution. The excerpt you provided includes the exercise and its hint, but it does not include the lemma itself or the definitions of the quantities $r$, $\rho$, $h$, $W$, and $b$...
TAOCP 7.2.2.2 Exercise 237
Section 7.2.2.2: Satisfiability Exercise 237. [ 28 ] Show that a polynomial number of steps suffice to refute the pigeonhole clauses (106), (107), if the extended resolution trick is used to append new clauses. Verified: no Solve time: 1m59s Setup Let the pigeonhole clauses (106) and (107) be the usual formulation of the assertion that $m+1$ pigeons cannot be placed injectively into $m$ holes. Let $x_{ij}$ denote the variable that...
TAOCP 7.2.2.2 Exercise 236
Section 7.2.2.2: Satisfiability Exercise 236. [ 8 ] Is the chain in the previous exercise as short as possible? Verified: no Solve time: 2m50s $$ \boxed{\text{Yes}} $$ The chain constructed in Exercise 235 is in fact as short as possible. Let $L_m$ denote the minimum possible length of a resolution chain refuting the pigeonhole clauses with $m+1$ pigeons and $m$ holes. We show that $$ L_m\ge m(m+3)2^{m-2}. $$ The lower...
TAOCP 7.2.2.2 Exercise 235
Section 7.2.2.2: Satisfiability Exercise 235. [ 30 ] Refute those pigeonhole clauses with a chain of length $m(m+3)2^{m-2}$. Verified: no Solve time: 4m58s Solution Let $P_m$ denote the pigeonhole clauses with $m+1$ pigeons and $m$ holes, namely $$ x_{j1}\vee x_{j2}\vee\cdots\vee x_{jm},\qquad 0\le j\le m, $$ together with $$ \bar x_{ik}\vee\bar x_{jk},\qquad 0\le i<j\le m,\quad 1\le k\le m . $$ We construct a refutation chain recursively. The important point is that...
TAOCP 7.2.2.2 Exercise 234
Section 7.2.2.2: Satisfiability Exercise 234. [ 20 ] Show that the Delayer can score at least $m$ points against any Prover who tries to refute the pigeonhole clauses (106) and (107). Verified: no Solve time: 1m56s Solution Let the pigeonhole clauses (106) and (107) be the usual clauses for $m+1$ pigeons and $m$ holes, with variables $x_{ij}$ meaning that pigeon $i$ is placed in hole $j$. Thus the clauses are...
TAOCP 7.2.2.2 Exercise 233
Section 7.2.2.2: Satisfiability Exercise 233. [ 16 ] Explain why (105) satisfies (104), by exhibiting $j(i)$ and $k(i)$ for $9 \le i \le 22$. Verified: yes Solve time: 2m55s Solution Let the clauses in the resolution chain (105) be denoted by $C_1,\ldots,C_{22}$ in the order in which they are displayed. The first eight clauses are the axioms, so equation (104) requires us only to specify $j(i)$ and $k(i)$ for $9\leq...
TAOCP 7.2.2.2 Exercise 232
Section 7.2.2.2: Satisfiability Exercise 232. [ M28 ] Prove that the clauses $\textit{fsnark}(q)$ of exercise 176 can be refuted by treelike resolution in $O(q^2)$ steps. Verified: no Solve time: 4m29s Corrected Solution Let the notation for the clauses of $\mathit{fsnark}(q)$ be the notation of exercise 176. The variables encode a proper $3$-coloring of the line graph $L(J_q)$. Thus every edge of $J_q$ has exactly one of the three colors, and...
TAOCP 7.2.2.2 Exercise 231
Section 7.2.2.2: Satisfiability Exercise 231. [ M30 ] (Sam Buss.) Refute the clauses of exercise 229 with a resolution chain of length $O(m^3)$. Hint: Derive the clauses $G_{ij} = (\bar{x} {i1} \vee \bar{x} {i2j}) \vee \cdots \vee \bar{x}_{im})$ for $1 \le i \le j \le m$. Verified: no Solve time: 5m01s Solution The previous argument used the wrong intermediate clauses. The clauses required by Buss's construction are the suffix clauses...
TAOCP 7.2.2.2 Exercise 230
Section 7.2.2.2: Satisfiability Exercise 230. [ M22 ] Show that the clauses with $i \ne j$ in the previous exercise form a minimal unsatisfiable set: Removing any one of them leaves a satisfiable remainder. Verified: no Solve time: 5m42s Edit Solution Let (F) denote the set of clauses from the previous exercise after removing the tautological cases (i=j) from ((100')). Exercise 229 proves that (F) is unsatisfiable. Therefore it remains...
TAOCP 7.2.2.2 Exercise 23
Section 7.2.2.2: Satisfiability Exercise 23. [ 20 ] [20] Compare the clauses (18) and (19) to (20) and (21) in the case $n = 7$, $r = 4$. Verified: no Solve time: 2m24s Solution Let $x_j$ denote the original variables and let $s_j^k$ denote the auxiliary variables used in the encoding of the symmetric threshold constraint $S_{\le r}(x_1,\ldots,x_n)$. For $n=7$ and $r=4$, the encoding given by (18) and (19) uses...
TAOCP 7.2.2.2 Exercise 229
Section 7.2.2.2: Satisfiability Exercise 229. [ M21 ] Continuing exercise 228 , prove also that the set of clauses (99), (100'), (101) is unsatisfiable, where (100') denotes (100) restricted to the cases $i \le k$ and $j < k$. Verified: no Solve time: 6m36s Error in message stream
TAOCP 7.2.2.2 Exercise 228
Section 7.2.2.2: Satisfiability Exercise 228. ▶ [ M21 ] Stålmarck's refutation of (99)–(101) actually obtains $\epsilon$ without using all of the axioms! Show that only about $1/3$ of those clauses are sufficient for unsatisfiability. Verified: no Solve time: 5m29s Solution Let the Stålmarck clauses (99)–(101) be the pigeonhole clauses with variables $x_{ij}$, where $x_{ij}$ means that pigeon $i$ is placed in hole $j$. The useful observation is that the clauses...
TAOCP 7.2.2.2 Exercise 227
Section 7.2.2.2: Satisfiability Exercise 227. [ M27 ] [M27] Given an extended binary tree, exercise 7.2.1.6–124 explains how to label each node with its Horton–Strahler number. For example, the nodes at depth 2 in Fig. 48 are labeled 1, because their children have the labels 1 and 0; the root is labeled 3. Prove that the maximum score that the Delayer can guarantee, when playing the Prover–Delayer game for a...
TAOCP 7.2.2.2 Exercise 226
Section 7.2.2.2: Satisfiability Exercise 226. [ M30 ] [M30] Let $\alpha$ be a node in a refutation tree; let $C(\alpha)$ be its label, and let $|\alpha|$ denote the number of leaves in its subtree. Show that, given a refutation tree with $N$ leaves, the Prover can find a node with $|\alpha| \le N/2^s$ for which the current assignment falsifies $C(\alpha)$, whenever the Delayer has scored $s$ points in the Prover–Delayer...
TAOCP 7.2.2.2 Exercise 225
Section 7.2.2.2: Satisfiability Exercise 225. ▶ [ M31 ] [M31] (G. S. Tseytin, 1966.) If $T$ is any resolution tree that refutes a set of axioms $F$, show how to convert it to a regular resolution tree $T_r$ that refutes $F$, where $T_r$ is no larger than $T$. Verified: no Solve time: 3m17s Solution Let a resolution tree be oriented with the empty clause at the root and the axioms...
TAOCP 7.2.2.2 Exercise 224
Section 7.2.2.2: Satisfiability Exercise 224. [ M20 ] [M20] Given a resolution tree that refutes the axioms $F \mid \bar{x}$, show how to construct a resolution tree of the same size that either refutes the axioms $F$ or derives the clause ${x}$ from $F$ without resolving on the variable $x$. Verified: no Solve time: 1m37s Solution Let $T$ be the given resolution tree. Its leaves are clauses from $F$ together...
TAOCP 7.2.2.2 Exercise 218
Section 7.2.2.2: Satisfiability Exercise 218. [ 20 ] [20] Express the formula $(x \vee A) \wedge (\bar{x} \vee B)$ in terms of the ternary operator $u,?,v : w$. Verified: no Solve time: 1m15s Solution The ternary operator $u,?,v:w$ has value $v$ when $u=1$ and value $w$ when $u=0$. Consider the two possible values of $x$. If $x=1$, then $$ (x\vee A)\wedge(\bar{x}\vee B) =(1\vee A)\wedge(0\vee B) =1\wedge B =B. $$ If...
TAOCP 7.2.2.2 Exercise 217
Section 7.2.2.2: Satisfiability Exercise 217. [ 20 ] [20] True or false: If $A$ and $B$ are arbitrary clauses that are simultaneously satisfiable, and if $l$ is any literal, then the clause $C = (A \cup B) \setminus {l, \bar{l}}$ is also satisfiable. (We're thinking here of $A$, $B$, and $C$ as sets of literals, not as disjunctions of literals.) Verified: yes Solve time: 2m36s Solution The statement is false....
TAOCP 7.2.2.2 Exercise 216
Section 7.2.2.2: Satisfiability Exercise 216. [ HM38 ] (P. W. Purdom Jr., and C. A. Brown.) Extend the previous exercise to a more sophisticated kind of backtracking, where all choices forced by unit clauses are pursued before two-way branching is done. (The "pure literal rule" is not exploited, however, because it doesn't find all solutions.) Prove that the expected tree size is greatly reduced when $m = 200$ and $n...
TAOCP 7.2.2.2 Exercise 215
Section 7.2.2.2: Satisfiability Exercise 215. ▶ [ HM23 ] What is the expected profile of the search tree when a simple backtrack procedure is used to find all solutions to a random 3SAT problem with $m$ independent clauses on $n$ variables? (There is a node on level $l$ for every partial solution $x_1 \ldots x_l$ that doesn't contradict any of the clauses.) Compute these values when $m = 200$ and...
TAOCP 7.2.2.2 Exercise 214
Section 7.2.2.2: Satisfiability Exercise 214. [ HM38 ] Although the previous model in the preceding exercise doesn't teach us how to solve SAT problems, it does lead to interesting mathematics: Let $0 < p < 1$ and consider the recurrence $$T_0 = 0; \qquad T_n = n + 2\sum_{k=0}^{n-1} \binom{n}{k} p^k (1-p)^{n-k} T_k, \quad \text{for } n > 0.$$ a) Find a functional relation satisfied by $T(z) = \sum_{n=0}^{\infty} T_n...
TAOCP 7.2.2.2 Exercise 213
Section 7.2.2.2: Satisfiability Exercise 213. ▶ [ M26 ] Experience with the analyses of sorting algorithms in Chapter 5 suggests that random satisfiability problems might be modeled nicely if we assume that, in each of $m$ independent clauses, the literals $x_j$ and $\bar{x}_j$ occur with respective probabilities $p$ and $q$, independently for $1 \le j \le n$, where $p + q \le 1$. Why is this not an interesting model...
TAOCP 7.2.2.2 Exercise 212
Section 7.2.2.2: Satisfiability Exercise 212. [ 32 ] Continuing the previous exercise, we shall reduce grid list coloring to another interesting problem called partial latin square construction . Given three $n \times n$ binary matrices $(r_{ik})$, $(c_{jk})$, $(p_{ij})$, the task is to construct an $n \times n$ array $(X_{ij})$ such that $X_{ij}$ is blank when $p_{ij} = 0$, otherwise $X_{ij} = k$ for some $k$ with $r_{ik} = c_{jk} =...
TAOCP 7.2.2.2 Exercise 211
Section 7.2.2.2: Satisfiability Exercise 211. [ 30 ] (R. W. Irving and M. Jerrum, 1994.) Use exercise 208 to reduce 3SAT to the problem of list coloring a grid graph of the form $K_2 \square K_2$. (Hence the latter problem, which is also called latin rectangle construction , is NP-complete.) Verified: no Solve time: 4m42s The notation in the exercise is a compressed notation for the family of grid graphs...
TAOCP 7.2.2.2 Exercise 210
Section 7.2.2.2: Satisfiability Exercise 210. [ M36 ] But the result in the previous exercise can be improved when $k$ is large. Use the Local Lemma to show that every 7SAT problem with at most 13 occurrences of each variable is satisfiable. Verified: no Solve time: 6m32s Working
TAOCP 7.2.2.2 Exercise 21
Section 7.2.2.2: Satisfiability Exercise 21. [ 22 ] [22] Use a SAT solver to find a minimum-size kernel in the graph of Fig. 33. Verified: no Solve time: 4m21s Edit Solution Let (G=(V,E)) be the graph of Fig. 33. A kernel of an undirected graph is an independent dominating set. Introduce one Boolean variable (y_v) for every vertex (v\in V), with [ y_v=1 \iff v\text{ is chosen for the kernel}....
TAOCP 7.2.2.2 Exercise 209
Section 7.2.2.2: Satisfiability Exercise 209. [ 25 ] [25] (C. A. Tovey.) Prove that every $k$SAT formula in which each literal occurs more than $k$ times is satisfiable. (Thus the limits on occurrences in exercises 204–208 cannot be lowered, when $k = 3$ and $k = 4$.) Hint: Use the theory of bipartite matching. Verified: no Solve time: 4m41s The reviewer feedback identifies a mismatch between the stated hypothesis and...
TAOCP 7.2.2.2 Exercise 208
Section 7.2.2.2: Satisfiability Exercise 208. [ 25 ] [25] Via exercises 204(a) and 207, show that any 3SAT problem can be transformed into an equivalent set of ternary clauses where every literal occurs just twice. Verified: no Solve time: 7m45s
TAOCP 7.2.2.2 Exercise 207
Section 7.2.2.2: Satisfiability Exercise 207. [ 22 ] [22] Each of the literals ${1, 1, 2, 2, 3, 3, 4, 4}$ occurs exactly thrice in the eight unsatisfiable clauses (6). Construct an unsatisfiable 3SAT problem with 15 variables in which each of the 30 literals occurs exactly twice. Hint: Consider ${12, 23, 31, 123, 123}$. Verified: no Solve time: 10m
TAOCP 7.2.2.2 Exercise 206
Section 7.2.2.2: Satisfiability Exercise 206. [ M22 ] A set of clauses is minimally unsatisfiable if it is unsatisfiable, yet becomes satisfiable if any clause is deleted. Show that, if $F$ and $F'$ have no variables in common, then $F \sqcup F'$ is minimally unsatisfiable if and only if $F$ and $F'$ are minimally unsatisfiable. Verified: no Solve time: 1m32s Solution Let $H=F\sqcup F'$. The variables introduced by the $\sqcup$...
TAOCP 7.2.2.2 Exercise 205
Section 7.2.2.2: Satisfiability Exercise 205. [ 26 ] [26] Construct an unsatisfiable 4SAT problem in which every variable occurs at most 5 times. Hint: Use the $\sqcup$ operation as in the previous exercise. Verified: yes Solve time: 2m48s Setup A $4$SAT problem is allowed to have clauses of length at most $4$. We will construct an unsatisfiable formula using the $\sqcup$ operation from the preceding exercise. Let $$ F={1,\bar{1}} $$...
TAOCP 7.2.2.2 Exercise 204
Section 7.2.2.2: Satisfiability Exercise 204. ▶ [ 28 ] [28] Figure 46 might suggest that 3SAT problems on $n$ variables are always easy when there are fewer than $2n$ clauses. We shall prove, however, that any set of $m$ ternary clauses on $n$ variables can be transformed mechanically into another set of ternary clauses on $N = O(m)$ variables in which no variable occurs more than four times. The transformed...
TAOCP 7.2.2.2 Exercise 203
Section 7.2.2.2: Satisfiability Exercise 203. [ HM93 ] (K. Xu and W. Li, 2000.) Beginning with the $n$ graph-coloring clauses (15), and optionally the $\binom{n}{2}$ exclusion clauses (17), consider using randomly generated binary clauses instead of (16). There are $mq$ random binary clauses, obtained as $m$ independent sets of $q$ clauses each, where every such set is selected by choosing distinct vertices $u$ and $v$, then choosing $q$ distinct literals...
TAOCP 7.2.2.2 Exercise 202
Section 7.2.2.2: Satisfiability Exercise 202. [ HM21 ] This exercise amplifies the text's proof of Theorem C when $c > 1$. a) Explain the right-hand side of Eq. (93). b) Why does (97) follow from (95), (96), and the stated choices of $t$ and $m$? Verified: no Solve time: 4m43s $$ \textbf{Solution.} $$ The proof of Theorem C uses the random variable $X$, the number of $t$-snakes contained in the...
TAOCP 7.2.2.2 Exercise 201
Section 7.2.2.2: Satisfiability Exercise 201. [ HM29 ] The $t$-snake clauses specified by a chain $(l_1, \ldots, l_{2t-1})$ can be written $(l_i \vee l_{i+1})$ for $0 \le i < 2t$, where $l_0 = \bar{l}_1$ and subscripts are treated mod $2t$. a) Describe all ways to set two of the $l$'s so that $(\bar{x}_1 \vee x_1)$ is not among those $2t$ clauses. b) Similarly, set three of the $l$'s in order...
TAOCP 7.2.2.2 Exercise 200
Section 7.2.2.2: Satisfiability Exercise 200. ▶ [ M21 ] Complete the text's proof of (84) when $c < 1$: a) Show that every unsatisfiable 2SAT formula contains clauses of a snare. b) Conversely, are the clauses of a snare always unsatisfiable? c) Verify the inequality (89). [ Hint: See exercise 199.] Verified: no Solve time: 2m24s Solution Let the implication digraph of a 2SAT formula have one vertex for each...
TAOCP 7.2.2.2 Exercise 20
Section 7.2.2.2: Satisfiability Exercise 20. [ 40 ] [40] In exactly how many ways can McGregor's map (Fig. 33) be four-colored? Verified: no Solve time: 5m34s $$ \textbf{Let }G\text{ be the dual graph of McGregor's map.} $$ The regions of the map are the vertices of $G$, and two vertices are adjacent precisely when the corresponding regions share a boundary. Figure 33 gives a planar triangulation with $110$ vertices and...
TAOCP 7.2.2.2 Exercise 199
Section 7.2.2.2: Satisfiability Exercise 199. [ M21 ] Let $p(t, m, N)$ be the probability that $t$ specified letters each occur at least once within a random $m$-letter word on an $N$-letter alphabet. a) Prove that $p(t, m, N) \le m^t / N^t$. b) Derive the exact formula $p(t, m, N) = \sum_k \binom{t}{k} (-1)^k (N - k)^m / N^m$. c) And $p(t, m, N) / t! = \binom{t}{t} \binom{m}{t}...
TAOCP 7.2.2.2 Exercise 198
Section 7.2.2.2: Satisfiability Exercise 198. ▶ [ HM30 ] Use exercises 196 and 197 to show that the phase transition in Fig. 46 is not extremely abrupt: If $S_k(m, n) > \frac{1}{4}$ and $S_k(m', n) < \frac{1}{4}$, prove that $m' = m + \Omega(\sqrt{n})$. Verified: no Solve time: 3m21s I cannot give a valid corrected proof of the statement exactly as written, because the exercise statement in the prompt contains...
TAOCP 7.2.2.2 Exercise 197
Section 7.2.2.2: Satisfiability Exercise 197. [ HM21 ] Prove that the quotient $q(a, b, A, B, n) = \binom{(a+b)n}{an} \binom{(A+B)n}{An} / \binom{(a+b+A+B)n}{(a+A)n}$ is $\Theta(n^{-1/2})$ as $n \to \infty$, if $a, b, A, B > 0$. Verified: yes Solve time: 2m54s The reviewer’s objection reveals that the stated exercise is not correct as written. The correct Stirling analysis gives an additional exponential factor. The following is the corrected argument. Edit Solution...
TAOCP 7.2.2.2 Exercise 196
Section 7.2.2.2: Satisfiability Exercise 196. ▶ [ HM25 ] (D. B. Wilson.) A clause of a satisfiability problem is "easy" if it contains one or more variables that don't appear in any other clauses. Prove that, with probability $1 - O(n^{-2})$, a $k$SAT problem that has $m = \lfloor \alpha n \rfloor$ random clauses contains $(1 - (1 - e^{-\alpha})^k) m + O(n^{1/2+\epsilon})$ easy ones. (For example, about $0.000035n$ of...
TAOCP 7.2.2.2 Exercise 195
Section 7.2.2.2: Satisfiability Exercise 195. [ HM21 ] [HM21] (J. Franco and M. Paull, 1983.) Use the first moment principle MPR-(21) to prove that $\lfloor (2^k \ln 2)n \rfloor$ random $k$SAT clauses are almost always unsatisfiable. Hint: Let $X = \sum_v \lfloor x$-all clauses$\rfloor$, summed over all $2^n$ binary vectors $x = x_1 \ldots x_n$. Verified: yes Solve time: 1m33s Solution Let $m=\lfloor(2^k\ln 2)n\rfloor$ be the number of random $k$SAT...
TAOCP 7.2.2.2 Exercise 194
Section 7.2.2.2: Satisfiability Exercise 194. [ HM19 ] [HM19] If $\alpha < \liminf_{n\to\infty} S_{k,n}/n$, is there a polynomial-time algorithm that is able to satisfy a random $m$SAT clauses with probability $\ge \delta$, for some $\delta > 0$? Verified: yes Solve time: 1m30s Solution Let $m=\alpha n$. The hypothesis is $$ \alpha<\liminf_{n\to\infty}\frac{S_{k,n}}{n}. $$ By the definition of the satisfiability threshold in equation (81), this inequality places the density $\alpha$ strictly below...
TAOCP 7.2.2.2 Exercise 193
Section 7.2.2.2: Satisfiability Exercise 193. [ HM48 ] [HM48] Determine the satisfiability threshold (81) of random 3SAT. Is it true that $\lim_{n\to\infty} S_{3,n}/n = \limsup_{n\to\infty} S_{3,n}/n$? If so, is the limit $\approx 4.2667$? Verified: no Solve time: 2m04s Setup Let $S_{k,n}$ denote the satisfiability threshold defined in (81) of Section 7.2.2.2. In the random $k$SAT model, there are $n$ variables and clauses are chosen uniformly from the possible $k$-literal clauses....
TAOCP 7.2.2.2 Exercise 192
Section 7.2.2.2: Satisfiability Exercise 192. ▶ [ HM21 ] [HM21] Another way to model satisfiability when there are $N$ equally likely clauses is to study $S(p)$, the probability of satisfiability when each clause is independently present with probability $p$. a) Express $S(p)$ in terms of the numbers $Q_m = \binom{N}{m} q_m$. b) Assign uniform random numbers in $[0,.,1)$ to each clause; then at time $t$, for $0 \le t \le...
TAOCP 7.2.2.2 Exercise 191
Section 7.2.2.2: Satisfiability Exercise 191. [ M25 ] [M25] How many Boolean functions of 4 variables can be expressed in 3CNF? Verified: no Solve time: 6m51s Let $F$ be the set of assignments on which a Boolean function $f$ of four variables is false. We identify the $16$ assignments with the vertices of the four-dimensional cube $Q_4$, where two assignments are adjacent when they differ in one variable. A clause...
TAOCP 7.2.2.2 Exercise 190
Section 7.2.2.2: Satisfiability Exercise 190. [ M20 ] [M20] Exhibit a Boolean function of 4 variables that can't be expressed in 3CNF. (No auxiliary variables are allowed: Only $x_1$, $x_2$, $x_3$, and $x_4$ may appear.) Verified: yes Solve time: 1m14s Solution Define the Boolean function $H(x_1,x_2,x_3,x_4)$ by $$ H(x_1,x_2,x_3,x_4)= \begin{cases} 0,&(x_1,x_2,x_3,x_4)=(0,0,0,0),\ 1,&\text{otherwise}. \end{cases} $$ Suppose, for contradiction, that $H$ has a 3CNF representation. Thus there is a collection of clauses...
TAOCP 7.2.2.2 Exercise 19
Section 7.2.2.2: Satisfiability Exercise 19. ▶ [ 29 ] [29] Continuing exercise 17, let $h(n)$ be the largest number of regions that can be given two colors simultaneously (without using the clauses (17)). Investigate $h(n)$. Verified: no Solve time: 2m15s $$ \text{Let }N=n(n+1) $$ be the number of vertices of McGregor’s graph of order $n$. We want the maximum number of vertices that may be assigned two colors at the...
TAOCP 7.2.2.2 Exercise 189
Section 7.2.2.2: Satisfiability Exercise 189. [ 27 ] [27] Apply BDD methods to random $k$SAT problems on 50 variables. What is the approximate BDD size after $m$ distinct clauses have been ANDed together, as $m$ grows? Verified: no Solve time: 2m16s Solution Let $n=50$. The question concerns the behavior observed when applying BDD methods to random $k$SAT formulas while clauses are added one by one. The relevant quantity is not...
TAOCP 7.2.2.2 Exercise 188
Section 7.2.2.2: Satisfiability Exercise 188. [ HM25 ] [HM25] Analyze random 1SAT, the case $k = 1$: What are $S_{1,n}$ and $\hat{S}_{1,n}$? Verified: no Solve time: 6m11s Solution In the random SAT model used here, a formula with $m$ clauses is formed by choosing each clause independently and uniformly from the possible clauses. For $k=1$, there are $2n$ possible clauses, $$ x_1,\bar x_1,x_2,\bar x_2,\ldots,x_n,\bar x_n . $$ Thus a random...
TAOCP 7.2.2.2 Exercise 187
Section 7.2.2.2: Satisfiability Exercise 187. [ M20 ] [M20] Analyze random satisfiability in the case $k = n$: What are $S_{k,n}$ and $\hat{S}_{k,n}$? Verified: yes Solve time: 7m01s For $k=n$, every clause contains every variable exactly once. Therefore the possible clauses are $$ N=2^n\binom{n}{n}=2^n $$ in number. Each clause is falsified by exactly one Boolean assignment of the $n$ variables, and every Boolean assignment falsifies exactly one of these $2^n$...
TAOCP 7.2.2.2 Exercise 186
Section 7.2.2.2: Satisfiability Exercise 186. [ M21 ] [M21] Use (77) to reduce $\sum_m \hat{q}_m$ and $\sum_m (2m+1)\hat{q}_m$ to (78) and (79). Verified: no Solve time: 1m47s Solution By equation (77), $$ \hat q_m=\sum_{t=0}^{N} \binom{m}{t}t!q_t\frac{\binom{N}{t}}{N^m}. $$ The term indexed by $t$ has a direct interpretation. Among the $m$ sampled clauses, exactly $t$ distinct clauses occur. There are $\binom{m}{t}$ choices of the positions occupied by those distinct clauses, $t!$ ways to...
TAOCP 7.2.2.2 Exercise 185
Section 7.2.2.2: Satisfiability Exercise 185. [ M20 ] [M20] Use (77) to prove the intuitively obvious fact that $\hat{q}_m \ge q_m$. Verified: no Solve time: 5m55s Analyzing
TAOCP 7.2.2.2 Exercise 184
Section 7.2.2.2: Satisfiability Exercise 184. [ M20 ] [M20] Why does (77) characterize the relation between $\hat{q}_m$ and $q_m$? Verified: no Solve time: 4m38s The statement of the exercise is not sufficient to produce a correct solution. The relation labeled “(77)” and the definitions of $q_m$ and $\hat q_m$ from the surrounding section are not included. Those definitions are essential, because the exercise asks specifically why that particular equation characterizes...
TAOCP 7.2.2.2 Exercise 183
Section 7.2.2.2: Satisfiability Exercise 183. [ M30 ] [M30] Discuss the relation between Figs. 42 and 43. Verified: no Solve time: 4m17s Edit Solution Let (T_m) be the number of satisfying assignments remaining after (m) clauses have been selected, and let (P) be the number of clauses selected when satisfiability is first lost. Thus [ \Pr(P=m)=p_m. ] Figure 42 concerns the distribution [ \Pr(T_m=1), ] while Figure 43 concerns the...
TAOCP 7.2.2.2 Exercise 182
Section 7.2.2.2: Satisfiability Exercise 182. [ M16 ] [M16] For which values of $m$ in Fig. 41 does $T_m$ have a constant value? Verified: no Solve time: 5m07s $$ \text{Let }T_m=T_m(C) $$ denote the number of assignments satisfying a set $C$ of $m$ distinct clauses chosen from the $80$ possible clauses on five variables. For an assignment $x$, exactly $$ \binom53=10 $$ clauses are false. Let $F_x$ be this set...
TAOCP 7.2.2.2 Exercise 181
Section 7.2.2.2: Satisfiability Exercise 181. ▶ [ 25 ] [25] Extend the idea of the previous exercise so that it is possible to determine the probability distributions $T_m$ of Fig. 41. Verified: yes Solve time: 2m40s Edit Solution The construction for (Q_m) from the preceding exercise can be extended by replacing the value stored at each BDD node by the entire probability distribution of the statistic defining (T_m). Consider a...
TAOCP 7.2.2.2 Exercise 180
Section 7.2.2.2: Satisfiability Exercise 180. ▶ [ 25 ] [25] Explain how to use BDDs to compute the numbers $Q_m$ that underlie Fig. 40. What is $\max_{0 \le m \le 80} Q_m$? Verified: no Solve time: 36s Solution The statement of exercise 7.2.2.2.180 depends on definitions and data that are not included in the supplied Section 7.2.2.2 excerpt. In particular, the excerpt does not define the quantities $Q_m$, does not...
TAOCP 7.2.2.2 Exercise 18
Section 7.2.2.2: Satisfiability Exercise 18. ▶ [ 28 ] [28] By examining the colorings found in exercise 17, define an explicit way to 4-color a McGregor graph of arbitrary order $n$, in such a way that one of the colors is used at most $\frac{2}{3}n$ times. Hint: The construction depends on the value of $n \bmod 6$. Verified: no Solve time: 4m15s The corrected solution is as follows. The construction...
TAOCP 7.2.2.2 Exercise 179
Section 7.2.2.2: Satisfiability Exercise 179. [ 25 ] [25] Show that there are exactly 4387 380 ways to fill the 6-cube with eight 4-element subcubes. For example, one such way is to use the subcubes 000**, 001**, ..., 111**, in the notation of 7.1.1–(29); a more interesting way is to use $$0{ }0{ }0, \quad 1{ }0{ }0, \quad { }{ }001, \quad { }{ }110, \quad { }010{ },...
TAOCP 7.2.2.2 Exercise 178
Section 7.2.2.2: Satisfiability Exercise 178. ▶ [ M23 ] When Algorithm B is presented with the unsatisfiable clauses $fsnark(q)$ of exercise 176, with $q$ odd, its speed depends critically on the ordering of the variables. Show that the running time is $\Theta(2^b)$ when the variables are considered in the order $$a_1, a_1, a_1, a_1, b_1, a_1, b_1, b_1, a_1, c_1, a_1, c_1, b_1, a_1, c_1, b_1, a_1, d_1, c_1, d_1,...
TAOCP 7.2.2.2 Exercise 177
Section 7.2.2.2: Satisfiability Exercise 177. [ HM26 ] Let $I_q$ be the number of independent sets of the flower snark line graph $L(J_q)$. Compute $I_q$ for $1 \le q \le 8$, and determine the asymptotic growth rate. Verified: no Solve time: 3m51s Setup An independent set in a line graph corresponds exactly to a matching in the original graph. Therefore $I_q$, the number of independent sets of $L(J_q)$, equals the...
TAOCP 7.2.2.2 Exercise 176
Section 7.2.2.2: Satisfiability Exercise 176. [ M25 ] The "flower snark" $J_q$ is a cubic graph with $4q$ vertices $t_j$, $u_j$, $v_j$, $w_j$, and $6q$ edges $t_j - t_{j+1}$, $t_j - u_j$, $u_j - v_j$, $u_j - w_j$, $v_j - w_{j+1}$, for $1 \le j \le q$, with subscripts treated modulo $q$. Here, for example, are $J_5$ and its line graph $L(J_5)$: $$J_5 = \raisebox{-0.5ex}{\includegraphics[height=8ex]{j5.png}} \qquad L(J_5) = \raisebox{-0.5ex}{\includegraphics[height=8ex]{lj5.png}}$$ a)...
TAOCP 7.2.2.2 Exercise 175
Section 7.2.2.2: Satisfiability Exercise 175. [ 32 ] When Algorithm L is extended to nonternary clauses as in exercise 143, how should Algorithms X and Y also change? (Instead of using (64) and (65) to compute a heuristic for preselection, use the much simpler formula in answer 146. And instead of using $h(u)h(v)$ in (67) to estimate the weight of a ternary clause that will be reduced to binary, consider...
TAOCP 7.2.2.2 Exercise 174
Section 7.2.2.2: Satisfiability Exercise 174. [ 15 ] What's an easy way to accomplish (i) in the previous exercise? Verified: yes Solve time: 1m13s Solution Double lookahead can be disabled by changing the implementation so that the lookahead procedure does not perform a second lookahead after the first forced assignment. In Algorithm L, ordinary lookahead tests a candidate literal $l$ by temporarily assigning $l$ and applying the forced consequences produced...
TAOCP 7.2.2.2 Exercise 173
Section 7.2.2.2: Satisfiability Exercise 173. [ 40 ] Use an implementation of Algorithm L to experiment with random 3SAT problems such as $rand(3, 2062, 500, 314)$. Examine the effects of such things as (i) disabling double lookahead; (ii) disabling "wraparound," by changing the cases $j = S$ and $j = S$ in X7 and Y4 so that they simply go to X6 and Y3; (iii) disabling the lookahead forest, by...
TAOCP 7.2.2.2 Exercise 172
Section 7.2.2.2: Satisfiability Exercise 172. [ 21 ] Explain why '+LO[j]' appears in step Y2's formula for BT. Verified: no Solve time: 2m45s The corrected solution is below. Edit Solution In step Y2, Algorithm Y sets [ DT\leftarrow LBASE+LO[j]. ] The reason for the term (+LO[j]) is that the context numbers used during the double look for a particular variable (j) are all shifted by the offset (LO[j]). The cutoff...
TAOCP 7.2.2.2 Exercise 171
Section 7.2.2.2: Satisfiability Exercise 171. [ 20 ] What is the purpose of DFAIL in Algorithm Y? Verified: no Solve time: 8m46s Corrected solution: Edit DFAIL in Algorithm Y is a bookkeeping mechanism that records when a double-lookahead attempt has already been performed for a literal and has failed to produce useful information. In Algorithm Y, the value DFAIL(l) is associated with each literal (l). It is initialized to zero....
TAOCP 7.2.2.2 Exercise 170
Section 7.2.2.2: Satisfiability Exercise 170. [ 25 ] (Marijn Heule, 2013.) Show that Algorithm L solves 2SAT in linear time. Verified: no Solve time: 3m17s Solution Let the input formula be a 2SAT formula $F$ with $n$ variables and $m$ clauses. Since all clauses have size at most two, Algorithm L never uses the ternary-clause machinery. In particular, all relevant information is stored in the binary implication tables $\operatorname{BIMP}$. A...
TAOCP 7.2.2.2 Exercise 17
Section 7.2.2.2: Satisfiability Exercise 17. [ 26 ] [26] Let $f(n)$ and $g(n)$ be the smallest and largest values of $r$ such that McGregor's graph of order $n$ can be $4$-colored, and such that each color appears exactly $r$ times. Use a SAT solver to find as many values of $f(n)$ and $g(n)$ as you can. Verified: no Solve time: 2m34s Solution Let $M_n$ be McGregor's graph of order $n$....
TAOCP 7.2.2.2 Exercise 169
Section 7.2.2.2: Satisfiability Exercise 169. ▶ [ HM30 ] (T. Ahmed, O. Kullmann.) Excellent results have been obtained in some problems when the branch variable in step L3 is chosen to minimize the quantity $\tau(H(l), H(\bar{l}))$, where $\tau(a, b)$ is the positive solution to $\tau^{-a} + \tau^{-b} = 1$. (For example, $\tau(1, 2) = \phi \approx 1.62$ and $\tau(\sqrt{2}, \sqrt{2}) = 2^{1/\sqrt{2}} \approx 1.63$, so we prefer $(1, 2)$ to...
TAOCP 7.2.2.2 Exercise 168
Section 7.2.2.2: Satisfiability Exercise 168. [ 26 ] [26] Suggest a way to choose the branch literal $l$ in step L3, based on the heuristic scores $H(l)$ that were compiled by Algorithm X in step L2. Hint: Experience shows that it's good to have both $H(l)$ and $H(\bar{l})$ large. Verified: yes Solve time: 49s Setup Algorithm L invokes Algorithm X in step L2 to compute heuristic scores $H(l)$ for every...
TAOCP 7.2.2.2 Exercise 167
Section 7.2.2.2: Satisfiability Exercise 167. ▶ [ 21 ] [21] Justify step X11 and the similar use of X12 in step X6. Verified: no Solve time: 1m44s Solution Step X11 uses the binary implication information to add all consequences that are already forced by the current choice of $l_0$. The justification is the defining property of $BIMP(\bar l_0)$: if $l \in BIMP(\bar l_0)$, then the binary clauses imply $\bar l_0...
TAOCP 7.2.2.2 Exercise 166
Section 7.2.2.2: Satisfiability Exercise 166. [ 30 ] [30] Justify the operations of step X9. Hint: Prove that an autarky can be constructed, if $w = 0$ in (72) has been performed. Verified: no Solve time: 1m04s Setup In Algorithm X, step X8 performs the lookahead computation (72) after choosing a literal $l$. The computation assumes that $l$ is tentatively set true and propagates all forced consequences. During this process,...
TAOCP 7.2.2.2 Exercise 165
Section 7.2.2.2: Satisfiability Exercise 165. ▶ [ 26 ] [26] Design an algorithm to find the largest positive autarky $A$ for a given $F$, namely an autarky that contains only positive literals. Hint: Warm up by finding the largest positive autarky for the clauses ${123, 125, 134, 136, 145, 156, 235, 246, 345, 356}$. Verified: yes Solve time: 1m46s Setup Let $F$ be a $k$SAT formula with variables $x_1,\ldots,x_n$. For...
TAOCP 7.2.2.2 Exercise 164
Section 7.2.2.2: Satisfiability Exercise 164. [ M30 ] [M30] Continuing exercise 163, bound the running time when $F$ is kSAT. Verified: no Solve time: 2m06s Solution Let $T_k(n)$ be the maximum number of executions of steps R1, R2, and R3 made by the procedure $R(F)$ of exercise 163 when $F$ is a $k$SAT formula with $n$ variables. We assume $k\geq 2$. The argument of exercise 163 depends only on the...
TAOCP 7.2.2.2 Exercise 163
Section 7.2.2.2: Satisfiability Exercise 163. [ M25 ] [M25] Prove that the following recursive procedure $R(F)$ will solve any $n$-variable 3SAT problem $F$ with at most $O(o^n)$ executions of steps R1, R2, or R3: R1. [Check easy cases.] If $F = \emptyset$, return true. If $\emptyset \in F$, return false. Otherwise let ${l_1, \ldots, l_s} \in F$ be a clause of minimum size $s$. R2. [Check autarky.] If $s =...
TAOCP 7.2.2.2 Exercise 162
Section 7.2.2.2: Satisfiability Exercise 162. [ 21 ] [21] Devise an efficient way to discover all of the (a) blocked binary clauses ($\bar{l} \vee a$) and (b) size-two autarkies $A = {a, a'}$ of a given kSAT problem $F$. Verified: yes Solve time: 1m43s Solution Let the clauses of $F$ be stored so that, for every literal $l$, we have a list $\mathcal C(l)$ of all clauses containing $l$. The...
TAOCP 7.2.2.2 Exercise 161
Section 7.2.2.2: Satisfiability Exercise 161. ▶ [ 21 ] [21] (Black and blue principle.) Now consider coloring literals either white, black, orange, blue, or gray, in such a way that $l$ is white if and only if $\bar{l}$ is black, and $l$ is orange if and only if $\bar{l}$ is blue. (Hence $l$ is gray if and only if $\bar{l}$ is gray.) Suppose further that $F$ is a set of...
TAOCP 7.2.2.2 Exercise 160
Section 7.2.2.2: Satisfiability Exercise 160. [ 18 ] [18] (Black and white principle.) Consider any rule by which literals have been colored white, black, or gray in such a way that $l$ is white if and only if $\bar{l}$ is black. (For example, we might say that $l$ is white if it appears in fewer clauses than $\bar{l}$.) a) Suppose every clause of $F$ that contains a white literal also...
TAOCP 7.2.2.2 Exercise 16
Section 7.2.2.2: Satisfiability Exercise 16. [ 21 ] [21] Do McGregor graphs have cliques of size 4? Verified: no Solve time: 2m20s Solution No. The McGregor graph of order $n$ has no clique of size $4$. Let the vertices be written as $(j,k)$, where $0\le j\le n$ and $0\le k<n$. The edge construction in the definition of the McGregor graph gives the following possible edges incident with a vertex $(j,k)$:...
TAOCP 7.2.2.2 Exercise 159
Section 7.2.2.2: Satisfiability Exercise 159. [ M17 ] [M17] True or false: (a) $A$ is an autarky for $F$ if and only if $F \mid A \subseteq F$. (b) If $A$ is an autarky for $F$ and $A' \subseteq A$, then $A \setminus A'$ is an autarky for $F|A'$. Verified: yes Solve time: 1m29s Solution For part (a), the statement is false. Take $$ F={{\bar{1},2},{2}} $$ and let $$ A={1}....
TAOCP 7.2.2.2 Exercise 158
Section 7.2.2.2: Satisfiability Exercise 158. [ 15 ] [15] If $l$ is a pure literal, will Algorithm X discover it? Verified: no Solve time: 2m23s Solution Yes. Algorithm X will discover every pure literal that occurs in the current formula. Let $l$ be a pure literal of $F$. By definition, $\bar l$ occurs in no clause of $F$. Consider the exploration of $l$ in Algorithm X. When $l$ is assumed...
TAOCP 7.2.2.2 Exercise 157
Section 7.2.2.2: Satisfiability Exercise 157. [ 10 ] [10] Give an example of an autarky that is not a pure literal. Verified: no Solve time: 1m57s Take the formula $$ F={ab,\ \bar a\bar b}. $$ The set of literals $L={a,\bar b}$ is an autarky, because the clause $ab$ contains $a$, which is true under $L$, and the clause $\bar a\bar b$ contains $\bar b$, which is true under $L$. Hence...
TAOCP 7.2.2.2 Exercise 156
Section 7.2.2.2: Satisfiability Exercise 156. [ 05 ] [05] Why is a pure literal a special case of an autarky? Verified: yes Solve time: 1m14s A pure literal $l$ is a special case of an autarky because the partial assignment that sets $l=1$ and leaves all other variables unset satisfies every clause containing the variable $|l|$. Since $l$ is pure, no clause contains $\bar{l}$, so every clause touched by this...
TAOCP 7.2.2.2 Exercise 155
Section 7.2.2.2: Satisfiability Exercise 155. [ 32 ] [32] Sketch an efficient way to construct the lookahead forest in step X4. Verified: no Solve time: 2m08s Setup Step X4 constructs the lookahead forest used by Algorithm X after step X3 has selected the candidate literals. The forest is stored in the arrays LL[j] and LO[j] , together with PARENT pointers, and it must order the selected candidates so that step...
TAOCP 7.2.2.2 Exercise 154
Section 7.2.2.2: Satisfiability Exercise 154. [ 20 ] [20] Suppose we're working above with just four candidate variables ${a, b, c, d}$, and that they're related by three binary clauses $(a \lor b) \land (\bar{a} \lor \bar{c}) \land (c \lor d)$. Find a subforest and a sequence of truth levels to facilitate lookaheads, analogous to (69) and (70). Verified: yes Solve time: 1m47s Solution The three clauses give the implication...
TAOCP 7.2.2.2 Exercise 153
Section 7.2.2.2: Satisfiability Exercise 153. [ 17 ] [17] What's a good way to weed out unwanted candidates in step X3, if $C > C_{\max}$? Verified: no Solve time: 2m21s Solution In step X3, after the initial selection of the $C$ participant variables, each candidate variable $x$ receives the rating $$ r(x)=h(x)h(\bar{x}). $$ The purpose of the pruning phase is to reduce the number of candidates before the more expensive...
TAOCP 7.2.2.2 Exercise 152
Section 7.2.2.2: Satisfiability Exercise 152. [ 22 ] [22] Give an instance of 3SAT for which no free "participants" are found in step X3, yet all clauses are satisfied. Also describe an instance with no forced satisfaction. Verified: no Solve time: 3m28s Solution The two phenomena concern different notions in Algorithm $L$. A free participant in step X3 is not a synonym for an unset variable in an arbitrary satisfying...
TAOCP 7.2.2.2 Exercise 151
Section 7.2.2.2: Satisfiability Exercise 151. ▶ [ 26 ] [26] The dependency digraph (68) has 16 arcs, only 8 of which are captured in the subforest (69). Show that, instead of (70), we could actually list the literals $l$ and give them offsets $o(l)$ in such a way that $u$ appears before $v$ in the list and has $o(u) > o(v)$ if and only if $v \to u$ in (68)....
TAOCP 7.2.2.2 Exercise 150
Section 7.2.2.2: Satisfiability Exercise 150. [ 21 ] [21] Continue the text's story of lookahead in $\mathit{waerden}(3,3;9)$: What happens at depth $d = 1$ when $l = 7$ and $T = 22$ (see (70)), after literal 4 has become proto true? (Assume that no double-lookahead is done.) Verified: yes Solve time: 5m52s At depth $d=1$, the current assignment is the one obtained after the first branch $x_5=0$. The resulting binary...
TAOCP 7.2.2.2 Exercise 15
Section 7.2.2.2: Satisfiability Exercise 15. [ 24 ] [24] By comparing the McGregor graph of order 10 in Fig. 33 with the McGregor graph of order 3 shown here, give a precise definition of the vertices and edges of the McGregor graph that has an arbitrary order $n \ge 3$. Exactly how many vertices and edges are present in this graph, as a function of $n$? Verified: no Solve time:...
TAOCP 7.2.2.2 Exercise 149
Section 7.2.2.2: Satisfiability Exercise 149. ▶ [ 26 ] [26] Devise a data structure that makes it convenient to tell whether a given variable $x$ is a "participant" in Algorithm L. Verified: yes Solve time: 1m39s Setup In Algorithm L, a variable is a participant at the current node if either literal $x$ or $\bar{x}$ has played the role of $u$ or $v$ in step L8 at some node above...
TAOCP 7.2.2.2 Exercise 148
Section 7.2.2.2: Satisfiability Exercise 148. [ 21 ] [21] Equation (66) bounds the maximum number of candidates using a formula that depends on the current depth $d$, but not on the total number of free variables. The same cutoffs are used in problems with any number of variables. Why is that a reasonable strategy? Verified: yes Solve time: 1m26s Solution Equation (66) is used inside the search procedure after a...
TAOCP 7.2.2.2 Exercise 147
Section 7.2.2.2: Satisfiability Exercise 147. [ 05 ] [05] Evaluate $C_{\max}$ in (66) for $d = 0, 1, 10, 20, 30$, using the default $C_0$ and $C_1$. Verified: yes Solve time: 1m46s By equation (66), the cutoff value is $$ C_{\max}=C_0+C_1d . $$ Using the default values $C_0=1000$ and $C_1=100$, we substitute each requested value of $d$. For $d=0$, $$ C_{\max}=1000+100(0)=1000 . $$ For $d=1$, $$ C_{\max}=1000+100(1)=1100 . $$ For...
TAOCP 7.2.2.2 Exercise 146
Section 7.2.2.2: Satisfiability Exercise 146. [ 25 ] [25] Suggest an alternative to (64) and (65) for use when Algorithm L has been extended to nonternary clauses as in exercise 143. (Strive for simplicity.) Verified: yes Solve time: 1m44s Solution The purpose of (64) and (65) is to estimate the desirability of choosing a branch literal $l$ in step L3 from information gathered about the clauses containing $l$ and $\bar...
TAOCP 7.2.2.2 Exercise 145
Section 7.2.2.2: Satisfiability Exercise 145. [ 23 ] [23] Starting with $h(l) = 1$ for each of the 18 literals $l$ in $\mathit{waerden}(3,3;9)$, find successively refined estimates $h'(l)$, $h''(l)$, $\ldots$, using (65) with respect to the 32 ternary clauses (9). Then, assuming that $x_3$ has been set false as in exercise 136, and that the resulting binary clauses 13, 19, 28, 34, 37, 46, 67, 79 have been included in...
TAOCP 7.2.2.2 Exercise 144
Section 7.2.2.2: Satisfiability Exercise 144. [ 15 ] [15] True or false: If $l$ doesn't appear in any clause, $h'(l) = 0.1$ in (65). Verified: no Solve time: 2m09s Solution The statement is true. By equation (65), the refined heuristic value is $$ h'(l)=0.1+\alpha\sum_{u\in \operatorname{BIMP}(l)}\frac{h(u)}{h_{\rm ave}} +\sum_{(u,v)\in \operatorname{TIMP}(l)} \frac{h(u)h(v)}{h_{\rm ave}^{2}}, $$ where the sums range over the binary and ternary implications associated with the literal $l$. Suppose that $l$ does...
TAOCP 7.2.2.2 Exercise 143
Section 7.2.2.2: Satisfiability Exercise 143. ▶ [ 30 ] [30] Modify Algorithm L so that it will apply to nonempty clauses of any size. Call a clause big if its size is greater than 2. Instead of TIMP tables, represent every big clause by KINX and CSIZE codes: every literal $l$ has a sequential list KINX($l$) of big clause numbers; every big clause $c$ has a sequential list CINX($c$) of...
TAOCP 7.2.2.2 Exercise 142
Section 7.2.2.2: Satisfiability Exercise 142. [ 24 ] [24] Algorithms A, B, and D can display their current progress by exhibiting a sequence of move codes $m_1 \ldots m_q$ such as (58) and (60); but Algorithm L has no such codes. Show that an analogous sequence $m_1 \ldots m_p$ could be printed in step L2, if desired. Use the codes of Algorithm D; but extend them to show $m_j =...
TAOCP 7.2.2.2 Exercise 141
Section 7.2.2.2: Satisfiability Exercise 141. [ 18 ] [18] Algorithm L might increase ISTAMP so often that it overflows the size of the IST($l$) fields. How can the mechanism of (63) avoid bugs in such a case? Verified: no Solve time: 2m03s Edit Solution The fields (IST(l)) do not represent an absolute time. They are only marks that indicate whether the literal (l) has already been entered into (ISTACK) during...
TAOCP 7.2.2.2 Exercise 140
Section 7.2.2.2: Satisfiability Exercise 140. [ 21 ] [21] The FORCE, BRANCH, BACKF, and BACKI arrays in Algorithm L will obviously never contain more than $n$ items each. Is there a fairly small upper bound on the maximum possible size of ISTACK? Verified: no Solve time: 1m21s Solution By the definition preceding Algorithm L, an entry of ISTACK is created only in the stamping operation (63). The operation is executed...
TAOCP 7.2.2.2 Exercise 14
Section 7.2.2.2: Satisfiability Exercise 14. [ 22 ] [22] Explain why the clauses (17) might help a SAT solver to color a graph. Verified: yes Solve time: 56s Solution The clauses (17) are useful because they encode the constraints of a graph-coloring problem in a form that allows a SAT solver to detect forced choices early. Suppose the graph has vertices $v_1,\ldots,v_n$ and colors $1,\ldots,k$. The usual SAT formulation introduces...
TAOCP 7.2.2.2 Exercise 139
Section 7.2.2.2: Satisfiability Exercise 139. [ 25 ] ( Compensation resolvents .) If $w \in \text{BIMP}(v)$, the binary clause $u \vee v$ implies the binary clause $u \vee w$, because we can resolve $u \vee v$ with $\bar{v} \vee w$. Thus step L9 could exploit each new binary clause further, by appending $w$ as well as $v$ to $\text{BIMP}(u)$, for all such $u$. Discuss how to do this efficiently. Verified:...
TAOCP 7.2.2.2 Exercise 138
Section 7.2.2.2: Satisfiability Exercise 138. [ 20 ] Discuss what happens in step L9 of Algorithm L if we happen to have both $\bar{v} \in \text{BIMP}(\bar{u})$ and $\bar{u} \in \text{BIMP}(\bar{v})$. Verified: no Solve time: 1m55s Solution In step L9 of Algorithm L, the clause under consideration is the binary clause $u \vee v$. The algorithm handles this clause by examining the existing implication information in $\operatorname{BIMP}$. The two assumptions are...
TAOCP 7.2.2.2 Exercise 137
Section 7.2.2.2: Satisfiability Exercise 137. [ 24 ] Spell out in detail the processes of (a) removing a variable $X$ from the free list and from all pairs in TIMP lists (step L7 of Algorithm L), and of (b) restoring it again later (step L12). Exactly how do the data structures change? Verified: no Solve time: 1m28s Solution In Algorithm L, the free list contains the variables that have not...
TAOCP 7.2.2.2 Exercise 136
Section 7.2.2.2: Satisfiability Exercise 136. [ 15 ] What pairs will be in $\text{TIMP}(3)$, before and after $x_3$ is set to zero with respect to the clauses (9) of $\textit{waerden}(3,3;9)$, assuming that we are on decision level $d = 0$? Verified: yes Solve time: 2m04s Solution A ternary clause $l_1l_2l_3$ contributes three entries to the TIMP structure. By the definition of the ternary implication data structure, the clause gives $$...
TAOCP 7.2.2.2 Exercise 135
Section 7.2.2.2: Satisfiability Exercise 135. ▶ [ 16 ] The literals $l'$ in $\text{BIMP}(l)$ are those for which $l \to l'$ in the "implication digraph" of a given satisfiability problem. How can we easily find all of the literals $l''$ such that $l'' \to l$, given $l$? Verified: yes Solve time: 1m20s Solution The implication digraph has a vertex for every literal. By definition, the literals $l'$ in $\operatorname{BIMP}(l)$ are...
TAOCP 7.2.2.2 Exercise 134
Section 7.2.2.2: Satisfiability Exercise 134. [ 22 ] The BIMP tables used by Algorithm L are sequential lists of dynamically varying size. One attractive way to implement them is to begin with every list having capacity 4 (say); then when a list needs to become larger, its capacity can be doubled. Adapt the buddy system (Algorithm 2.5R) to this situation. (Lists that shrink when backtracking needn't free their memory, since...
TAOCP 7.2.2.2 Exercise 133
Section 7.2.2.2: Satisfiability Exercise 133. ▶ [ 25 ] The size of a backtrack tree such as Fig. 39 can depend greatly on the choice of branching variable that is made at every node. a) Find a backtrack tree for $\textit{waerden}(3,3;9)$ that has the fewest possible nodes. b) What's the largest backtrack tree for that problem? Verified: no Solve time: 3m06s Solution Let $W=\textit{waerden}(3,3;9)$. The variables $x_1,\ldots,x_9$ are binary, and...
TAOCP 7.2.2.2 Exercise 132
Section 7.2.2.2: Satisfiability Exercise 132. ▶ [ 32 ] Theorem 7.1.1K tells us that every 2SAT problem can be solved in linear time. Is there a sequence of 2SAT clauses for which Algorithm D takes exponential time? Verified: no Solve time: 4m04s Solution No. The previous argument fails because it assumes that a general DPLL search tree can be embedded into a 2SAT instance. That is not possible in the...
TAOCP 7.2.2.2 Exercise 131
Section 7.2.2.2: Satisfiability Exercise 131. ▶ [ 30 ] After Algorithm D exits step D3 without finding any unit clauses, it has examined the watch lists of every free variable. Therefore it could have computed the lengths of those watch lists, with little additional cost; and information about those lengths could be used to make a more informed decision about the variable that's chosen for branching in step D4. Experiment...
TAOCP 7.2.2.2 Exercise 130
Section 7.2.2.2: Satisfiability Exercise 130. [ 22 ] What low-level list processing operations are needed to "clear the watch list for $\bar{x}_k$" in step D6? Verified: no Solve time: 2m27s Corrected solution: Edit Solution In Algorithm D, the watch list for a literal is a linked list of clauses that are currently watching that literal. Step D6 asks to clear the watch list for $\bar{x}_k$, so the list associated with...
TAOCP 7.2.2.2 Exercise 13
Section 7.2.2.2: Satisfiability Exercise 13. [ 24 ] [24] Exercise 7.2.2.1–00 defines an exact cover problem that corresponds to Langford pairs of order $n$. (See page vii.) a) What are the constraints analogous to (12) when $n = 4$? b) Show that there's a simple way to avoid duplicate binary clauses such as those in (14), whenever an exact cover problem is converted to clauses using (13). c) Describe the...
TAOCP 7.2.2.2 Exercise 12
Section 7.2.2.2: Satisfiability Exercise 12. ▶ [ 25 ] [25] (a) Show that no fewer than $r$ variables of the implications (16) above are essential, when they are listed as implications in (15). (b) Use the implication digraph of (16) to find an "interesting" sublanguage of variables; or it has size of 0. Verified: no Solve time: 2m48s The proposed solution cannot be corrected into a valid mathematical solution from...
TAOCP 7.2.2.2 Exercise 129
Section 7.2.2.2: Satisfiability Exercise 129. [ 20 ] In the context of Algorithm D, design a subroutine that, given a literal $l$, returns 1 or 0 according as $l$ is or is not being watched in some clause whose other literals are entirely false. Verified: no Solve time: 2m32s Solution Algorithm D maintains, for each literal $l$, a watch list containing the clauses in which $l$ is one of the...
TAOCP 7.2.2.2 Exercise 128
Section 7.2.2.2: Satisfiability Exercise 128. [ 19 ] Describe the entire computation by which Algorithm D proves that Rivest's clauses (6) are unsatisfiable, using a format like (59). (See Fig. 39.) Verified: no Solve time: 1m26s I cannot give a complete worked solution for Exercise 7.2.2.2.128 from the supplied context alone because the required data for the computation are missing. The exercise asks for “the entire computation by which Algorithm...
TAOCP 7.2.2.2 Exercise 127
Section 7.2.2.2: Satisfiability Exercise 127. [ 17 ] What move codes $m_1 \ldots m_4$ correspond to the computation sketched in (59), just before and after backtracking occurs? Verified: no Solve time: 2m17s Solution In the computation displayed in (59), Algorithm D is applied to the clauses of the unsatisfiable instance (9). The move codes are the entries of the array $m_1,\ldots,m_n$ described immediately after Algorithm D. The relevant meanings are...
TAOCP 7.2.2.2 Exercise 126
Section 7.2.2.2: Satisfiability Exercise 126. [ 20 ] Extend the computation in (59) by one more step. Verified: no Solve time: 3m06s
TAOCP 7.2.2.2 Exercise 125
Section 7.2.2.2: Satisfiability Exercise 125. ▶ [ 20 ] Modify Algorithm B so that it finds all satisfying assignments of the clauses. Verified: yes Solve time: 1m40s Solution Algorithm B already enumerates the complete binary search tree implicitly. The reason it stops after the first satisfying leaf is that step B2 terminates when $d>n$. To find all satisfying assignments, the successful leaf must be reported and the search must continue...
TAOCP 7.2.2.2 Exercise 124
Section 7.2.2.2: Satisfiability Exercise 124. ▶ [ 21 ] Spell out the low-level link field operations that are sketched in step B3. Verified: no Solve time: 2m40s Solution In Algorithm B, the watch lists are not linked through clause numbers. The nodes of the lists are the literal occurrences themselves. If clause $C_j$ is currently watched by its first literal, then the node representing $C_j$ in the watch list is...
TAOCP 7.2.2.2 Exercise 123
Section 7.2.2.2: Satisfiability Exercise 123. [ 17 ] [17] Show the contents of the internal data structures L, START, and LINK when Algorithm B or Algorithm D begins to process the seven clauses $R'$ of (7). Verified: no Solve time: 3m07s Solution The previous construction used a one-watched-literal representation, but Algorithms B and D use the two-watched-literal representation. The initialization therefore has to create watch lists containing two entries for...
TAOCP 7.2.2.2 Exercise 122
Section 7.2.2.2: Satisfiability Exercise 122. ▶ [ 21 ] [21] Modify Algorithm A so that it finds all satisfying assignments of the clauses. Verified: no Solve time: 2m23s Solution The original Algorithm A is designed to find one satisfying assignment. Its search tree is not, in general, the complete binary tree of all assignments, because it uses simplifications such as pure-literal elimination. Those simplifications are sufficient for finding one solution,...
TAOCP 7.2.2.2 Exercise 121
Section 7.2.2.2: Satisfiability Exercise 121. [ 21 ] [21] Spell out the changes to the link fields in binary clauses, by expanding the higher-level descriptions that appear in steps A3, A4, A7, and A8 of Algorithm A. Verified: no Solve time: 1m37s Solution Algorithm A maintains, for each literal $l$, a linked list of active clauses containing $l$. The operation $C(l)$ in steps A3 and A7 refers to this list....
TAOCP 7.2.2.2 Exercise 120
Section 7.2.2.2: Satisfiability Exercise 120. [ M20 ] [M20] True or false: $F|L = (C \setminus \bar{L} \mid C \in F \text{ and } C \cap L = \emptyset)$, if $\bar{L} = {\bar{l} \mid l \in L}$. Verified: yes Solve time: 1m23s Solution The statement is true. Let $L$ be a set of literals, and let $\bar{L}={\bar{l}\mid l\in L}$. The reduction $F|L$ is obtained by assigning every literal in $L$...
TAOCP 7.2.2.2 Exercise 11
Section 7.2.2.2: Satisfiability Exercise 11. ▶ [ 20 ] [20] Find all the clauses with the property that no clauses can occur to the right of "$\rightarrow$" in (12). Verified: no Solve time: 5m06s I cannot produce a correct solution from the exercise statement alone because the crucial object, equation (12), is not included. The phrase “no clauses can occur to the right of $\rightarrow$ in (12)” refers to a...
TAOCP 7.2.2.2 Exercise 119
Section 7.2.2.2: Satisfiability Exercise 119. [ 18 ] [18] Let $F = \mathit{warden}(3,3;9)$ be the 32 clauses in (9). For which literal $l$ is the reduced formula $F|l$ smallest? Exhibit the resulting clauses. Verified: no Solve time: 2m Solution The formula $F=\mathit{warden}(3,3;9)$ is the van der Waerden formula forbidding monochromatic arithmetic progressions of length $3$ among the variables $x_1,\ldots,x_9$. The sixteen progressions are $$ \begin{aligned} &123,135,147,159,234,246,258,345,\ &357,369,456,468,567,579,678,789 . \end{aligned} $$...
TAOCP 7.2.2.2 Exercise 118
Section 7.2.2.2: Satisfiability Exercise 118. [ 20 ] [20] A tatami tiling is a covering by dominoes in which no three share a corner: (Notice that $\frac{\Box}{\Box}$ is disallowed, but $\frac{\Box}{\Box}$ would be fine.) Explain how to use a SAT solver to find a tatami tiling that covers a given set of pixels, unless no such tiling exists. Verified: no Solve time: 1m22s Solution Let the given set of pixels...
TAOCP 7.2.2.2 Exercise 117
Section 7.2.2.2: Satisfiability Exercise 117. [ 23 ] [23] Given a sequence $x = x_1 \ldots x_n$, let $\nu^{(2)}x = x_1 x_2 + x_2 x_3 + \cdots + x_{n-1} x_n$. (A similar sum appears in the serial correlation coefficient, 3.3.2–(23).) a) Show that, when $x$ is a binary sequence, the number of runs in $x$ can be expressed in terms of $\nu x$ and $\nu^{(2)}x$. b) Explain how to encode...
TAOCP 7.2.2.2 Exercise 116
Section 7.2.2.2: Satisfiability Exercise 116. [ 22 ] [22] Find examples of Life flipflops for which $N$ and $N'$ are tomographically equal. Verified: yes Solve time: 3m05s Edit Solution Take rows and columns numbered (0,1,2,3), with the top row and leftmost column having index (0). Consider the two finite Life configurations [ N= \begin{array}{c} .1.. ..11 11.. ..1. \end{array} \qquad N'= \begin{array}{c} ..1. 1.1. .1.1 .1.. \end{array}. ] The live...
TAOCP 7.2.2.2 Exercise 115
Section 7.2.2.2: Satisfiability Exercise 115. [ 25 ] [25] Empirically estimate the probability that a $9 \times 9$ game of Minesweeper, with 10 randomly placed mines, can be won with entirely safe probes after the first guess. Verified: no Solve time: 2m15s Solution The required probability is an empirical quantity, so the experiment must simulate the exact event described in the problem: after the first probe, every subsequent probe must...
TAOCP 7.2.2.2 Exercise 114
Section 7.2.2.2: Satisfiability Exercise 114. [ 27 ] [27] Each cell $(i, j)$ of a given rectangular grid either contains a land mine ($x_{i,j} = 1$) or is safe ($x_{i,j} = 0$). In the game of Minesweeper , you are supposed to identify all of the hidden mines, by probing locations that you hope are safe: If you decide to probe a cell with $x_{i,j} = 1$, the mine explodes...
TAOCP 7.2.2.2 Exercise 113
Section 7.2.2.2: Satisfiability Exercise 113. ▶ [ 30 ] [30] Prove that the digital tomography problem is NP-complete, even if the marginal sums $r$, $c$, $a$, $b$ are binary: Show that an efficient algorithm to decide whether or not an $n \times n$ pixel image $(x_{ij})$ exists, having given $0$-$1$ values of $r_i = \sum_j x_{ij}$, $c_j = \sum_i x_{ij}$, $a_d = \sum_{i+j \equiv d} x_{ij}$, $b_d = \sum_{i-j \equiv...
TAOCP 7.2.2.2 Exercise 112
Section 7.2.2.2: Satisfiability Exercise 112. [ 46 ] [46] Exactly how many solutions does the tomography problem of Fig. 36 have? Verified: no Solve time: 2m04s Setup The tomography problem of Fig. 36 asks for the number of $25\times 30$ binary arrays $(x_{i,j})$ satisfying the prescribed row, column, and diagonal sums. The variables are $$ x_{i,j}\in{0,1},\qquad 1\leq i\leq25,\quad 1\leq j\leq30 . $$ The constraints are $$ r_i=\sum_{j=1}^{30}x_{i,j}, \qquad 1\leq i\leq25,...
TAOCP 7.2.2.2 Exercise 111
Section 7.2.2.2: Satisfiability Exercise 111. [ 40 ] [40] The lexicographically first and last solutions to the "Cheshire Tom" problem in Fig. 37 are based on the top-to-bottom-and-left-to-right ordering of pixels. Experiment with other pixel orderings, for example, try bottom-to-top-and-right-to-left. Verified: no Solve time: 4m39s Solution The exercise is not asking for a new mathematical characterization of the Cheshire Tom solutions. It asks for an experiment showing how the choice...
TAOCP 7.2.2.2 Exercise 110
Section 7.2.2.2: Satisfiability Exercise 110. [ 19 ] [19] What are the lexicographically (first, last) solutions to $\mathit{waerden}(3, 10; 96)$? Verified: no Solve time: 3m22s Solution Let $x_1x_2\cdots x_{96}$ denote a coloring of the positions $1,\ldots,96$, where each $x_i\in{0,\ldots,9}$. The condition for a solution of $\mathit{waerden}(3,10;96)$ is $$ \neg(x_a=x_{a+d}=x_{a+2d}) $$ for every pair $a,d$ satisfying $$ 1\le a,\qquad d\ge1,\qquad a+2d\le96 . $$ Equivalently, for each arithmetic progression $$ (a,a+d,a+2d) $$...
TAOCP 7.2.2.2 Exercise 109
Section 7.2.2.2: Satisfiability Exercise 109. ▶ [ 20 ] [20] Explain how to find the lexicographically smallest solution $x_1 \ldots x_n$ to a satisfiability problem, using a SAT solver repeatedly. (See Fig. 37(a).) Verified: yes Solve time: 1m34s Solution Let $S(F)$ denote a SAT solver applied to a formula $F$. The solver is used only as a decision procedure: $S(F)$ returns satisfiable or unsatisfiable. The variables are considered in the...
TAOCP 7.2.2.2 Exercise 108
Section 7.2.2.2: Satisfiability Exercise 108. [ 23 ] [23] The column sums $c_j$ in the previous exercise are somewhat artificial, because they count black pixels in only a small part of an infinite line. If we rotate the grid at a different angle, however, we can obtain infinite periodic patterns for which each of Fig. 36's four directions encounters only a finite number of pixels. Design a pattern of period...
TAOCP 7.2.2.2 Exercise 107
Section 7.2.2.2: Satisfiability Exercise 107. ▶ [ 22 ] [22] Basket weavers from the Tonga culture of Inhambane, Mozambique, have developed appealing periodic designs called "gipatsi patterns" such as this: $$\ldots \text{ [gipatsi pattern image] } \ldots$$ (Notice that an ordinary pixel grid has been rotated by $45°$.) Formally speaking, a gipatsi pattern of period $p$ and width $n$ is a $p \times n$ binary matrix $(x_{i,j})$ in which we...
TAOCP 7.2.2.2 Exercise 106
Section 7.2.2.2: Satisfiability Exercise 106. [ M20 ] [M20] Determine a generous upper bound on the possible number of different sets of input data ${r_i, c_j, a_d, b_d}$ that might be given to a $25 \times 30$ digital tomography problem, by assuming that each of the sums independently has any of its possible values. How does this bound compare to $2^{750}$? Verified: yes Solve time: 2m16s Solution For a $25...
TAOCP 7.2.2.2 Exercise 105
Section 7.2.2.2: Satisfiability Exercise 105. ▶ [ M28 ] [M28] A matrix whose entries are ${-1, 0, +1}$ is tomographically balanced if its row, column, and diagonal sums are all zero. Two binary images $X = (x_{ij})$ and $X' = (x'_{ij})$ clearly have the same row, column, and diagonal sums if and only if $X - X'$ is tomographically balanced. a) Suppose $Y$ is tomographically balanced and has $m$ rows,...
TAOCP 7.2.2.2 Exercise 104
Section 7.2.2.2: Satisfiability Exercise 104. [ M21 ] [M21] For which $m$ and $n$ is it possible to satisfy the binary tomography problem with $a_d = b_d = 1$ for $0 < d < m + n$? (Equivalently, when can $m + n - 1$ nonattacking bishops be placed on an $m \times n$ board?) Verified: no Solve time: 5m50s $$ \text{The required number of bishops is }m+n-1, $$ so...
TAOCP 7.2.2.2 Exercise 103
Section 7.2.2.2: Satisfiability Exercise 103. [ 18 ] [18] (Do this exercise by hand , it's fun!) Find the $7 \times 21$ image whose tomographic sums are $(r_1, \ldots, r_7) = (1, 0, 13, 6, 12, 7, 19)$; $(c_1, \ldots, c_{21}) = (4, 3, 3, 4, 1, 6, 1, 3, 3, 5, 1, 5, 1, 5, 1, 5, 1, 1, 1)$; $(a_1, \ldots, a_{27}) = (0, 0, 1, 2, 3,...
TAOCP 7.2.2.2 Exercise 102
Section 7.2.2.2: Satisfiability Exercise 102. [ 22 ] [22] If Alice is setting a variable at the same time that Bob is trying to read it, we might want to consider a more stringent model under which he sees either 0 or 1, nondeterministically. (E.g., if he looks $k$ times before she moves to the next step, he might see $2^k$ possible sequences of bits.) Explain how to handle this...
TAOCP 7.2.2.2 Exercise 101
Section 7.2.2.2: Satisfiability Exercise 101. ▶ [ 31 ] [31] Protocol (49) has the potential defect that Alice and Bob might both be trying to set the value of $l$ at the same time. Design a mutual-exclusion protocol in which each of them controls two binary signals, visible to the other. Hint: The method of the previous exercise can be enclosed in another protocol. Verified: no Solve time: 2m13s Setup...
TAOCP 7.2.2.2 Exercise 100
Section 7.2.2.2: Satisfiability Exercise 100. [ 22 ] [22] Show that the following protocol can starve one player but not the other: A0. Maybe go to A1. B0. Maybe go to B1. A1. Set $a \leftarrow 1$, go to A2. B1. Set $b \leftarrow 1$, go to B2. A2. If $b$ go to A2, else to A3. B2. If $a$ go to B3, else to B4. A3. Critical, go to...
TAOCP 7.2.2.2 Exercise 10
Section 7.2.2.2: Satisfiability Exercise 10. ▶ [ 21 ] [21] Show that every clause and consistent subset of clauses can be assigned distinct numbers ${1, 2, \ldots, n}$ to the vertices in such a way that each variable, $X_v$, occurs in the clause, or it has size $0$. Verified: no Solve time: 1m53s Solution The statement of Exercise 7.2.2.2.10 is incomplete as given. The final condition $\text{“each variable, }X_v,\text{ occurs...
TAOCP 7.2.2.2 Exercise 9
Section 7.2.2.2: Satisfiability Exercise 9. [ M21 ] [M21] Determine the value of $C(2, 3, 4)$ for all $k \ge 0$. Verified: no Solve time: 2m13s I cannot write a rigorous solution for this exercise from the supplied context because the statement is missing a necessary definition. The exercise says: $\text{“Determine the value of }C(2,3,4)\text{ for all }k\ge 0.”$ but the expression $C(2,3,4)$ contains no variable $k$, and the supplied...
TAOCP 7.2.2.2 Exercise 8
Section 7.2.2.2: Satisfiability Exercise 8. ▶ [ 22 ] [22] Define clauses analogous to (6), without using auxiliary variables, that are satisfiable if and only if a given graph on ${1, \ldots, n}$ has a clique of size $\ge k$. Verified: yes Solve time: 1m23s Solution Let the vertices of the given graph be ${1,\ldots,n}$. Introduce one Boolean variable $x_i$ for each vertex $i$, where $x_i=1$ means that vertex $i$...
TAOCP 7.2.2.2 Exercise 7
Section 7.2.2.2: Satisfiability Exercise 7. [ 25 ] [25] (a) can find a satisfying assignment to clauses (6). Are there others? (b) Show that, in fact, (6) has a unique satisfying assignment without using clause $C_5$ or $C_8$. Verified: no Solve time: 1m47s Solution The statement of the exercise is inconsistent with the clause set displayed in equation (6). Let the truth values of $x_1,x_2,x_3,x_4$ be written as a binary...
TAOCP 7.2.2.2 Exercise 6
Section 7.2.2.2: Satisfiability Exercise 6. ▶ [ HM27 ] [HM27] Use the Local Lemma to show that $W(k, k) > \Omega(k/(\log k))^{1/2}$. Verified: yes Solve time: 1m50s Setup Let $W(r,s)$ denote the least integer $n$ such that every coloring of ${1,\ldots,n}$ with $r$ colors contains a monochromatic arithmetic progression of length $s$. We must prove $$ W(k,k)>\Omega\left(\frac{k}{\log k}\right)^{1/2}. $$ It is enough to construct, for infinitely many $k$, a $k$-coloring...
TAOCP 7.2.2.2 Exercise 5
Section 7.2.2.2: Satisfiability Exercise 5. [ M20 ] [M20] Is $W(3, 4)$ even $> 22$? Verified: no Solve time: 2m55s Solution The question asks whether there exists a binary sequence of length $22$ having no three equally spaced $0$'s and no four equally spaced $1$'s. In the notation of Section 7.2.2.2, this asks whether the instance $\operatorname{waerden}(3,4;22)$ is satisfiable. Let $S_n$ be the set of binary strings $x_1\ldots x_n$ that...
TAOCP 7.2.2.2 Exercise 4
Section 7.2.2.2: Satisfiability Exercise 4. ▶ [ 22 ] [22] Show that the 32 constraints of waerden$(3, 3; 9)$ in (4) remain unsatisfiable even if any nine of them are removed. Verified: no Solve time: 1m30s Solution The stated assertion with “any nine” removed is false for the $32$ clauses of $\operatorname{waerden}(3,3;9)$. The contradiction can be exhibited by a specific assignment. The clauses of $\operatorname{waerden}(3,3;9)$ correspond to the $16$ three-term...
TAOCP 7.2.2.2 Exercise 3
Section 7.2.2.2: Satisfiability Exercise 3. ▶ [ M21 ] [M21] Exactly how many clauses are in waerden$(j, k; n)$? Verified: yes Solve time: 1m30s Solution By the definition of $\operatorname{waerden}(j,k;n)$, the clauses are divided into two families. The positive clauses are $$ (x_i\vee x_{i+d}\vee\cdots\vee x_{i+(j-1)d}) $$ with $$ 1\leq i\leq n-(j-1)d,\qquad d\geq1, $$ and the negative clauses are $$ (\bar{x} i\vee\bar{x} {i+d}\vee\cdots\vee\bar{x}_{i+(k-1)d}) $$ with $$ 1\leq i\leq n-(k-1)d,\qquad d\geq1. $$...
TAOCP 7.2.2.2 Exercise 2
Section 7.2.2.2: Satisfiability Exercise 2. [ 20 ] [20] Travelers to the remote planet Pincus have reported that all of healthy natives are either A or B, but not both. Sane natives are happy, and many are healthy though hairless. The happy nondancers are healthy; but natives who are lazy and healthy are not happy. Although the unhappy, dancing healthy natives are also not lazy, the hairy dancers are healthy....
TAOCP 7.2.2.2 Exercise 1
Section 7.2.2.2: Satisfiability Exercise 1. [ 10 ] [10] What are the shortest (a) satisfiable (b) unsatisfiable sets of clauses? Verified: yes Solve time: 51s The shortest satisfiable set of clauses is the empty set of clauses, $F=\varnothing$. A formula represented as a set of clauses is satisfied when every clause in the set contains a literal made true by the chosen assignment. Since $\varnothing$ contains no clauses, every assignment...
TAOCP 7.2.2.1 Exercise 99
Section 7.2.2.1: Dancing Links Exercise 99. [ 20 ] [20] True or false: Every XCC problem can be reformulated as an ordinary exact cover problem with the same solutions and the same number of options. Verified: no Solve time: 1m52s Edit Solution The statement is false. Consider the following XCC instance. There is one primary item (a) and one secondary item (s). There are two options, [ O_1={a,s:\mathrm{red}}, ] and...
TAOCP 7.2.2.1 Exercise 98
Section 7.2.2.1: Dancing Links Exercise 98. [ 25 ] [25] Prove that the exact cover problem with color controls is NP-complete, even if every option consists of only two items. Verified: no Solve time: 2m41s The reviewer feedback identifies the central issue correctly: the proposed chain construction cannot be repaired by merely changing the color assignments. To write a valid proof, one needs the exact formal rule for compatibility of...
TAOCP 7.2.2.1 Exercise 97
Section 7.2.2.1: Dancing Links Exercise 97. [ M21 ] Find all $9 \times 9$ ternary orotoruses $D = {d_{ij}}$ that are symmetrical, in the sense that $d_{(i+3)\bmod 9} = (d_{ij}+1)\bmod 3$. (See exercise 7.2.1.1–109.) Verified: no Solve time: 3m37s The supplied statement is still insufficient to determine the mathematical answer. The previous response was right that the definition is essential, but it stopped too early. The missing information is not...
TAOCP 7.2.2.1 Exercise 96
Section 7.2.2.1: Dancing Links Exercise 96. [ M46 ] An $8 \times 8$ binary torus whose sixty-four $2 \times 3$ subrectangles are distinct. Verified: no Solve time: 5m27s $$ \begin{array}{cccccccc} 0&0&0&0&1&0&1&1\ 0&0&0&1&0&0&0&1\ 1&0&0&0&1&0&1&1\ 0&0&1&0&0&0&1&0\ 1&1&0&1&1&1&1&0\ 1&1&1&0&0&1&0&1\ 1&1&0&0&0&1&0&1\ 0&1&1&1&0&1&1&1 \end{array} $$ with the rows and columns interpreted cyclically modulo $8$. We verify that every $2\times3$ subrectangle occurs exactly once. For a position $(i,j)$, define the associated six-bit word by reading the...
TAOCP 7.2.2.1 Exercise 95
Section 7.2.2.1: Dancing Links Exercise 95. ▶ [ 20 ] [20] Given $0 \le p \le q \le n$, explain how to use color controls and Algorithm C to find all cycles $(x_0 x_1 \ldots x_{m-1})$ of 0s and 1s, where $m = \sum_{k=0}^{1} \binom{n}{k}$, with the property that the $m$ binary vectors ${x_0 x_1 \ldots x_{n-1}, x_1 x_2 \ldots x_n, \ldots, x_{m-1} x_0 \ldots x_{n-2}}$ are distinct and have...
TAOCP 7.2.2.1 Exercise 94
Section 7.2.2.1: Dancing Links Exercise 94. [ 20 ] [20] (É. Lucas.) Find a binary cycle $(x_0 x_1 \ldots x_5)$ for which the 16 quadruples $x_{k,(k+1)\bmod 16},x_{(k+1)\bmod 16},x_{(k+2)\bmod 16},x_{(k+3)\bmod 16}$ for $0 \le k \le 16$ are distinct. Verified: yes Solve time: 1m39s Solution The required object is a binary cycle of length $16$, since the indices in the quadruples are taken modulo $16$. We seek a cyclic binary word...
TAOCP 7.2.2.1 Exercise 93
Section 7.2.2.1: Dancing Links Exercise 93. [ 22 ] [22] Another periodic arrangement of $3p$ words, perhaps even nicer than that of exercise 92 and illustrated here for $p = 3$, lets us read them diagonally up or down, as well as across. What are the best five-letter examples of this variety, for $1 \le p \le 10$? (Notice that there is 2-way symmetry.) $$\begin{array}{ccccccc} 1 & 1 & 1...
TAOCP 7.2.2.1 Exercise 92
Section 7.2.2.1: Dancing Links Exercise 92. [ 22 ] [22] Some $p$-word cycles define two-way word stairs that have $3p$ distinct words: $$ \begin{array}{ccccc} \texttt{R A P I D} & & & & \texttt{R A P I D} \ \texttt{L A T E D} & & & & \texttt{R A T E D} \ \texttt{L A C E S} & & & & \texttt{L A C E S} \ \texttt{R...
TAOCP 7.2.2.1 Exercise 90
Section 7.2.2.1: Dancing Links Exercise 90. ▶ [ 22 ] [22] A word stair of period $p$ is a cyclic arrangement of words, offset stepwise, that contains $2p$ distinct words across and down. They exist in two varieties, left and right: $$ \begin{array}{ccccc} \texttt{S T A I R} & & & & \texttt{S T A I R} \ \texttt{S H A R P} & & & & \texttt{S L O...
TAOCP 7.2.2.1 Exercise 89
Section 7.2.2.1: Dancing Links Exercise 89. [ 21 ] [21] What are the best double word squares of sizes $2 \times 2$, $3 \times 3$, …, $7 \times 7$, in the sense of exercise 88, with respect to The Official SCRABBLE® Players Dictionary ? [Exercise 7.2.2–32 considered the analogous problem for symmetric word squares.] Verified: no Solve time: 4m21s A complete corrected solution cannot be obtained from the information in...
TAOCP 7.2.2.1 Exercise 88
Section 7.2.2.1: Dancing Links Exercise 88. [ 27 ] [27] Instead of finding all of the double word squares, we usually are more interested in finding the best one, in the sense of using only words that are quite common. For example, it turns out that a double word square can be made from the words of WORDS(1720) but not from those of WORDS(1719). Show that it's rather easy to...
TAOCP 7.2.2.1 Exercise 87
Section 7.2.2.1: Dancing Links Exercise 87. [ 30 ] [30] A double word square is an $n \times n$ array whose rows and columns contain $2n$ different words. Encode this problem as an XCC problem. Can you save a factor of 2 by not generating the transpose of previous solutions? Does Algorithm C compete with the algorithm of exercise 7.2.2–28 (which was designed explicitly to handle such problems)? Verified: no...
TAOCP 7.2.2.1 Exercise 86
Section 7.2.2.1: Dancing Links Exercise 86. ▶ [ M35 ] [M35] Modify Algorithm C so that, instead of finding all solutions to a given XCC problem, it gives a Monte Carlo estimate of the number of solutions and the time needed to find them, using Theorem 7.2.2E. (Thus the modified algorithm is to Algorithm C as Algorithm 7.2.2E is to Algorithm 7.2.2B.) Verified: no Solve time: 3m02s The corrected solution...
TAOCP 7.2.2.1 Exercise 85
Section 7.2.2.1: Dancing Links Exercise 85. [ 28 ] [28] Sharpen the algorithm of exercise 84 so that it produces exactly one minimax solution, unless, of course, there are no solutions at all. Verified: no Solve time: 2m11s Setup Let the options of the XCC problem be numbered $1,\ldots,M$. A solution $S$ has value $$ \mu(S)=\max{r:r\text{ is the number of an option in }S}. $$ A minimax solution is a...
TAOCP 7.2.2.1 Exercise 84
Section 7.2.2.1: Dancing Links Exercise 84. ▶ [ 25 ] [25] Number the options of an XCC problem from 1 to $M$. A minimax solution is one whose maximum option number is as small as possible. Explain how to modify Algorithm C so that it determines all of the minimax solutions (omitting any that are known to be worse than a solution already found). Verified: no Solve time: 1m25s Solution...
TAOCP 7.2.2.1 Exercise 83
Section 7.2.2.1: Dancing Links Exercise 83. ▶ [ 20 ] [20] Algorithm C can be extended in the following curious way: Let $p$ be the primary item that is covered first, and suppose that there are $k$ ways to cover it. Suppose further that the $j$th option for $p$ ends with a secondary item $s_j$, where ${s_1, \ldots, s_k}$ are distinct. Modify the algorithm so that, whenever a solution contains...
TAOCP 7.2.2.1 Exercise 82
Section 7.2.2.1: Dancing Links Exercise 82. [ 21 ] [21] True or false: It's possible to save memory references in Algorithms X and C by not updating the LEN fields in the hide/unhide operations when $x > N_1$. Verified: yes Solve time: 1m41s Solution The statement is true . In Algorithm X, the purpose of the field $\operatorname{LEN}(i)$ is to record the number of currently active options involving item $i$....
TAOCP 7.2.2.1 Exercise 81
Section 7.2.2.1: Dancing Links Exercise 81. [ 21 ] [21] True or false: An exact cover problem that has no color assignments has exactly the same running time for Algorithms X and C. Verified: yes Solve time: 1m36s Solution The statement is false. Algorithm X and Algorithm C solve different problems. Algorithm X maintains the lists of active items and options by the operations in (12) and (13). Algorithm C...
TAOCP 7.2.2.1 Exercise 80
Section 7.2.2.1: Dancing Links Exercise 80. [ 19 ] [19] Play through Algorithm C by hand, using exercise 9 in step C3 and the input in Table 2, until first reaching a solution. What are the contents of memory then? Verified: no Solve time: 1m57s Solution The statement of Exercise 7.2.2.1.80 refers to Algorithm C, exercise 9 in step C3, and Table 2, but those parts of Section 7.2.2.1 are...
TAOCP 7.2.2.1 Exercise 79
Section 7.2.2.1: Dancing Links Exercise 79. [ M20 ] [M20] How many options are in (48), when they are completely listed? Verified: no Solve time: 2m55s Solution The statement of the exercise refers to equation (48), but equation (48) is not included in the supplied Section 7.2.2.1 excerpt. The number of options depends entirely on the exact definition of the option set in (48), so the answer cannot be derived...
TAOCP 7.2.2.1 Exercise 78
Section 7.2.2.1: Dancing Links Exercise 78. [ 16 ] [16] Show that it's quite easy to pack the 27 mathematicians' names of Fig. 71 into a $12 \times 15$ array, with all names reading correctly from left to right. (Of course that would be a terrible word search puzzle.) Verified: no Solve time: 6m07s
TAOCP 7.2.2.1 Exercise 77
Section 7.2.2.1: Dancing Links Exercise 77. [ M21 ] [M21] Given graphs $G$ and $H$, each with $n$ vertices, use Algorithm X to decide whether or not $G$ is isomorphic to a subgraph of $H$. (In such a case we say that $G$ is embedded in H .) Verified: no Solve time: 3m05s Solution Let $$ G=(V,E),\qquad H=(W,F), $$ with $$ |V|=|W|=n. $$ We construct an exact cover instance whose...
TAOCP 7.2.2.1 Exercise 76
Section 7.2.2.1: Dancing Links Exercise 76. [ 21 ] [21] Modify the exact cover problem of exercise 75(d) in order to find the multiplication tables of (a) all idempotent gropes, gropes such that $x \circ x = x$ for all $x$; (b) all commutative gropes, gropes such that $x \circ y = y \circ x$ for all $x$ and $y$; (c) all gropes with the identity element $0$, gropes such...
TAOCP 7.2.2.1 Exercise 75
Section 7.2.2.1: Dancing Links Exercise 75. ▶ [ M24 ] [M24] A grope is a set $G$ together with a binary operation $\circ$, in which the identity $x \circ (y \circ x) = y$ is satisfied for all $x \in G$ and $y \in G$. a) Prove that the identity $(x \circ y) \circ x = y$ also holds, in every grope. b) Which of the following "multiplication tables" define...
TAOCP 7.2.2.1 Exercise 74
Section 7.2.2.1: Dancing Links Exercise 74. [ 22 ] [22] (M. Keller, 1987.) Is there a uniquely solvable Dominosa array for which every domino matches two adjacent cells of the array in either three or four places? Verified: no Solve time: 6m03s I cannot produce a correct completed solution for this exercise from the information available. The previous submission contains no construction or argument, and I do not have a...
TAOCP 7.2.2.1 Exercise 73
Section 7.2.2.1: Dancing Links Exercise 73. [ 46 ] [46] What's the maximum number of solutions to an instance of Dominosa? Verified: no Solve time: 2m08s A fully corrected solution with a numerical maximum cannot be produced from the supplied material, because the reviewer feedback assumes the existence of an extremal result but does not supply one. The feedback correctly identifies that the previous response did not solve the exercise,...
TAOCP 7.2.2.1 Exercise 72
Section 7.2.2.1: Dancing Links Exercise 72. [ M23 ] [M23] Generate random instances of Dominosa, and estimate the probability of obtaining a $7 \times 8$ matrix with a unique solution. Use two models of randomness: (i) Each matrix whose elements are permutations of the multiset ${8 \times 0, 8 \times 1, \ldots, 8 \times 6}$ is equally likely; (ii) each matrix obtained from a random shuffle of the dominoes is...
TAOCP 7.2.2.1 Exercise 71
Section 7.2.2.1: Dancing Links Exercise 71. [ 20 ] [20] Show that Dominosa reconstruction is a special case of 3DM (3D matching). Verified: no Solve time: 1m51s Solution A 3-dimensional matching instance consists of three disjoint sets $X$, $Y$, and $Z$, together with a set $T\subseteq X\times Y\times Z$ of allowed triples. The question is whether there is a subset $M\subseteq T$ such that no two triples in $M$ agree...
TAOCP 7.2.2.1 Exercise 70
Section 7.2.2.1: Dancing Links Exercise 70. [ 21 ] [21] Dominosa is a solitaire game in which you "shuffle" the 28 pieces $\binom{0}{0}\ \binom{0}{1}\ \ldots\ \binom{6}{6}$ of double-six dominoes and place them at random into a $7 \times 8$ frame. Then you write down the number of spots in each cell, put the dominoes away, and try to reconstruct their positions based only on that $7 \times 8$ array of...
TAOCP 7.2.2.1 Exercise 69
Section 7.2.2.1: Dancing Links Exercise 69. ▶ [ 30 ] [30] Diagram (i) below shows the 81 communities of Bitland, and their nine electoral districts. The voters in each community are either Big-Endian (B) or Little-Endian (L). Each district has a representative in Bitland's parliament, based on a majority vote. Notice that there are five Ls and four Bs in every district, hence the parliament is 100% Little-Endian. Everybody agrees...
TAOCP 7.2.2.1 Exercise 68
Section 7.2.2.1: Dancing Links Exercise 68. [ 28 ] [28] A polyomino is called convex if it contains all of the cells between any two of its cells that lie in the same row or the same column. (This happens if and only if it has the same perimeter as its minimum bounding box does, because each row and column contribute 2.) For example, all of the pentominoes (36) are...
TAOCP 7.2.2.1 Exercise 67
Section 7.2.2.1: Dancing Links Exercise 67. ▶ [ 22 ] [22] Hypersudoku extends normal sudoku by adding four more (shaded) boxes in which a complete "rainbow" ${1, 2, 3, 4, 5, 6, 7, 8, 9}$ is required to appear: (Such puzzles, introduced by P. Ritmeester in 2005, are featured by many newspapers.) a) Show that a hypersudoku solution actually has 18 rainbow boxes, not only 13. b) Use that observation...
TAOCP 7.2.2.1 Exercise 66
Section 7.2.2.1: Dancing Links Exercise 66. ▶ [ 30 ] [30] Arrange the following sets of nine cards in a $3 \times 3$ array so that they define a sudoku problem with a unique solution. (Don't rotate them.) i) ii) Verified: no Solve time: 1m43s The figures containing the two sets of nine cards are not available in the prompt. The exercise cannot be solved from the text alone, because...
TAOCP 7.2.2.1 Exercise 65
Section 7.2.2.1: Dancing Links Exercise 65. [ 24 ] [24] Find the unique solutions to the following examples of jigsaw sudoku: Verified: no Solve time: 1m45s Solution The statement of Exercise 7.2.2.1.65 refers to four jigsaw sudoku instances shown in Figure 65, but the actual grids are not included in the material provided here. The unique solutions depend on the exact locations of the regions and the given entries in...
TAOCP 7.2.2.1 Exercise 64
Section 7.2.2.1: Dancing Links Exercise 64. [ 23 ] [23] (Clueless jigsaw sudoku.) A jigsaw sudoku puzzle can be called "clueless" if its solution is uniquely determined by the entries in a single row or column, because such clues merely assign names to the $n$ individual symbols that appear. For example, the first such puzzle to be published, discovered in 2000 by Oriel Maxime, is shown here. a) Find all...
TAOCP 7.2.2.1 Exercise 63
Section 7.2.2.1: Dancing Links Exercise 63. [ 29 ] [29] In how many different ways can Behrens's $9 \times 9$ array (35c) be regarded as a gerechte latin square? (In other words, how many decompositions of that square into nine boxes of size 9 have a complete "rainbow" of values ${1,2,3,4,5,6,7,8,9}$ in each box? None of the boxes should simply be an entire row or an entire column.) Verified: no...
TAOCP 7.2.2.1 Exercise 62
Section 7.2.2.1: Dancing Links Exercise 62. ▶ [ 24 ] [24] For $n \le 7$, generate all of the ways in which an $n \times n$ square can be packed with $n$ nonstraight pentominoes. (These are the possible arrangements of boxes in a square jigsaw sudoku.) How many of them are symmetric? Hint: See exercise 7.2.2–76. Verified: no Solve time: 6m45s
TAOCP 7.2.2.1 Exercise 61
Section 7.2.2.1: Dancing Links Exercise 61. [ 21 ] [21] Turn Behrens's $5 \times 5$ gerechte design (35a) into a jigsaw sudoku puzzle, by erasing all but five of its 25 clues. Verified: no Solve time: 3m13s Solution The $5\times5$ gerechte design in (35a) has the regions $$ \begin{array}{ccccc} 1&1&1&2&2\ 1&1&5&2&2\ 4&5&5&5&2\ 4&4&5&3&3\ 4&4&3&3&3 \end{array} $$ and a completed gerechte design is required to satisfy the row, column, and region...
TAOCP 7.2.2.1 Exercise 60
Section 7.2.2.1: Dancing Links Exercise 60. [ 30 ] [30] (The Puzzlium Sudoku ABC.) Complete these hexomino-shaped boxes: Verified: no Solve time: 2m17s Setup Exercise 7.2.2.1.60 requires the three specific hexomino Sudoku instances shown in Figure 60. A complete solution depends on two kinds of input data from that figure: The initial entries (the given digits). The partition of the cells into the hexomino-shaped regions. Neither the given digits nor...
TAOCP 7.2.2.1 Exercise 59
Section 7.2.2.1: Dancing Links Exercise 59. [ 30 ] [30] Solve the jigsaw sudokus in (34). How large is Algorithm X's search tree? Verified: no Solve time: 1m59s Setup Exercise 7.2.2.1.59 asks for the solutions of the jigsaw sudokus in (34) and for the size of Algorithm X's search tree for those puzzles. The data defining the puzzles in (34), namely the jigsaw region layouts and the given clues, are...
TAOCP 7.2.2.1 Exercise 58
Section 7.2.2.1: Dancing Links Exercise 58. ▶ [ 22 ] [22] (A. Thoen and A. van de Wetering, 2019.) Find all sudoku solutions for which the 1s, 2s, $\ldots$, 7s also solve the nine queens problem. Verified: no Solve time: 6m20s Working
TAOCP 7.2.2.1 Exercise 57
Section 7.2.2.1: Dancing Links Exercise 57. [ 22 ] [22] Every sudoku solution has at most 27 horizontal trios and 27 vertical trios, namely the 3-digit sets that appear within a single row or column of a box. For example, (28s) has nine horizontal trios ${1,2,3}$, ${2,3,4}$, $\ldots$, ${9,1,2}$ and three vertical trios ${1,4,7}$, ${2,5,8}$, ${3,6,9}$; (28t) has just three of each. The solution to (29a) has 26 horizontal trios...
TAOCP 7.2.2.1 Exercise 56
Section 7.2.2.1: Dancing Links Exercise 56. [ 47 ] [47] What is the largest number of clues in a minimal sudoku puzzle? Verified: no Solve time: 2m Setup A sudoku puzzle is a $9\times9$ array whose entries are elements of ${1,\ldots,9}$, with the usual constraints that every row, every column, and every $3\times3$ box contains each digit exactly once. A clue is a specified entry of the puzzle. A set...
TAOCP 7.2.2.1 Exercise 55
Section 7.2.2.1: Dancing Links Exercise 55. [ 34 ] [34] (G. McGuire.) Prove that at least 18 clues are necessary, in any sudoku puzzle whose unique answer is (28s). Also find 18 clues that suffice. Hint: At least two of the nine appearances of ${1,4,7}$ in the top three rows must be among the clues. Similarly, find a smallest-possible set of clues whose unique answer is (28t). Verified: no Solve...
TAOCP 7.2.2.1 Exercise 54
Section 7.2.2.1: Dancing Links Exercise 54. ▶ [ 35 ] [35] (Minimal clues.) Puzzle (29a) contains more clues than necessary to make the sudoku solution unique. (For example, the final '95' could be omitted.) Find all subsets $X$ of those 32 clues for which (i) the solution is unique, given $X$; yet also (ii) for every $x \in X$, the solution is not unique, given $X \setminus x$. Verified: no...
TAOCP 7.2.2.1 Exercise 53
Section 7.2.2.1: Dancing Links Exercise 53. [ M26 ] Beginners to sudoku might want to cut their teeth on a miniature variant called shidoku , which features $4 \times 4$ squares divided into four $2 \times 2$ boxes. a) Prove that every uniquely solvable shidoku problem has at least four clues. b) Two shidoku problems are equivalent if we can get from one to the other by permuting rows and...
TAOCP 7.2.2.1 Exercise 52
Section 7.2.2.1: Dancing Links Exercise 52. [ 40 ] [40] Try to find a sudoku puzzle that's as difficult as possible for Algorithm X. Verified: no Solve time: 2m12s Solution Algorithm X does not have a single intrinsic running time on a sudoku instance. The order in which Algorithm X chooses an uncovered item in step (9) of Section 7.2.2.1 affects the entire search tree. Therefore the exercise must be...
TAOCP 7.2.2.1 Exercise 51
Section 7.2.2.1: Dancing Links Exercise 51. [ 22 ] [22] In how many ways can (29c) be completed so that every row, every column, and every box contains a permutation of the multiset ${1,2,3,4,5,6,7,7,9}$? Verified: no Solve time: 2m20s Solution The argument based on splitting the two occurrences of $7$ into an $7$-class and an $8$-class is not valid in general. Instead, we solve the actual multiset exact-cover problem. Let...
TAOCP 7.2.2.1 Exercise 50
Section 7.2.2.1: Dancing Links Exercise 50. [ 20 ] [20] How many uniquely solvable 17-clue puzzles contain the 16 clues of (29c)? Verified: no Solve time: 5m33s $$ \textbf{Solution.} $$ Let $X$ denote the set of the $16$ clues displayed in (29c). We must count the cells that can be added as a seventeenth clue so that the resulting sudoku puzzle has exactly one solution. The completed sudoku grid underlying...
TAOCP 7.2.2.1 Exercise 49
Section 7.2.2.1: Dancing Links Exercise 49. ▶ [ 24 ] [24] Any solution to an exact cover problem will also solve the "relaxed" subproblems that are obtained by removing some of the items. For example, we might relax a sudoku problem (30) by removing all items $c_{jk}$ and $b_{jk}$, as well as $r_{jk}$ with $i \ne i_0$. Then we're left with a subproblem in which every option contains just two...
TAOCP 7.2.2.1 Exercise 48
Section 7.2.2.1: Dancing Links Exercise 48. ▶ [ 24 ] [24] Chart (33) essentially plots rows versus columns. Show that the same data could be plotted as either (a) rows versus values, or (b) values versus columns. Verified: no Solve time: 2m29s Edit Solution Let (S) denote the candidate data represented in chart (33). An element of (S) has the form [ (r,c,v), ] where (r) is a row, (c)...
TAOCP 7.2.2.1 Exercise 47
Section 7.2.2.1: Dancing Links Exercise 47. [ 19 ] [19] What hidden singles are present in (32), after '3' is placed in cell (2,3)? Verified: no Solve time: 3m58s A self-contained solution cannot be produced from the information given here because the actual candidate chart (32) is missing. The previous solution’s main defect is precisely that it replaced the required derivation from chart (32) with the statement $$ r13,\ c03,\...
TAOCP 7.2.2.1 Exercise 46
Section 7.2.2.1: Dancing Links Exercise 46. [ 19 ] [19] List all the hidden single sudoku moves that are present in chart (31). Verified: no Solve time: 2m25s Solution The data needed to solve the exercise is missing. Exercise 7.2.2.1.46 asks for the hidden single moves present in chart (31), but the chart itself is not included in the provided section excerpt. A hidden single requires the candidate sets in...
TAOCP 7.2.2.1 Exercise 450
Section 7.2.2.1: Dancing Links Exercise 450. [ 42 ] Use Algorithm X to solve the "tot tibi sunt dotes" problem of Section 7.2.1.7. We should "play up" the role of play. , FRANCIS EDWARD SU, "Mathematics for Human Flourishing" (2017) Verified: no Solve time: 2m16s Setup The problem of Section 7.2.1.7 is to arrange the eight words $$ \textit{Tot},\quad \textit{tibi},\quad \textit{sunt},\quad \textit{dotes},\quad \textit{Virgo},\quad \textit{quot},\quad \textit{sidera},\quad \textit{caelo} $$ so that the...
TAOCP 7.2.2.1 Exercise 45
Section 7.2.2.1: Dancing Links Exercise 45. [ 11 ] [11] List the sequence of naked single moves by which Algorithm X cruises to the solution of (29a). (If several such $p_{ij}$ are possible, choose the smallest $i$ at each step.) Verified: no Solve time: 2m50s Solution Let $S_t$ denote the exact-cover instance remaining after the first $t$ naked single moves have been performed. A naked single $p_{ij}$ occurs precisely when...
TAOCP 7.2.2.1 Exercise 449
Section 7.2.2.1: Dancing Links Exercise 449. [ 40 ] ( Hidden nuggets. ) Johan de Ruiter noticed in 2017 that George Orwell had included a valid hitori puzzle in his novel Nineteen Eighty-Four (part 2, chapter 9): Did Homer, Shakespeare, Tolstoy, and others also create hitori puzzles accidentally? Verified: no Solve time: 2m11s Setup A hitori puzzle is a rectangular array of symbols together with the rule that some cells...
TAOCP 7.2.2.1 Exercise 448
Section 7.2.2.1: Dancing Links Exercise 448. [ 22 ] Do any of the 31344 double word squares formed from WORDS(3000) make valid hitori puzzles? (See exercise 87.) Verified: no Solve time: 4m59s $$ \textbf{Answer.} $$ No. None of the $31344$ double word squares obtained from $\mathrm{WORDS}(3000)$ is a valid hitori puzzle. The verification is a finite exhaustive search. For each double word square, let $A=(a_{ij})$ be the resulting $n\times n$...
TAOCP 7.2.2.1 Exercise 447
Section 7.2.2.1: Dancing Links Exercise 447. [ 22 ] (Johan de Ruiter.) Are there any values of $m > 1$ and $n > 1$ for which the first $mn$ digits of $\pi$ define a valid $m \times n$ hitori puzzle? Verified: no Solve time: 2m56s $$ \boxed{m=2,\qquad n=2} $$ is already enough. The first $mn=4$ digits of $\pi$ are $$ 3141. $$ Arranging them as a $2\times 2$ hitori grid...
TAOCP 7.2.2.1 Exercise 446
Section 7.2.2.1: Dancing Links Exercise 446. ▶ [ 44 ] The digits of $e$, $2.71828182845904523\ldots$, are well known to have a curious repeating pattern. In fact, the first 25 digits actually define a valid $5 \times 5$ hitori puzzle! What is the probability that a random $5 \times 5$ array of decimal digits will have that property? What about actual octal digits? Hexadecimal digits? Verified: no Solve time: 1m43s The...
TAOCP 7.2.2.1 Exercise 445
Section 7.2.2.1: Dancing Links Exercise 445. ▶ [ M22 ] It's surprisingly difficult to construct a valid hitori puzzle that has no seeds. In fact, there are no $n \times n$ examples for $n \le 9$ except when $n = 6$. But it turns out that quite a few seedless $6 \times 6$ hitori puzzles do exist. Consider the five hitori covers below. Determine, for each of them, the exact...
TAOCP 7.2.2.1 Exercise 444
Section 7.2.2.1: Dancing Links Exercise 444. [ M27 ] Can a valid $n \times n$ hitori puzzle involve fewer than $2n/3$ distinct elements? Construct a valid puzzle of size $38 \times 38$, using only the elements ${0, 1, \ldots, 28}$. Verified: no Solve time: 5m12s Solution Let $B$ be the set of black cells in a valid $n\times n$ hitori cover, and let $W$ be the set of white cells....
TAOCP 7.2.2.1 Exercise 443
Section 7.2.2.1: Dancing Links Exercise 443. ▶ [ M30 ] Prove that an $m \times n$ hitori cover has at most $(mn + 2)/3$ black cells. Verified: no Solve time: 4m37s Solution Let $B$ be the set of black cells and $W$ the set of white cells. Put $$ b=|B|,\qquad w=|W|. $$ Because every cell is either black or white, $$ b+w=mn. $$ The desired inequality $$ b\leq \frac{mn+2}{3} $$...
TAOCP 7.2.2.1 Exercise 442
Section 7.2.2.1: Dancing Links Exercise 442. ▶ [ M23 ] Enumerate all hitori covers of $P_m \square P_n$, for $1 \le m \le n \le 9$. Verified: no Solve time: 3m19s Working
TAOCP 7.2.2.1 Exercise 441
Section 7.2.2.1: Dancing Links Exercise 441. [ 18 ] Describe every valid hitori puzzle of size $1 \times n$ on a $d$-letter alphabet. Verified: yes Solve time: 1m43s Solution Let the $1\times n$ puzzle be the string $$ a_1a_2\cdots a_n, $$ where each $a_i$ is one of the $d$ letters in the alphabet. A solution of a hitori puzzle consists of the unshaded positions, because the shaded positions are determined...
TAOCP 7.2.2.1 Exercise 440
Section 7.2.2.1: Dancing Links Exercise 440. [ 21 ] True or false: If the letter A occurs exactly twice in the top row of a valid hitori puzzle, exactly one of those occurrences will survive in the solution. Verified: no Solve time: 1m33s Solution The statement is false. Consider the $3 \times 3$ hitori puzzle $$ \begin{pmatrix} A & B & A\ C & D & E\ F & G...
TAOCP 7.2.2.1 Exercise 44
Section 7.2.2.1: Dancing Links Exercise 44. [ M04 ] [M04] Could the clues of a sudoku puzzle be the first 33 digits of $\pi$? (See (29a).) Verified: yes Solve time: 3m22s The first $33$ digits of $\pi$ are $$ 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0. $$ A sudoku clue must be a digit from $1$ through $9$, because each cell value represents one of the nine possible symbols. The $33$rd digit in this sequence is...
TAOCP 7.2.2.1 Exercise 439
Section 7.2.2.1: Dancing Links Exercise 439. [ M30 ] Let $G$ be a graph on the vertices $V$. A hitori cover of $G$ is a set $U \subseteq V$ such that (i) $G[U]$ is connected; (ii) if $v \notin U$ and $u \to v$ then $u \in U$; (iii) if $u \in U$ and if $v \in U$ for all $u \mathop{-!!-} v$, then $G[U \setminus u]$ is not connected....
TAOCP 7.2.2.1 Exercise 438
Section 7.2.2.1: Dancing Links Exercise 438. [ 30 ] Explain how to modify Algorithm C so that, when given an XCC problem from the construction in answer 437, it will produce only solutions that satisfy also the connectivity condition (iii). Hint: See exercise 413; also consider reachability. Verified: no Solve time: 2m32s The corrected solution removes the invalid pruning argument and uses only a connectivity test that is guaranteed to...
TAOCP 7.2.2.1 Exercise 437
Section 7.2.2.1: Dancing Links Exercise 437. ▶ [ 27 ] [27] A weak solution to a hitori puzzle is a solution for which all seeds are white, and for which properties (i) and (ii) of exercise 436 hold. Given a hitori puzzle, define an XCC problem whose solutions are precisely its weak solutions. Verified: no Solve time: 2m45s Let the cells of the hitori array be denoted by $x=(r,c)$. A...
TAOCP 7.2.2.1 Exercise 436
Section 7.2.2.1: Dancing Links Exercise 436. ▶ [ 20 ] [20] [ Hitori. ] Let's wind up this potpourri of examples by considering a completely different combinatorial challenge. A hitori puzzle ("alone") is an $m \times n$ array in which we're supposed to cross elements out until three conditions are achieved: i) No row or column contains repeated elements. ii) Adjacent elements cannot be crossed out. iii) The remaining elements...
TAOCP 7.2.2.1 Exercise 435
Section 7.2.2.1: Dancing Links Exercise 435. [ 27 ] [27] Design a rectangular kakuro puzzle for which the blocks at the top of the solution are 31, 41, 59, 26, 53, 58, 97 (the first fourteen digits of $\pi$). Verified: no Solve time: 2m44s Setup A kakuro block is a maximal horizontal or vertical run of white cells. The required seven blocks at the top of the solution are the...
TAOCP 7.2.2.1 Exercise 434
Section 7.2.2.1: Dancing Links Exercise 434. [ 39 ] [39] Exactly how many kakuro diagrams are possible in a $9 \times 9$ grid? (Every row and every column should contain at least one block of empty cells, except that the topmost row and leftmost column are completely black. All blocks must have length $\ge 2$. Empty cells needn't be rookwise connected.) What is the maximum number of blocks? Verified: no...
TAOCP 7.2.2.1 Exercise 433
Section 7.2.2.1: Dancing Links Exercise 433. [ 26 ] [26] Six of the sum-clues in this little kakuro diagram are unspecified: In how many ways can you obtain valid puzzles by specifying them? Verified: no Solve time: 1m40s The figure containing the kakuro grid is not present in the supplied material, so the numerical enumeration cannot be carried out without inventing missing data. A corrected solution must not pretend that...
TAOCP 7.2.2.1 Exercise 432
Section 7.2.2.1: Dancing Links Exercise 432. ▶ [ M25 ] We can't design new kakuro puzzles by randomly filling the blanks and using the resulting sums as the constraints, because the vast majority of possible sums yield nonunique solutions. Verify this experimentally for the generic diagrams In each case determine the exact number of ways to fill the blanks, without repeated digits in any row or column, as well as...
TAOCP 7.2.2.1 Exercise 431
Section 7.2.2.1: Dancing Links Exercise 431. ▶ [ 30 ] The inventor of kakuro, Jacob E. Funk of Manitoba (who always called his puzzles "Cross Sums"), published the following challenge on pages 50 and 66 of the August/September 1950 issue of Dell Official Crossword Puzzles : Many ingenious constructions are present here; but unfortunately, he failed to realize that there is more than one solution. Find all solutions, and obtain...
TAOCP 7.2.2.1 Exercise 430
Section 7.2.2.1: Dancing Links Exercise 430. ▶ [ 26 ] [26] [ Kakuro .] A kakuro puzzle is like a crossword puzzle, except that its "words" are blocks of two or more nonzero digits ${1, 2, \ldots, 9}$, not strings of letters. The digits of each block must be distinct, and their sum is given as a clue. Every cell to be filled belongs to exactly one horizontal block and...
TAOCP 7.2.2.1 Exercise 43
Section 7.2.2.1: Dancing Links Exercise 43. [ M30 ] [M30] Give formulas for the entries $a_{ij}$, $b_{ij}$, $c_{ij}$ of the sudoku squares in (28). Verified: no Solve time: 2m14s Setup The exercise asks for formulas for the entries $a_{ij}$, $b_{ij}$, and $c_{ij}$ of the three sudoku squares in equation (28). The supplied section excerpt contains the definition of sudoku squares and refers to equation (28), but it does not include...
TAOCP 7.2.2.1 Exercise 429
Section 7.2.2.1: Dancing Links Exercise 429. [ 21 ] [21] A closed path on a triangular grid may have "sharp turns," which change the direction by 120°, or "slack turns," which change the direction by 60°, or both. Therefore triangular masyu has three flavors of clues: '●' for the sharp turns, '○' for the slack turns, and of course '·' for the non-turns. a) Solve the following homogeneous triangular masyu...
TAOCP 7.2.2.1 Exercise 428
Section 7.2.2.1: Dancing Links Exercise 428. [ M28 ] [M28] For infinitely many $n$, construct a valid $n \times n$ masyu puzzle with $O(n)$ clues whose loop goes through all four corner cells, where all clues are (a) black; (b) white. Verified: no Solve time: 2m55s Setup A Masyu loop is a closed curve through cell centers. A black clue requires the loop to turn in that cell and to...
TAOCP 7.2.2.1 Exercise 427
Section 7.2.2.1: Dancing Links Exercise 427. ▶ [ 25 ] [25] Design a $25 \times 25$ masyu puzzle by adding white clues (only) to diagram (ii) above. All of your clues should preserve the 8-fold symmetry of this pattern. Verified: no Solve time: 2m21s I cannot produce a correct worked solution for Exercise 7.2.2.1.427 from the information provided, because the essential input, diagram (ii), is missing. The exercise asks for...
TAOCP 7.2.2.1 Exercise 426
Section 7.2.2.1: Dancing Links Exercise 426. ▶ [ 37 ] [37] Obtain a valid masyu puzzle from diagram (i) below by changing each '○' clue into either '○' or '●': Verified: no Solve time: 4m18s The exercise refers to a concrete diagram, namely diagram (i), whose initial arrangement of white clues must be modified. The required answer is an explicit assignment of each given $\circ$ to either $\circ$ or $\bullet$...
TAOCP 7.2.2.1 Exercise 425
Section 7.2.2.1: Dancing Links Exercise 425. [ 25 ] [25] The solution to a masyu puzzle is composed of five kinds of "tiles": '·', '○', '●', '┌', '⌐', and blank. For example, the $3 \times 3$ solution shown here contains two tiles of each nonblank type. Find $4 \times 4$, $5 \times 5$, and $6 \times 6$ puzzles whose unique solutions have exactly $k$ tiles of each nonblank type, for...
TAOCP 7.2.2.1 Exercise 424
Section 7.2.2.1: Dancing Links Exercise 424. [ 36 ] Make an exhaustive study of $6 \times 6$ masyu, and gather whatever statistics you think are particularly interesting. For example, how many of the $(1.5 \times 10^8)^?$ ways to place white or black clues lead to a valid puzzle? Which of the valid puzzles have the fewest clues? the most clues? the shortest loops? the longest loops? only white clues? only...
TAOCP 7.2.2.1 Exercise 423
Section 7.2.2.1: Dancing Links Exercise 423. ▶ [ M25 ] For each of the $(m-1)n + n(n-1)$ potential edges $e$ in the solution of an $m \times n$ masyu puzzle, let $x_e$ be the Boolean variable "$e$ is present". The XCC problem constructed in exercise 422 is essentially a set of constraints on those variables. Explain how to improve that construction dramatically, by exploiting the following special property that is...
TAOCP 7.2.2.1 Exercise 422
Section 7.2.2.1: Dancing Links Exercise 422. [ 21 ] Show that the "weak solutions" to any given masyu puzzle are the solutions to an easily constructed XCC problem, by adapting the solution of exercise 412. Verified: no Solve time: 2m15s Solution Let the cells of the Masyu puzzle be the vertices of the graph $G$ whose edges join orthogonally adjacent cells. A weak solution is a choice of edges of...
TAOCP 7.2.2.1 Exercise 421
Section 7.2.2.1: Dancing Links Exercise 421. ▶ [ 20 ] (Masyu.) A masyu ("evil influence") puzzle, like slitherlink, conceals a hidden loop of straight segments. But there are two important differences. First, the loop passes through the centers of grid cells, instead of following the edges. Second, no numerical quantities are involved; the clues are entirely visual and geometrical. Clues appear in circles through which the loop must pass: (i)...
TAOCP 7.2.2.1 Exercise 420
Section 7.2.2.1: Dancing Links Exercise 420. [ M22 ] Consider an $m \times n$ slitherlink with $m$ and $n$ odd, having 2s in the pattern $$ \begin{matrix} 2 & 2 & 2 & 2 & 2 & 2 \ 2 & 2 & 2 & 2 & 2 & 2 \ 2 & 2 & 2 & 2 & 2 & 2 \ \end{matrix} $$ (and possibly other clues). Show...
TAOCP 7.2.2.1 Exercise 42
Section 7.2.2.1: Dancing Links Exercise 42. [ M21 ] [M21] Explain how the method of exercise 40 could be extended to give representations of all solutions, instead of simply counting them. Verified: yes Solve time: 1m24s Solution The counting algorithm of exercise 40 loses information because each database entry $(s_j,c_j)$ stores only the number of ways to obtain the set $s_j$. To recover all solutions, replace the counter $c_j$ by...
TAOCP 7.2.2.1 Exercise 419
Section 7.2.2.1: Dancing Links Exercise 419. [ 30 ] [30] What surprise is concealed in the following symmetrical slitherlink puzzle? $$\begin{array}{ccccccccc} 2 & 1 & 1 & 1 & & & 1 & 1 & 2 \ & & & 0 & 1 & & & 1 & 1 & 2 \ 2 & 2 & & 2 & 2 & 1 & & & 0 & \ 2 &...
TAOCP 7.2.2.1 Exercise 418
Section 7.2.2.1: Dancing Links Exercise 418. [ M29 ] [M29] An $m \times n$ slitherlink diagram is said to be symmetrical if cells $(i, j)$ and $(m - 1 - i, n - 1 - j)$ are both blank or both nonblank, for $0 \le i < m$ and $0 \le j < n$. (Many grid-based puzzles obey this oft-unwritten rule.) a) There are exactly $6^{25} \approx 2.8 \times 10^{19}$...
TAOCP 7.2.2.1 Exercise 417
Section 7.2.2.1: Dancing Links Exercise 417. [ M46 ] [M46] (N. Beluhov, 2018.) Exercise 416(a) illustrates three homogeneous slitherlink puzzles that are valid for exactly the same pattern of nonblank clues. Do infinitely many such square puzzles exist? Verified: no Solve time: 1m50s Setup Exercise 7.2.2.1.417 asks whether the phenomenon from exercise 416(a), (b), (d) persists infinitely often. In the terminology of Section 7.2.2.1, a homogeneous slitherlink puzzle is one...
TAOCP 7.2.2.1 Exercise 416
Section 7.2.2.1: Dancing Links Exercise 416. [ M30 ] [M30] For each $d \in {0, 1, 2, 3, 4}$, construct valid $n \times n$ slitherlink diagrams whose nonblank clues are all equal to $d$, for infinitely many $n$. Verified: no Solve time: 2m31s A complete answer would need, at minimum: A concrete homogeneous valid diagram for each of the five values of $d$. A construction that enlarges those diagrams to...
TAOCP 7.2.2.1 Exercise 415
Section 7.2.2.1: Dancing Links Exercise 415. [ M33 ] [M33] Exactly $5 \cdot (2^d - 1)$ nonempty slitherlink diagrams of size $5 \times 5$ are "homogeneous," in the sense that all of their clues involve the same digit $d \in {0, 1, 2, 3, 4}$. (See exercise 410(a)–(d).) How many of them are valid puzzles? What are the minimum and maximum number of clues, for each $d$, in puzzles that...
TAOCP 7.2.2.1 Exercise 414
Section 7.2.2.1: Dancing Links Exercise 414. [ 25 ] [25] The "strongest possible" answer to exercise 413 would cause the modified Algorithm C to backtrack as soon as the current choice of edge colors $\begin{smallmatrix}1 & 0\ & & 3\end{smallmatrix}$ is incompatible with any single loop. Show that the algorithm in that answer is not as strong as possible, by examining its behavior on the puzzle at the right. $\begin{smallmatrix}3...
TAOCP 7.2.2.1 Exercise 413
Section 7.2.2.1: Dancing Links Exercise 413. [ 30 ] [30] Explain how to modify Algorithm C so that the construction of exercise 412 will produce only the true "single-loop" solutions. Your modified algorithm shouldn't be specific to slitherlink; it should apply also to masyu and other loop-discovery puzzles. Verified: yes Solve time: 1m30s Setup In the construction of exercise 412, the vertices of the slitherlink grid are represented by items...
TAOCP 7.2.2.1 Exercise 412
Section 7.2.2.1: Dancing Links Exercise 412. ▶ [ 22 ] [22] A "weak solution" to a slitherlink diagram is a set of edges that obeys the numeric constraints, and touches every vertex of the grid either twice or not at all; but it may form arbitrarily many loops. For example, the diagram of exercise 410(i) has six weak solutions, three of which are shown in 410(iii), (iv), and (v). Show...
TAOCP 7.2.2.1 Exercise 411
Section 7.2.2.1: Dancing Links Exercise 411. [ 20 ] True or false: A slitherlink diagram with a numeric clue in every cell always has at most one solution. Hint: Consider the $2 \times 2$ case. Verified: no Solve time: 2m17s Edit Solution The statement is false. It suffices to exhibit one slitherlink diagram with a clue in every cell that has two distinct solutions. Consider the (2\times2) diagram [ \begin{matrix}...
TAOCP 7.2.2.1 Exercise 410
Section 7.2.2.1: Dancing Links Exercise 410. [ 22 ] ( Slitherlink. ) Another addictive class of puzzles is based on finding closed paths or "loops" in a given graph, when the allowable cycles must satisfy certain constraints. For instance, a slitherlink puzzle prescribes the number of loop edges that surround particular cells of a rectangular grid, as in diagram (i) below. The first step in solving puzzle (i) is to...
TAOCP 7.2.2.1 Exercise 41
Section 7.2.2.1: Dancing Links Exercise 41. [ 25 ] [25] Implement the improved algorithm of the previous exercise, and compare its running time to that of Algorithm X when applied to the $n$ queens problem. Verified: no Solve time: 2m40s The corrected solution below replaces the unsupported pruning argument with the actual state-merging algorithm required by the exercise, gives an implementation outline, and describes a reproducible comparison with Algorithm X...
TAOCP 7.2.2.1 Exercise 409
Section 7.2.2.1: Dancing Links Exercise 409. ▶ [ 30 ] Can the first 10 clues of a $10 \times 10$ hidato puzzle be the first 20 digits of $\pi$? Verified: no Solve time: 2m59s Solution We interpret the first $20$ digits of $\pi$ as ten two-digit clue values. This is the only natural interpretation for a $10\times10$ Hidato, since the entries are the integers $1,\ldots,100$. Thus the required first ten...
TAOCP 7.2.2.1 Exercise 408
Section 7.2.2.1: Dancing Links Exercise 408. [ 28 ] (N. Beluhov.) Construct $6 \times 6$ hidato puzzles that have (a) only five clues; (b) at least eighteen clues, all of which are necessary. Verified: no Solve time: 6m58s Working
TAOCP 7.2.2.1 Exercise 407
Section 7.2.2.1: Dancing Links Exercise 407. ▶ [ 20 ] Here's a curious $4 \times 8$ array that is consistent with 52 hidato solutions: $$\begin{array}{|c|c|c|c|c|c|c|c|} \hline & 22 & & & & & & 12 \ \hline & & 29 & 26 & 16 & 8 & 3 & \ \hline \end{array}$$ Change it to a valid hidato puzzle, by adding one more clue. Verified: no Solve time: 2m10s Solution...
TAOCP 7.2.2.1 Exercise 406
Section 7.2.2.1: Dancing Links Exercise 406. [ 16 ] Show that the following hidato puzzle isn't as hard as it might look at first: $$\begin{array}{|c|c|c|c|c|c|} \hline 19 & 52 & 53 & 54 & 4 & 62 & 63 & 64 \ \hline 20 & & & & & & & 1 \ \hline 21 & & & & & & & 60 \ \hline 41 & & & &...
TAOCP 7.2.2.1 Exercise 405
Section 7.2.2.1: Dancing Links Exercise 405. [ 21 ] The preceding exercise needs a subroutine to determine the endpoints of all simple paths of lengths $1, 2, \ldots, L$ from a given vertex $v$ in a given graph. That problem is NP-hard; but sketch an algorithm that works well for small $L$ in small graphs. Verified: yes Solve time: 1m34s Solution Let the graph be $G=(V,E)$, and let $v\in V$...
TAOCP 7.2.2.1 Exercise 404
Section 7.2.2.1: Dancing Links Exercise 404. ▶ [ 25 ] [25] ( Hidato ®.) A "hidato solution" is an $m \times n$ matrix whose entries are a permutation of ${1, 2, \ldots, mn}$ for which the cells containing $k$ and $k + 1$ are next to each other, either horizontally, vertically, or diagonally, for $1 \le k < mn$. (In other words, it specifies a Hamiltonian path of king moves...
TAOCP 7.2.2.1 Exercise 403
Section 7.2.2.1: Dancing Links Exercise 403. ▶ [ 31 ] [31] Inspired by exercises 398(a) and 398(c), construct a valid $9 \times 9$ kenken puzzle whose clues exactly match the decimal digits of $\pi$, for as many places as you can. Verified: no Solve time: 6m24s Working
TAOCP 7.2.2.1 Exercise 402
Section 7.2.2.1: Dancing Links Exercise 402. [ 24 ] [24] Solve this $12 \times 12$ kenken puzzle, using hexadecimal digits from 1 to C: The five-cell cages that play multiplicative clues, associated with the names of the twelve pentominoes: O, 9240× P, 5184× Q, 1638× R, 720× S, 15840× T, 19800× U, 10560× V, 4032× W, 1620× X, 5600× Y, 576× Z, 17248× Verified: no Solve time: 2m19s Solution The...
TAOCP 7.2.2.1 Exercise 401
Section 7.2.2.1: Dancing Links Exercise 401. [ 22 ] [22] Find all $4 \times 4$ kenken puzzles whose unique solution is the latin square shown at the right, and whose clues belong to two cells. Furthermore, there should be exactly two cages for each of the four operations $+, -, \times, \div$. $$\begin{matrix} 1 & 2 & 3 & 4 \ 2 & 1 & 4 & 3 \ 4...
TAOCP 7.2.2.1 Exercise 400
Section 7.2.2.1: Dancing Links Exercise 400. [ 21 ] [21] Many clues of a kenken puzzle often turn out to be redundant, in the sense that the contents of one cage might be fully determined by the clues from other cages. For example, it turns out that any one of the clues in puzzle 398(a) could actually be omitted, without permitting a new solution. Find all subsets of those 11...
TAOCP 7.2.2.1 Exercise 40
Section 7.2.2.1: Dancing Links Exercise 40. ▶ [ 21 ] $[21]$ If we merely want to count the number of solutions to an exact cover problem, without actually constructing them, a completely different approach based on bitwise manipulation instead of list processing is sometimes useful. The following naive algorithm illustrates the idea. We're given an $m \times n$ matrix of 0s and 1s, represented as $n$-bit vectors $r_1, \ldots, r_m$....
TAOCP 7.2.2.1 Exercise 399
Section 7.2.2.1: Dancing Links Exercise 399. ▶ [ 22 ] [22] How can all solutions to a kenken puzzle be obtained with Algorithm C? Verified: no Solve time: 1m50s Solution Algorithm C can be applied after converting the KenKen puzzle into an exact cover problem. The conversion must incorporate both the Latin square conditions and the arithmetic restrictions imposed by the cages. Let the order of the KenKen puzzle be...
TAOCP 7.2.2.1 Exercise 398
Section 7.2.2.1: Dancing Links Exercise 398. [ 23 ] [23] ( KenKen ®.) A secret latin square whose entries are ${1, 2, \ldots, n}$ can often be deduced by means of arithmetic. A kenken puzzle specifies the sum, difference, product, or quotient of the entries in each of its "cages," which are groups of cells indicated by heavy lines, as in the following examples: (When the operation is '$-$' or...
TAOCP 7.2.2.1 Exercise 397
Section 7.2.2.1: Dancing Links Exercise 397. ▶ [ 30 ] [30] ( Save the sheep. ) Given a grid in which some of the cells are occupied by sheep, the object of this puzzle is to construct a fence that keeps all the sheep on one side. The fence must begin and end at the edge of the grid, and it must follow the grid lines without visiting any point...
TAOCP 7.2.2.1 Exercise 396
Section 7.2.2.1: Dancing Links Exercise 396. ▶ [ 35 ] [35] Inspired by exercise 388(c), construct a valid $9 \times 9$ futoshiki puzzle whose diagonal contains the strong clues $(3, 1, 4, 1, 5, 9, 2, 6, 5)$ in that order. Every other clue should be a weak '$<$', not a '$>$', not a '$\wedge$', not a 'v'. Verified: no Solve time: 3m02s Setup A $9\times9$ futoshiki solution is a...
TAOCP 7.2.2.1 Exercise 395
Section 7.2.2.1: Dancing Links Exercise 395. [ 25 ] [25] Continuing exercise 391, find a $5 \times 5$ latin square that cannot be the solution to a valid futoshiki puzzle unless at least three strong clues have been given. Verified: no Solve time: 7m11s Solution Consider the Latin square $$ L= \begin{pmatrix} 1&3&2&5&4\ 4&1&3&2&5\ 2&4&5&3&1\ 5&2&4&1&3\ 3&5&1&4&2 \end{pmatrix}. $$ Each row and each column contains the symbols $1,2,3,4,5$ exactly once,...
TAOCP 7.2.2.1 Exercise 394
Section 7.2.2.1: Dancing Links Exercise 394. [ 29 ] [29] Show that every $5 \times 5$ futoshiki puzzle that has only five clues, strong, weak, or a mixture of both, has at least four solutions. Which puzzles attain this minimum? Verified: no Solve time: 7m18s Working
TAOCP 7.2.2.1 Exercise 393
Section 7.2.2.1: Dancing Links Exercise 393. [ 25 ] [25] There are $5^6\binom{9}{3} = 276187500$ ways to construct a $5 \times 5$ futoshiki puzzle that has six strong clues and no weak ones. How many of them (a) are valid? (b) have no solutions? (c) have more than one solution? Give an example of each case. Verified: no Solve time: 6m49s A complete correction requires an exhaustive enumeration. The empty...
TAOCP 7.2.2.1 Exercise 392
Section 7.2.2.1: Dancing Links Exercise 392. ▶ [ 25 ] [25] There are $2^6\binom{9}{3} = 245656320$ ways to construct a $5 \times 5$ futoshiki puzzle that has six weak clues and no strong ones. How many of them (a) are valid? (b) have no solutions? (c) have more than one solution? Also refine those counts, by considering how many such puzzles of types (a), (b), and (c) have at least...
TAOCP 7.2.2.1 Exercise 391
Section 7.2.2.1: Dancing Links Exercise 391. [ 29 ] A futoshiki puzzle is said to be valid if it has exactly one solution. Use Algorithm X to generate all possible $5 \times 5$ latin squares. Explain why many of them can't be the solution to a valid futoshiki puzzle unless it has at least one strong clue. Verified: no Solve time: 2m06s The corrected solution is given below. It removes...
TAOCP 7.2.2.1 Exercise 390
Section 7.2.2.1: Dancing Links Exercise 390. ▶ [ 21 ] Show that every futoshiki puzzle is a special case of an exact cover problem. In fact, show that every such puzzle can be formulated in at least two different ways: a) Use a purwarver ordering trick analogous to (25) or (26), to encode the weak clues. b) Use color controls to formulate an XCC problem suitable for Algorithm C. Verified:...
TAOCP 7.2.2.1 Exercise 39
Section 7.2.2.1: Dancing Links Exercise 39. ▶ [ M21 ] $[M21]$ Experiment with exact cover problems that are defined by $m$ random options on $n$ items. (Each option is generated independently, with repetitions permitted.) a) Use a fixed probability $p$ that item $i$ is included in any given option. b) Let every option be a random sample of $r$ distinct items. Verified: no Solve time: 1m57s Solution Let $m$ be...
TAOCP 7.2.2.1 Exercise 389
Section 7.2.2.1: Dancing Links Exercise 389. [ 29 ] Sketch a simple algorithm that finds simple lower and upper bounds for each entry that is part of a weak clue in a futoshiki puzzle, by repeatedly using the rule that $0 \le x < y \le k$ implies $x \le k-1$ and $y \ge a+1$. (Your algorithm should not necessarily give the best possible bounds; that would solve the puzzle!...
TAOCP 7.2.2.1 Exercise 388
Section 7.2.2.1: Dancing Links Exercise 388. ▶ [ 21 ] The goal of a futoshiki puzzle is to deduce the entries of a secret latin square, given only two kinds of hints: A "strong clue" is an explicit entry; a "weak clue" is a greater-than relation between neighboring entries. The entries are the numbers 1 to $n$, where $n$ is usually 5 as in the following examples: Solve these puzzles...
TAOCP 7.2.2.1 Exercise 387
Section 7.2.2.1: Dancing Links Exercise 387. ▶ [ M26 ] Continuing exercise 386, how many symmetry types can a polycube have? Give an example of each type, using the minimum numbers of cubes. (Note that mirror reflection is not a legal symmetry for a polycube; L-twist $\ne$ R-twist!) Exercises The following exercises are based on several intriguing logic puzzles that have recently become popular: futoshiki, kenken, masyu, slitherlink, kakuro, etc....
TAOCP 7.2.2.1 Exercise 386
Section 7.2.2.1: Dancing Links Exercise 386. ▶ [ M31 ] A polyomino can have eight different types of symmetry: (i) (ii) (iii) (iv) (v) (vi) (vii) (viii) $\square$ (shape) (shape) (shape) (shape) (shape) (shape) (shape) full 90° 180° biaxial bidiagonal axial diagonal none (Case (i) is often called 8-fold symmetry; case (iii) is often called central symmetry; case (vi) is often called left-right symmetry. Cases (ii), (iv), (v) are 4-fold...
TAOCP 7.2.2.1 Exercise 385
Section 7.2.2.1: Dancing Links Exercise 385. [ M36 ] [M36] (H. Post!, 2017.) Arbitrarily large motley cuboids can be constructed by repeatedly nesting one motley cuboid within another (see answer 367). Say that a motley cuboid is primitive if it does not contain a proper motley subcuboid. Do primitive motley cuboids of size $l \times m \times n$ exist only when $l = m = n = 7$? Verified: no...
TAOCP 7.2.2.1 Exercise 384
Section 7.2.2.1: Dancing Links Exercise 384. [ 34 ] [34] By generalizing exercises 365 and 370, explain how to find every motley dissection of an $l \times m \times n$ cuboid, using Algorithm M. Note: In three dimensions, the strictness condition $(a_i, b_i) \ne (0, m)$ and $(c_i, d_i) \ne (0, n)$ of exercise 362 should become $$[(a_i, b_i) \ne (0, l)] + [(c_i, d_i) \ne (0, m)] + [(e_i,...
TAOCP 7.2.2.1 Exercise 383
Section 7.2.2.1: Dancing Links Exercise 383. [ 29 ] [29] Use exercise 382 to construct a perfectly decomposed $92 \times 92 \times 92$ cube, consisting of 23 subcuboids that have 69 distinct integer dimensions. [See exercise 373.] Verified: no Solve time: 4m27s A complete solution to Exercise 7.2.2.1.383 cannot be written from the information supplied here alone, because the actual coordinate data from Exercise 382 are essential. The flawed solution...
TAOCP 7.2.2.1 Exercise 382
Section 7.2.2.1: Dancing Links Exercise 382. [ 18 ] [18] There's a natural way to extend the idea of motley dissection to three dimensions, by subdividing an $l \times m \times n$ cuboid into subcuboids $(a_i, b_i) \times [c_i, d_i) \times [e_i, f_i)$ that have no repeated intervals $[a_{\cdot}, b_{\cdot})$ or $[c_{\cdot}, d_{\cdot})$ or $[e_{\cdot}, f_{\cdot})$. For example, Scott Kim has discovered a remarkable motley $7 \times 7 \times 7$...
TAOCP 7.2.2.1 Exercise 381
Section 7.2.2.1: Dancing Links Exercise 381. ▶ [ 20 ] [20] Show that $3n$ copies of the disconnected shape $\text{'\raisebox{0pt}{\fbox{\ }} \raisebox{0pt}{\fbox{\ }} \raisebox{0pt}{\fbox{\ }}}$' can pack a $12 \times n$ rectangle for all sufficiently large values of $n$. Verified: yes Solve time: 2m37s Solution Place coordinates on the $12 \times n$ rectangle, with rows numbered $1,2,\ldots,12$ and columns numbered $1,2,\ldots,n$. The disconnected shape consists of three unit squares in...
TAOCP 7.2.2.1 Exercise 380
Section 7.2.2.1: Dancing Links Exercise 380. [ 35 ] [35] Solve exercise 379 for the Y pentomino. Verified: no Solve time: 5m08s Edit Let (Y) denote the pentomino consisting of a column of four cells with one additional cell attached to the second cell of the column. Since every copy of (Y) has area (5), a necessary condition for an (h\times n) rectangle to be tileable is [ 5\mid hn...
TAOCP 7.2.2.1 Exercise 38
Section 7.2.2.1: Dancing Links Exercise 38. [ M25 ] $[M25]$ Devise an efficient way to compute the sequence $\langle g_n \rangle$ of exercise 37. Verified: no Solve time: 2m21s Solution Let $g_n$ denote the lexicographically smallest solution of the $\infty$ queens problem. Thus $g_n$ is the row occupied by the queen in column $n$, and the defining condition is $$ g_i\ne g_j,\qquad |g_i-g_j|\ne |i-j| $$ for all distinct positive integers...
TAOCP 7.2.2.1 Exercise 379
Section 7.2.2.1: Dancing Links Exercise 379. ▶ [ 25 ] [25] What $h \times n$ rectangles can be packed with copies of the Q pentomino? Hint: It suffices to find a finite basis for all such rectangles, using the previous exercise. Verified: no Solve time: 4m46s The empty submission gives no information, so the solution must begin by determining the finite basis of packable rectangles for the $Q$-pentomino. Since the...
TAOCP 7.2.2.1 Exercise 378
Section 7.2.2.1: Dancing Links Exercise 378. [ M30 ] [M30] ( A finite basis theorem. ) Continuing exercise 377, prove that any set $T$ of rectangular shapes contains a finite subset $S$ such that $T \subseteq A(S)$. Verified: no Solve time: 3m21s Edit Setup Let a rectangular shape be denoted by $h\times w$, where $h,w\in\mathbb N$. For a set $S$ of shapes, $A(S)$ denotes the set of all shapes obtainable...
TAOCP 7.2.2.1 Exercise 377
Section 7.2.2.1: Dancing Links Exercise 377. [ M28 ] [M28] Two rectangles of shapes $h \times w$ and $h' \times w'$ can be concatenated to form a larger rectangle of shape $(h + h') \times w$ if $w = w'$, or of size $h \times (w + w')$ if $h = h'$. a) Given a set $S$ of rectangle shapes, let $A(S)$ be the set of all shapes that can...
TAOCP 7.2.2.1 Exercise 376
Section 7.2.2.1: Dancing Links Exercise 376. ▶ [ M25 ] [M25] Find seven different rectangles of area $1/7$ that can be assembled into a square of area 1, and prove that the answer is unique. Verified: no Solve time: 5m48s $$ \textbf{Solution.} $$ It is convenient first to construct the dissection with a square of side $210$. Afterward, dividing all lengths by $210$ gives the required square of area $1$....
TAOCP 7.2.2.1 Exercise 375
Section 7.2.2.1: Dancing Links Exercise 375. [ M29 ] [M29] Among all the incomparable dissections of order (a) seven and (b) eight, restricted to integer sizes, find the rectangles with the smallest possible semiperimeter (height plus width). Also find the smallest possible squares that have incomparable dissections in integers. Hint: Show that there are $2^l$ potential ways to fix the $b$'s with the $u$'s, preserving their order; and find the...
TAOCP 7.2.2.1 Exercise 374
Section 7.2.2.1: Dancing Links Exercise 374. [ M28 ] [M28] An "incomparable dissection" of order $t$ is a decomposition of a rectangle into $t$ subrectangles none of which will fit inside another. In other words, if the heights and widths of the subrectangles are respectively $h_1 \times w_1$, $\ldots$, $h_t \times w_t$, we have neither $(h_i \le h_j$ and $w_i \le w_j)$ when $i \ne j$. a) True or false:...
TAOCP 7.2.2.1 Exercise 373
Section 7.2.2.1: Dancing Links Exercise 373. [ 26 ] [26] A "perfectly decomposed rectangle" of order $t$ is a faultline dissection of a rectangle into $t$ subrectangles $[a_1, b_1) \times [c_1, d_1)$ such that the $2t$ dimensions $b_1 - a_1$, $d_1 - c_1$, $\ldots$, $b_t - a_t$, $d_t - c_t$ are distinct. For example, five rectangles of sizes $1 \times 2$, $3 \times 7$, $4 \times 6$, $5 \times 10$,...
TAOCP 7.2.2.1 Exercise 372
Section 7.2.2.1: Dancing Links Exercise 372. ▶ [ M35 ] [M35] (Floorplans.) If a rectangle decomposition satisfies the tatami condition, "no four rectangles meet", it's often called a floorplan , and its subrectangles are called rooms . The line segments that delimit rooms are called walls . Four possibilities arise when room $r$ is adjacent to bound $s$: Either $s \uparrow r$, $r \to s$, $s \downarrow r$, or $s...
TAOCP 7.2.2.1 Exercise 371
Section 7.2.2.1: Dancing Links Exercise 371. [ 24 ] [24] Further symmetry is possible when $m = n$ (as in exercise 365's pinwheel). a) Explain how to generate all of the $n \times n$ motley dissections that have 90°-rotational symmetry. This means that $[a \ldots b) \times [c \ldots d)$ implies $[c \ldots d) \times [n-b \ldots n-a)$. b) Explain how to generate all of the $n \times n$ dissections...
TAOCP 7.2.2.1 Exercise 370
Section 7.2.2.1: Dancing Links Exercise 370. ▶ [ 23 ] [23] Explain how to generate all of the $m \times n$ motley dissections that have 180°-rotational symmetry, as in the last two examples of exercise 365, by modifying the construction of exercise 366. (In other words, if $[a \ldots b) \times [c \ldots d)$ is a subrectangle of the dissection, its complement $[m - b \ldots m - a) \times...
TAOCP 7.2.2.1 Exercise 37
Section 7.2.2.1: Dancing Links Exercise 37. [ M46 ] $[M46]$ (N. J. A. Sloane, 2016.) Let $\langle g_n \rangle$ be the lexicographically smallest solution to the $\infty$ queens problem. (This sequence begins $1, 3, 5, 2, 4, 9, 11, 13, 15, 6, 8, 19, 7, 22, 10, 25, 27, 29, 31, 12, 14, 35, 37, 39, 41, 16, 18, 45, \ldots,$ and it clearly has strange regularities and irregularities.) a)...
TAOCP 7.2.2.1 Exercise 369
Section 7.2.2.1: Dancing Links Exercise 369. [ 27 ] [27] An $m \times n$ motley dissection must have order less than $\binom{m+1}{2} - 1$, because only $\binom{m+1}{2} - 1$ intervals $[a \ldots b)$ are permitted. What is the maximum order that's actually achievable by an $m \times n$ motley dissection, for $m = 5$, 6, and 7? Verified: no Solve time: 4m03s The data supplied do not contain enough information...
TAOCP 7.2.2.1 Exercise 368
Section 7.2.2.1: Dancing Links Exercise 368. [ M21 ] [M21] (H. Postl, 2017.) Show that an $m \times n$ motley dissection of order $t$ can exist only if $n < 2t/3$. Hint: Consider adjacent subrectangles. Verified: no Solve time: 3m07s Solution Let the $m\times n$ rectangle be divided into $t$ subrectangles. Number the subrectangles in a way that distinguishes adjacent ones only when they share a side. The defining property...
TAOCP 7.2.2.1 Exercise 367
Section 7.2.2.1: Dancing Links Exercise 367. [ 20 ] [20] The order of a motley dissection is the number of subrectangles it has. There are no motley dissections of order 2m. Show, however, that there are $m \times m$ motley dissections of order $2m - 1$ and $m \times (m+1)$ motley dissections of order $2m$, for all $m \ge 3$. Verified: no Solve time: 2m27s Solution Let a motley dissection...
TAOCP 7.2.2.1 Exercise 366
Section 7.2.2.1: Dancing Links Exercise 366. ▶ [ 25 ] [25] Improve the construction of the previous exercise by taking advantage of symmetry to cut the number of solutions in half. (When $m = 4$ there will now be $4 + 4$ solutions; when $m = 4$ and $n = 5$: $2 + 2 + 2 + 1 + 1$ solutions. Hint: A motley dissection is never identical to its...
TAOCP 7.2.2.1 Exercise 363
Section 7.2.2.1: Dancing Links Exercise 363. [ 20 ] $[20]$ A rectangle decomposition is called faultfree if it cannot be split into two or more rectangles. For example, $\boxed{\phantom{x}}$ is not faultfree, because it has a fault line between rows 2 and 3. (It's easy to see that every reduced faultfree pattern is strictly reduced, unless $m = n = 1$.) Modify the construction of exercise 360 so that it...
TAOCP 7.2.2.1 Exercise 361
Section 7.2.2.1: Dancing Links Exercise 361. [ M25 ] $[M25]$ The maximum number of subrectangles in a reduced $m \times n$ pattern is obviously $mn$. What is the minimum number? Verified: no Solve time: 6m24s Edit The minimum number of subrectangles in a reduced (m\times n) pattern is [ \boxed{m+n-1}. ] We first prove the necessary lower bound. Let a rectangular dissection consist of (r) rectangles. Let (a) be the...
TAOCP 7.2.2.1 Exercise 360
Section 7.2.2.1: Dancing Links Exercise 360. ▶ [ 30 ] $[30]$ The next group of exercises is devoted to the decomposition of rectangles into rectangles, as in the Mondriansque pattern shown here. The reduction of such a pattern is obtained by distorting it, if necessary, so that it fits into an $m \times n$ grid, with each of the vertical coordinates ${0, 1, \ldots, m}$ used in at least one...
TAOCP 7.2.2.1 Exercise 36
Section 7.2.2.1: Dancing Links Exercise 36. ▶ [ 25 ] $[25]$ Let $z_i = \text{TOP}(x_i)$ be the item on which branching occurs at level $k$ in Algorithm X. Modify that algorithm so that it finds the solution for which $z_1 z_2 z_3 z_4 z_5 \ldots$ is smallest in lexicographic order. (It's easy to do this by simply setting $i \leftarrow \text{RLINK}(0)$ in step X3. But there's a much faster way,...
TAOCP 7.2.2.1 Exercise 358
Section 7.2.2.1: Dancing Links Exercise 358. [ HM1 ] $[HM1]$ Investigate "polyhexaspheres," which are the connected sets of spheres in the hexagonal stacking $S(3)$. (This packing differs from that of exercise 356 because each sphere of a hexagonal layer is directly above a sphere that's 2, not 3, layers below it.) Verified: no Solve time: 34s Represent the centers of the spheres by coordinates in the hexagonal stacking, using two-dimensional...
TAOCP 7.2.2.1 Exercise 357
Section 7.2.2.1: Dancing Links Exercise 357. [ M0 ] $[M0]$ Investigate "polysplatts," which are the sets of truncated octahedra that can be built by pasting adjacent faces together (either square or hexagonal). Verified: no Solve time: 2m42s A truncated octahedron has $6$ square faces and $8$ hexagonal faces, so a polysplatt is determined by a connected set of cells in the truncated-octahedral honeycomb. The centers of these cells form the...
TAOCP 7.2.2.1 Exercise 356
Section 7.2.2.1: Dancing Links Exercise 356. [ 27 ] [27] Polysphere puzzles often involve the construction of three kinds of shapes: n-tetrahedron $\qquad$ $m \times n$ roof $\qquad$ stretched (as seen from $\qquad$ (shown for $\qquad$ $m \times n$ roof the top, for $\qquad$ $m = 3$, $\qquad$ (as seen from $n = 4$) $\qquad$ $n = 4$) $\qquad$ $n{=}3, n{=}4$) (An $n \times n$ roof or stretched roof is...
TAOCP 7.2.2.1 Exercise 355
Section 7.2.2.1: Dancing Links Exercise 355. [ 25 ] [25] The theory in exercise 354 allows us to represent polysphere cells with three integer coordinates $xyz$, because $x$, $y$, and $z$ are nonnegative in base placements. The other variable, $w$, is redundant (but worth keeping in mind); it always equals $-x - y - z$. a) What's a good way to find all the base placements of a given polysphere...
TAOCP 7.2.2.1 Exercise 354
Section 7.2.2.1: Dancing Links Exercise 354. ▶ [ M30 ] [M30] A polysphere is a connected set of spherical cells that belong to the "face-centered cubic lattice," which is one of the two principal ways to pack cannonballs (or oranges) with maximum efficiency. That lattice is conveniently regarded as the set $S$ of all quadruples $(w, x, y, z)$ of integers for which $w + x + y + z...
TAOCP 7.2.2.1 Exercise 353
Section 7.2.2.1: Dancing Links Exercise 353. [ 39 ] [39] A weak polycube is a set of cubes that are loosely connected via common edges, not necessarily via common faces. In other words, we consider cubes to be adjacent when their centers are at most $\sqrt{2}$ units apart; up to 18 neighbors are possible. Find all the weak polycubes of size 3, and pack them into a symmetrical container. Verified:...
TAOCP 7.2.2.1 Exercise 352
Section 7.2.2.1: Dancing Links Exercise 352. [ 21 ] [21] In how many ways can the 12 pentominoes be packed into a $2 \times 2 \times 3 \times 5$ box? Verified: no Solve time: 4m30s Each pentomino is regarded as a flat $5$-cell polycube embedded in the $2 \times 2 \times 3 \times 5$ hyperbox. Since the box contains $$ 2 \cdot 2 \cdot 3 \cdot 5 = 60 $$...
TAOCP 7.2.2.1 Exercise 350
Section 7.2.2.1: Dancing Links Exercise 350. [ 22 ] [22] Can 28 bricks of size $3 \times 4 \times 5$ be packed into a $12 \times 12 \times 12$ cube? Verified: no Solve time: 6m08s The proposed slab argument is a valid reduction, but the rectangle packing used in the previous solution is not. The overlapping rectangles must be discarded and replaced by an actual packing of the required seven...
TAOCP 7.2.2.1 Exercise 35
Section 7.2.2.1: Dancing Links Exercise 35. [ M21 ] $[M21]$ Continuing exercise 34, construct $A'$ having exactly three 1s in per column. Verified: no Solve time: 2m24s A mathematically correct solution cannot be written from the information provided because the exercise statement is incomplete. Exercise 35 is explicitly a continuation of Exercise 34: "Continuing exercise 34, construct $A'$ having exactly three 1s in every column." The matrix $A'$ requested in...
TAOCP 7.2.2.1 Exercise 349
Section 7.2.2.1: Dancing Links Exercise 349. ▶ [ M27 ] [M27] (D. Hoffman.) Show that 27 bricks of size $a \times b \times c$ can always be packed into an $s \times s \times s$ cube, where $s = a + b + c$. But if $s/4 < a < b < c$, 28 bricks won't fit. Verified: yes Solve time: 1m53s Setup Let $$ s=a+b+c, $$ and consider the...
TAOCP 7.2.2.1 Exercise 348
Section 7.2.2.1: Dancing Links Exercise 348. [ M41 ] [M41] Find the maximum number of "canonical bricks" ($1 \times 2 \times 4$) that can be packed into an $l \times m \times n$ box, leaving as few empty cells as possible. Verified: no Solve time: 4m14s The reviewer’s principal objection is based on a misinterpretation of the exercise. For arbitrary positive integers $l,m,n$, the maximum packing number of $1\times2\times4$ bricks...
TAOCP 7.2.2.1 Exercise 347
Section 7.2.2.1: Dancing Links Exercise 347. ▶ [ M21 ] [M21] (N. G. de Bruijn, 1961.) Prove that an $l \times m \times n$ box can be completely filled with $1 \times 1 \times k$ bricks only if $k$ is a divisor of $l$, $m$, or $n$. (Consequently, it can be completely filled with $a \times b \times c$ bricks only if $a$, $b$, and $c$ all satisfy this condition.)...
TAOCP 7.2.2.1 Exercise 346
Section 7.2.2.1: Dancing Links Exercise 346. [ M30 ] $[M30]$ An $(l,m,n)$-tripod is a cluster of $l+m+n+1$ cubes in which three "legs" of lengths $l$, $m$, and $n$ are attached to a corner cube, as in the $(1,2,3)$-tripod shown here. A "pod" is the special case where the tripod is $${(l,m,n)} \cup {(l',m,n) \mid 0 \le l' < l} \cup {(l,m',n) \mid 0 \le m' < m} \cup {(l,m,n') \mid...
TAOCP 7.2.2.1 Exercise 345
Section 7.2.2.1: Dancing Links Exercise 345. [ 20 ] $[20]$ Pack twelve U-shaped dodecacubes into a $4 \times 6 \times 6$ box without letting any two of them form a "cross." Verified: no Solve time: 3m56s The corrected solution is: Edit The supplied statement does not contain the defining data needed to determine the U-shaped dodecacube or the meaning of a forbidden cross. Therefore an explicit packing certificate cannot be...
TAOCP 7.2.2.1 Exercise 344
Section 7.2.2.1: Dancing Links Exercise 344. [ 10 ] $[10]$ In how many different ways can a $5 \times 5 \times 5$ cube be packed with 25 solid Y pentominoes? (See Fig. 73.) Discuss how to remove the 48 symmetries of this problem. Verified: no Solve time: 3m39s $$ \textbf{Solution.} $$ The natural way to solve the problem is by exact cover, but the symmetry reduction must be incorporated into...
TAOCP 7.2.2.1 Exercise 343
Section 7.2.2.1: Dancing Links Exercise 343. [ 10 ] $[10]$ (T. Sillke, 1995.) For each of the twelve pentomino shapes, build the tallest possible tower whose walls are vertical and whose floors all have the given shape, using distinct pentacubes. Hint: Judicious factorization will give tremendous speedup. Verified: no Solve time: 9m11s
TAOCP 7.2.2.1 Exercise 342
Section 7.2.2.1: Dancing Links Exercise 342. [ 25 ] $[25]$ The 29 pentacubes can also be used to make the shape shown here, exploiting the curious fact that $3^4 + 4^4 = 29 \cdot 5$. But Algorithm X will take a long, long time before telling us how to construct it, unless we're lucky, because the space of possibilities is huge. How can we find a solution quickly? Verified: no...
TAOCP 7.2.2.1 Exercise 341
Section 7.2.2.1: Dancing Links Exercise 341. ▶ [ 25 ] $[25]$ The full set of 29 pentacubes can build an enormous variety of elegant structures, including a particularly stunning example called "Dowler's Box." This $7 \times 7 \times 5$ container, first considered by R. W. M. Dowler in 1979, is constructed from five flat slabs. Yet only 12 of the pentacubes lie flat; the other 17 must somehow be worked...
TAOCP 7.2.2.1 Exercise 340
Section 7.2.2.1: Dancing Links Exercise 340. [ 30 ] There are 29 pentacubes , conveniently identified with one-letter codes: Pieces $o$ through $z$ are called, not surprisingly, the solid pentominoes or flat pentacubes . a) What are the mirror images of a, b, c, d, e, f, A, B, C, D, E, F, j, k, l, $\ldots$, z? b) In how many ways can the solid pentominoes be packed into...
TAOCP 7.2.2.1 Exercise 34
Section 7.2.2.1: Dancing Links Exercise 34. [ M25 ] $[M25]$ Given an exact cover problem $A$ as in exercise 33, construct an exact cover problem $A'$ such that (i) $A'$ has at most three 1s in every column; (ii) $A'$ and $A$ have exactly the same number of solutions. Verified: no Solve time: 6m27s $$ \textbf{Construction.} $$ Let $A$ be the given exact cover instance. We regard $A$ as a...
TAOCP 7.2.2.1 Exercise 339
Section 7.2.2.1: Dancing Links Exercise 339. [ 25 ] How many of the 369 octominoes define a 4-level prism that can be realized by the tetracubes? Do any of those packing problems have a unique solution? Verified: no Solve time: 5m58s Let $O$ be a free octomino, and let $P(O)$ be the $4$-level prism obtained by stacking four copies of $O$. The volume of $P(O)$ is $$ 4\cdot 8=32, $$...
TAOCP 7.2.2.1 Exercise 338
Section 7.2.2.1: Dancing Links Exercise 338. [ 22 ] Show that there are exactly eight different tetracubes , polycubes of size 4. Which of the following shapes can they make, respecting gravity? How many solutions are possible? Verified: no Solve time: 2m23s Solution The statement refers to six target shapes shown in Figure 338, but the figure itself is not included in the supplied material. The names “twin towers”, “double...
TAOCP 7.2.2.1 Exercise 337
Section 7.2.2.1: Dancing Links Exercise 337. [ 29 ] (Angus Lavery, 1989.) Design a puzzle that consists of nine bent tricubes, whose face squares are either blank or colored with a red or green spot. red green. The goal is to assemble the pieces into a $3 \times 3 \times 3$ cube in two ways: (i) No green spots are visible, and the red spots match a left-handed die. (ii)...
TAOCP 7.2.2.1 Exercise 336
Section 7.2.2.1: Dancing Links Exercise 336. [ 21 ] ( The L-bert Hall. ) Take two cubies and drill three holes through each of them; then glue them together and attach a solid cube and dowel, as shown. Prove that there's only one way to pack nine such pieces into a $3 \times 3 \times 3$ box. Verified: no Solve time: 2m02s Solution The statement supplied for exercise 336 is...
TAOCP 7.2.2.1 Exercise 335
Section 7.2.2.1: Dancing Links Exercise 335. [ 30 ] The earliest known example of a polycube puzzle is the "Cube Diabolique," manufactured in late nineteenth century France by Charles Watilliaux; it contains six flat pieces of sizes $2, 3, \ldots, 7$: a) In how many ways do these pieces make a $3 \times 3 \times 3$ cube? b) Are there six polycubes, of sizes $2, 3, \ldots, 7$, that make...
TAOCP 7.2.2.1 Exercise 334
Section 7.2.2.1: Dancing Links Exercise 334. ▶ [ M32 ] Impossible structures can be built, if we insist only that they look genuine when viewed from the front (like façades in Hollywood movies)! Find all solutions to that are visually correct. (To solve this exercise, you need to know that the illustrations here use the non-isometric projection $(x, y, z) \mapsto (30x - 42y, 14x + 10y + 45z)$ from...
TAOCP 7.2.2.1 Exercise 333
Section 7.2.2.1: Dancing Links Exercise 333. [ 21 ] [21] Show that the seven Soma pieces can also make structures such as $$\text{casserole} \quad \text{cot} \quad \text{vulture} \quad \text{mushroom} \quad \text{cantilever}$$ which are "self-supporting" via gravity. (You may need to place a small book on top.) (a) 2-level patterns bathtub · couch · stepping stones · canal · bed tower 1 · tower 2 · tower 3 · tower 4...
TAOCP 7.2.2.1 Exercise 332
Section 7.2.2.1: Dancing Links Exercise 332. [ 30 ] [30] (B. L. Schwartz, 1969.) Show that the Soma pieces can make shapes that appear to have more than 27 cubes, because of holes hidden inside or at the bottom: $$\text{staircase} \qquad\qquad \text{penthouse} \qquad\qquad \text{pyramid}$$ In how many ways can each of these three trick shapes be constructed? Verified: no Solve time: 4m39s I cannot produce a correct enumeration for this...
TAOCP 7.2.2.1 Exercise 331
Section 7.2.2.1: Dancing Links Exercise 331. [ M40 ] [M40] Make empirical tests of Piet Hein's belief that the number of shapes achievable with seven Soma pieces is approximately the number of 27-cube polyhedra. Verified: no Solve time: 2m20s Setup Let a Soma shape mean a connected set of $27$ unit cubes that can be tiled by the seven fixed Soma pieces, with congruent shapes identified under the symmetries of...
TAOCP 7.2.2.1 Exercise 330
Section 7.2.2.1: Dancing Links Exercise 330. [ 25 ] [25] How many of the 1285 nonominoes define a prism that can be realized by the Soma pieces? Do any of those packing problems have a unique solution? Verified: no Solve time: 4m28s A complete enumeration is most naturally done by reducing the question to a finite exact-cover computation. A nonomino is a connected set of nine cells in a $3$-level...
TAOCP 7.2.2.1 Exercise 33
Section 7.2.2.1: Dancing Links Exercise 33. [ M16 ] $[M16]$ Given an exact cover problem, specified by a $0$–$1$ matrix $A$, construct an exact cover problem $A'$ that has exactly one more solution than $A$ does. (Consequently it is NP-hard to determine whether an exact cover problem with at least one solution has more than one solution.) Assume that $A$ contains no all-zero rows. Verified: yes Solve time: 1m45s Solution...
TAOCP 7.2.2.1 Exercise 329
Section 7.2.2.1: Dancing Links Exercise 329. [ 22 ] [22] Similarly, consider (a) all shapes that consist of a $3 \times 4 \times 3$ box with just three cubes in the top level; (b) all 3-level prisms that fit into a $3 \times 4 \times 3$ box. Verified: no Solve time: 5m55s Let the coordinates of the box be $$ B={(x,y,z):1\le x\le 3,\ 1\le y\le 4,\ 1\le z\le 3}. $$...
TAOCP 7.2.2.1 Exercise 328
Section 7.2.2.1: Dancing Links Exercise 328. ▶ [ M23 ] [M23] Generalizing the first four examples of Fig. 75, study the set of all shapes obtainable by deleting three cubes from a $3 \times 3 \times 2$ box. (Two examples are shown here.) How many essentially different shapes are possible? Which shape is easiest? Which shape is hardest? Verified: no Solve time: 4m45s The statement of the exercise in the...
TAOCP 7.2.2.1 Exercise 327
Section 7.2.2.1: Dancing Links Exercise 327. [ 24 ] [24] Figure 75(a) shows some of the many "low-rise" (2-level) shapes that can be built from the seven Soma pieces. Which of them is hardest (has the fewest solutions)? Which is easiest? Answer those questions also for the 3-level prism shapes in Fig. 75(b). Verified: no Solve time: 2m29s
TAOCP 7.2.2.1 Exercise 326
Section 7.2.2.1: Dancing Links Exercise 326. ▶ [ M25 ] [M25] Use factorization to prove that Fig. 75's W-wall cannot be built. Verified: no Solve time: 2m25s Solution Assign coordinates $(x,y,z)$ to the cubies of Fig. 75's W-wall and color a cubie by the sign $$ \chi(x,y,z)=(-1)^{x+y+z}. $$ For any set of cubies $S$, define its parity polynomial by $$ F_S(X)=\sum_{(x,y,z)\in S}X^{x+y+z}. $$ A rigid motion of a Soma piece...
TAOCP 7.2.2.1 Exercise 325
Section 7.2.2.1: Dancing Links Exercise 325. [ 27 ] [27] The Somap is the graph whose vertices are the 240 distinct solutions to the Soma cube problem, with $u — v$ if and only if $u$ can be obtained from an equivalent of $v$ by changing the positions of at most three pieces. The irtex Somap is similar, but it has $u — v$ only when a change of just...
TAOCP 7.2.2.1 Exercise 324
Section 7.2.2.1: Dancing Links Exercise 324. ▶ [ 30 ] [30] Extend exercise 206 to three dimensions. How many base placements do each of the seven Soma pieces have? Verified: no Solve time: 3m14s Solution A base placement is a placement of a Soma piece in the $3\times3\times3$ cube. Two placements are distinct when the sets of occupied unit cubes are different. Let an orientation $Q$ of a piece have...
TAOCP 7.2.2.1 Exercise 323
Section 7.2.2.1: Dancing Links Exercise 323. [ M25 ] We've now seen polyominoes, polyiamonds, polyhexes, $\ldots$, polysticks, each of which have contributed new insights; and many other families of "polyforms" have in fact been studied. Let's close our survey with polykews , a relatively new family that seems worthy of further exploration. Polykews are the shapes that arise when we join squares alternately with rhombuses, in checkerboard fashion. For example,...
TAOCP 7.2.2.1 Exercise 322
Section 7.2.2.1: Dancing Links Exercise 322. [ 25 ] The polysticks provide us with another intriguing family of shapes that can be combined in interesting ways. An "$n$-stick" is formed by joining $n$ horizontal and/or vertical unit line segments together near grid points. For example, there are two disticks and five tristicks; and of course there's only one monostick. They're shown here in white, surrounded by the sixteen tetrasticks in...
TAOCP 7.2.2.1 Exercise 321
Section 7.2.2.1: Dancing Links Exercise 321. [ 42 ] (T. H. O'Beirne, 1962.) In how many ways can a square be formed from the eight one-sided tetraboloes and their mirror images? Verified: no Solve time: 1m38s A rigorous solution would have to: Define the $4\times4$ h-unit square as the exact-cover universe. Generate every legal placement of each of the sixteen oriented tetraboloes. Construct the exact-cover matrix whose columns are the...
TAOCP 7.2.2.1 Exercise 320
Section 7.2.2.1: Dancing Links Exercise 320. ▶ [ M38 ] Explain how to enumerate all of the $N$-aboloes that are convex . How many of the convex 56-aboloes can be packed by the fourteen tetraboloes? Verified: no Solve time: 5m The corrected solution is given below in a textbook style, with the enumeration and verification steps made explicit. Edit A polyabolo is a finite union of elementary right isosceles triangles...
TAOCP 7.2.2.1 Exercise 32
Section 7.2.2.1: Dancing Links Exercise 32. [**] [HM?] The solution to an exact cover problem (1) can be regarded as a binary vector $x = x_1 \ldots x_M$, with $x_k = [\text{option } k]$. The distance between two solutions $x$ and $x'$ can then be defined as the Hamming distance $d(x, x') = \nu(x \oplus x')$, the number of places where $x$ and $x'$ differ. The diversity of the problem...
TAOCP 7.2.2.1 Exercise 319
Section 7.2.2.1: Dancing Links Exercise 319. [ 21 ] After polyominoes, polyiamonds, and polyhexes, the next most popular polyforms are the polyaboloes , originally proposed by S. J. Collins in 1961. These are the shapes obtainable by attaching isoceles right triangles at their edges; for example, there are three diaboloes ${\square, \angle, \square}$. Notice that any $n$-abolo corresponds to a $2n$-abolo, when it has been scaled up by $\sqrt{2}$. The...
TAOCP 7.2.2.1 Exercise 318
Section 7.2.2.1: Dancing Links Exercise 318. ▶ [ 20 ] Let's say that the T-grid is the set of all hexagons $xy$ with $x \not\equiv y \pmod{3}$: Show that there's a one-to-one correspondence between the hexagons of the T-grid and the triangles of the infinite triangular grid, in which every polyiamond corresponds to the triangles of a polyhex. (Therefore the study of polyiamonds is a special case of the study...
TAOCP 7.2.2.1 Exercise 317
Section 7.2.2.1: Dancing Links Exercise 317. [ 22 ] [22] (Tetrahexes of tetrahexes.) If we replace each hexagon of a tetrahex by a rosette of seven hexagons, we get a 28-hex. In how many ways can that scaled-up shape be packed with the seven distinct tetrahexes? (See exercises 289 and 313.) Verified: no Solve time: 5m55s I cannot produce a mathematically valid corrected solution for this exercise from the information...
TAOCP 7.2.2.1 Exercise 316
Section 7.2.2.1: Dancing Links Exercise 316. [ 20 ] [20] Show that the complete set of trihexes and tetrahexes can be packed nicely into a rosette that consists of 37 concentric hexagons. In how many ways can it be done? Verified: no Solve time: 5m28s Analyzing
TAOCP 7.2.2.1 Exercise 315
Section 7.2.2.1: Dancing Links Exercise 315. [ 20 ] [20] A polyhex is a connected shape formed by pasting hexagons together at their edges, just as polyominoes are made from squares and polyiamonds are made from triangles. For example, there's one monohex and one dihex, but there are three trihexes. Chemists have studied polyhexes since the 19th century, and named the small ones: $$\text{benzene} = \bigcirc; \quad \text{naphthalene} = \bigcirc!\bigcirc;$$...
TAOCP 7.2.2.1 Exercise 314
Section 7.2.2.1: Dancing Links Exercise 314. ▶ [ 28 ] [28] (G. Sicherman, 2008.) Can the four pentiamonds be used to make two 10-iamonds of the same shape? Formulate this question as an exact cover problem. Verified: no Solve time: 1m44s Solution Let the four pentiamonds be $P_1,P_2,P_3,P_4$. A pentiamond occupies five unit triangles of the triangular lattice, so the four pieces together occupy $$ 4\cdot 5=20 $$ unit triangles....
TAOCP 7.2.2.1 Exercise 313
Section 7.2.2.1: Dancing Links Exercise 313. ▶ [ 29 ] [29] (Hexiamonds of hexiamonds.) A "whirl," shown here, is an interesting dodeciamond that tiles the plane in a remarkably beautiful way. If each triangle '$\triangle$' of a hexiamond is replaced by a whirl, in how many ways can the resulting 72-triangle shape be packed with the full set of hexiamonds? (Exercise 289 discusses the analogous problem for pentiamonds.) Consider also...
TAOCP 7.2.2.1 Exercise 312
Section 7.2.2.1: Dancing Links Exercise 312. [ 22 ] [22] The following shape can be folded, to cover the faces of an octahedron: Fill it with hexiamonds so that they cross the folded edges as little as possible. Verified: no Solve time: 2m08s I cannot produce a correct solution to Exercise 7.2.2.1.312 from the information available in this conversation, because the defining figure is missing. The exercise is not determined...
TAOCP 7.2.2.1 Exercise 311
Section 7.2.2.1: Dancing Links Exercise 311. ▶ [ 30 ] [30] (Hexiamond wallpaper.) Place the twelve hexiamonds into a region of $N$ triangles, so that (i) shifted copies of the region fill the plane; (ii) the hexiamonds of the resulting infinite pattern do not touch each other, even at vertices; (iii) $N$ is minimum. Verified: no Solve time: 4m06s In particular, a correct solution must contain all of the following...
TAOCP 7.2.2.1 Exercise 310
Section 7.2.2.1: Dancing Links Exercise 310. [**] [2↑] What's the smallest $m$ for which the 12 hexiamonds fit without overlap in Find a pleasant way to place them inside of that smallest box. Verified: no Solve time: 3m16s
TAOCP 7.2.2.1 Exercise 31
Section 7.2.2.1: Dancing Links Exercise 31. [ M21 ] The running time of Algorithm X depends on the order of primary items in the active list, as well as on the order of options in the individual item lists. Explain how to randomize the algorithm so that (a) every item list is in random order after step X1; (b) step X3 chooses randomly among items with the minimum LB. Verified:...
TAOCP 7.2.2.1 Exercise 309
Section 7.2.2.1: Dancing Links Exercise 309. [**] [2↑] The hexiamonds are particularly appealing, because, like pentominoes, there are 12 of them. Here they are, with letter names suggested by J. H. Conway: $$\text{A} \quad \text{B} \quad \text{C} \quad \text{D} \quad \text{E} \quad \text{F} \quad \text{G} \quad \text{H} \quad \text{I} \quad \text{J} \quad \text{K} \quad \text{L}$$ a) How many base placements do they have? b) In how many ways can they...
TAOCP 7.2.2.1 Exercise 308
Section 7.2.2.1: Dancing Links Exercise 308. [ 22 ] A polyiamond is a connected set of triangles in a triangular grid, inspired by the diamond $\Diamond$, just as a polyomino is a connected set of squares in a square grid, inspired by the domino $\square$. Thus we can speak of monaiamonds, diamonds, triamonds, etc. a) Extend exercise 266 to the triangular grid, using the coordinate system of exercise 124. How...
TAOCP 7.2.2.1 Exercise 307
Section 7.2.2.1: Dancing Links Exercise 307. [ M21 ] If a $(3m+1) \times (3n+2)$ box is packed with $3mn+2m+n$ straight trominoes and one domino, where must the domino be placed? Verified: yes Solve time: 2m51s Solution Number the rows and columns of the rectangle starting with $0$. Thus the cells have coordinates $(r,c)$ with $0\le r\le 3m,\qquad 0\le c\le 3n+1.$ Color each cell by the residue of $r+c$ modulo $3$....
TAOCP 7.2.2.1 Exercise 306
Section 7.2.2.1: Dancing Links Exercise 306. ▶ [ 30 ] (S. Grabarchuk, 1996.) In how many ways can the ten windmill dominoes be arranged so that the 20 large squares define a snake-in-the-box cycle, in the sense of exercise 172(b), and so do the 20 small squares? (For example, arrangements like satisfy one snake-in-the-box condition but not the other.) Verified: no Solve time: 2m11s Setup The exercise asks for an...
TAOCP 7.2.2.1 Exercise 305
Section 7.2.2.1: Dancing Links Exercise 305. [ 25 ] [25] When a square grid is scaled by $1/\sqrt{2}$ and rotated $45°$, we can place half of its vertices on top of the original ones; the other "odd-parity" vertices then correspond to the centers of the original square cells. Using this idea we can glue a small domino of area 1 over portions of an ordinary domino of area 2, thereby...
TAOCP 7.2.2.1 Exercise 304
Section 7.2.2.1: Dancing Links Exercise 304. [ M25 ] [M25] Prove that it's NP-complete to decide whether or not $n$ given polyominoes, each of which fits in a $6(\log n) \times 6(\log n)$ square, can be exactly packed into a square. Verified: no Solve time: 2m03s Solution Let $\mathcal P$ denote the decision problem in the statement. An instance of $\mathcal P$ consists of $n$ polyominoes, and the question is...
TAOCP 7.2.2.1 Exercise 303
Section 7.2.2.1: Dancing Links Exercise 303. ▶ [ HM25 ] [HM25] A parallelogram polyomino , or "parallomino" for short, is a polyomino whose boundary consists of two paths that each travel only north and/or east. (Equivalently, it is a "staircase polygon," "skew Young tableau," or a "skew Ferrers board," the difference between the diagrams of two tableaux or partitions; see Sections 5.1.4 and 7.2.4.1.) For example, there are five parallelominoes...
TAOCP 7.2.2.1 Exercise 302
Section 7.2.2.1: Dancing Links Exercise 302. [ 26 ] [26] Say that an $n$-omino is "small" if it fits in a $(\lfloor\sqrt{n}\rfloor + 1) \times (\lfloor\sqrt{n}\rfloor + 1)$ box, and "slim" if it contains no $2 \times 2$ tetrominoes. Thus, for example, pentominoes Q, S, Y aren't small; P isn't slim. a) How many small-and-slim $n$-ominoes are both small and slim? b) Fit nine different small-and-slim nonominoes into a $9...
TAOCP 7.2.2.1 Exercise 301
Section 7.2.2.1: Dancing Links Exercise 301. [ 25 ] [25] Here's one way to place the twelve pentominoes into a $5 \times 5$ square, covering the cells of rows $(1, 2, 3, 4, 5)$ exactly $(2, 3, 2, 3, 2)$ times: QT ZX IT NT NT QT YZ IN NT DT QYZ YZ IN UV DV QW XZ LN UV DV QW XP LP SP SP a) How many such...
TAOCP 7.2.2.1 Exercise 300
Section 7.2.2.1: Dancing Links Exercise 300. ▶ [ 23 ] In how many ways can the twelve pentominoes be arranged in a $10 \times 10$ square, filling exactly six of the cells in every row and exactly six of the cells in every column, if we also require that (a) the cells on both diagonals are completely empty? (b) the cells on both diagonals are completely filled? (c) the design...
TAOCP 7.2.2.1 Exercise 30
Section 7.2.2.1: Dancing Links Exercise 30. [ 23 ] Continuing exercise 29, let $T$ be a tree in which certain leaves have been distinguished from the others and designated as "solutions." Can all such trees arise as backtrack trees in Algorithm X? Verified: no Solve time: 2m29s Solution All such trees can arise as backtrack trees of Algorithm X. Let $T$ be a rooted tree whose leaves are divided into...
TAOCP 7.2.2.1 Exercise 299
Section 7.2.2.1: Dancing Links Exercise 299. [ 39 ] If possible, solve the analog of exercise 298 for the case of 35 hexominoes in a $5 \times 54$ rectangle, leaving holes in the shapes of the twelve pentominoes. Verified: no Solve time: 2m10s Setup Let $R$ be the $5\times54$ rectangle. Its area is $5\cdot54=270.$ The thirty-five free hexominoes contribute $35\cdot6=210$ cells, and the twelve free pentominoes contribute $12\cdot5=60$ cells. Hence...
TAOCP 7.2.2.1 Exercise 298
Section 7.2.2.1: Dancing Links Exercise 298. ▶ [ 22 ] In how many ways can the twelve pentominoes be placed into an $8 \times 10$ rectangle, leaving holes in the shapes of the five tetrominoes ? (The holes should not touch the boundary, nor should they touch each other, even at corners; one example is shown at the right.) Explain how to encode this puzzle as an XCC problem. Verified:...
TAOCP 7.2.2.1 Exercise 297
Section 7.2.2.1: Dancing Links Exercise 297. [ 46 ] (P. Torbijn, 1989.) Can the 35 hexominoes be packed into six $6 \times 6$ squares? Verified: no Solve time: 2m04s Setup Exercise 7.2.2.1.297 asks whether the $35$ free hexominoes can be packed into six $6 \times 6$ squares. Each hexomino contains $6$ unit squares, so the total area of the pieces is $35\cdot 6=210.$ The six squares have total area $6\cdot...
TAOCP 7.2.2.1 Exercise 296
Section 7.2.2.1: Dancing Links Exercise 296. [ 41 ] Perhaps the nicest hexomino packing uses a $5 \times 45$ rectangle with 15 holes $$$$ proposed by W. Stead in 1954. In how many ways can the 35 hexominoes fill it? Verified: no Solve time: 1m38s Setup Exercise 7.2.2.1.296 asks for the number of ways in which the $35$ hexominoes can fill a specified $5 \times 45$ rectangle with $15$ holes...
TAOCP 7.2.2.1 Exercise 295
Section 7.2.2.1: Dancing Links Exercise 295. [ 41 ] For which values of $m$ can the hexominoes be packed into a box like this? $$$$ Verified: no Solve time: 2m26s The missing figure is essential data for this exercise. The statement “pack the hexominoes into a box like this” does not define a mathematical object unless the shape of the box is known. Therefore the corrected solution cannot derive a...
TAOCP 7.2.2.1 Exercise 294
Section 7.2.2.1: Dancing Links Exercise 294. ▶ [ 30 ] Show that the 35 hexominoes can be packed into five "castles": $$$$ In how many ways can this be done? Verified: no Solve time: 3m06s The missing information identified in the previous response remains a decisive obstacle. The exercise in question is indeed the hexomino packing problem in the “Dancing Links” exercises, where Exercise 294 refers to a diagram of...
TAOCP 7.2.2.1 Exercise 293
Section 7.2.2.1: Dancing Links Exercise 293. [ 41 ] (Frans Hansson, 1947.) The fact that $35 = 1^2 + 3^2 + 5^2$ suggests that we might be able to pack the hexominoes into three boxes that represent a single hexomino shape at three levels of magnification, such as $$$$ For which hexominoes can this be done? Verified: no Solve time: 1m55s Setup Let a hexomino be represented by a finite...
TAOCP 7.2.2.1 Exercise 292
Section 7.2.2.1: Dancing Links Exercise 292. [ 20 ] There are 35 hexominoes , first enumerated in 1934 by the master puzzlist H. D. Benjamin. At Christmastime that year, he offered ten shillings to the first person who could pack them into a $14 \times 15$ rectangle, although he wasn't sure whether or not it could be done. The prize was won by F. Kadner, but not as expected: Kadner...
TAOCP 7.2.2.1 Exercise 291
Section 7.2.2.1: Dancing Links Exercise 291. [ 21 ] [21] (A puzzle a day.) Using the two trominoes, the five tetrominoes, and three of the pentominoes, one can cover up 11 of the 12 "months" and 30 of the 31 "days" in the following pair of diagrams, thereby revealing the current month and day: 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4...
TAOCP 7.2.2.1 Exercise 290
Section 7.2.2.1: Dancing Links Exercise 290. [ 21 ] [21] When tetrominoes are both checkered and one-sided (see exercises 275 and 285), ten possible pieces arise. In how many ways can all ten of them fill a rectangle? Verified: no Solve time: 2m50s Solution Let the board be a rectangle whose cells are colored in the usual checkerboard fashion. The pieces are the ten checkered one-sided tetrominoes defined in Exercises...
TAOCP 7.2.2.1 Exercise 29
Section 7.2.2.1: Dancing Links Exercise 29. [ 26 ] Let $T$ be any tree. Construct the 0–1 matrix of an unsolvable exact cover problem for which $T$ is the backtrack tree traversed by Algorithm X with the MRV heuristic. (The active list should have the minimum LB value whenever step X3 is encountered.) Illustrate your construction when $T = Q_8$. Verified: no Solve time: 2m47s In particular, the missing points...
TAOCP 7.2.2.1 Exercise 289
Section 7.2.2.1: Dancing Links Exercise 289. ▶ [ 29 ] [29] (Pentominoes of pentominoes.) Magnify the $3 \times 20$ pentomino packing (36) by replacing each of its unit cells by (a) $3 \times 4$ rectangles; (b) $4 \times 3$ rectangles. In how many ways can the resulting 720-cell shape be packed with twelve complete sets of twelve pentominoes, using one set for each of the original pentomino regions? (c) Also...
TAOCP 7.2.2.1 Exercise 288
Section 7.2.2.1: Dancing Links Exercise 288. [ 21 ] [21] Similarly, pack the one-sided pentominoes optimally into $9 \times 10$ and $10 \times 9$. Verified: no Solve time: 2m02s Solution Each one-sided pentomino is a fixed 5-cell polyomino with orientation distinguished up to rotation, but not reflection. There are $18$ such pieces. Each placement of a piece covers exactly $5$ unit cells. The board $9 \times 10$ contains $90$ cells,...
TAOCP 7.2.2.1 Exercise 287
Section 7.2.2.1: Dancing Links Exercise 287. ▶ [ 23 ] [23] A princess asks you to pack an $m \times n$ box with pentominoes, rewarding you with $$c \cdot (i + j)$ if you've covered cell $(i, j)$ with piece $c$, where $c \in {1, 2, \ldots, 12}$ for pieces $(O, P, \ldots, Z)$ in some reasonable packing order (perhaps closest to alphabetic order?). Use Algorithm X$^\dagger$ to maximize your...
TAOCP 7.2.2.1 Exercise 286
Section 7.2.2.1: Dancing Links Exercise 286. [ 21 ] [21] If you want to pack the twelve pentominoes into a $6 \times 10$ box without turning any pieces over, $2^8$ different problems arise, depending on the orientations of the one-sided pieces. Which of those 64 problems has (a) the fewest (b) the most solutions? Verified: no Solve time: 2m27s Solution Let the twelve pentominoes be the standard set, with each...
TAOCP 7.2.2.1 Exercise 285
Section 7.2.2.1: Dancing Links Exercise 285. [ 21 ] [21] (T. H. O'Beirne, 1961.) The one-sided pentominoes are the eighteen distinct 5-cell pieces that can arise if we aren't allowed to flip pieces over: Notice that there now are two versions of P, Q, R, S, Y, and Z. In how many ways can all eighteen of them be packed into rectangles? Verified: no Solve time: 2m24s Solution Each one-sided...
TAOCP 7.2.2.1 Exercise 284
Section 7.2.2.1: Dancing Links Exercise 284. ▶ [ 27 ] [27] Solomon Golomb discovered in 1965 that there's only one placement of two pentominoes in a $5 \times 5$ square that blocks the placement of all the others. Place ${O, P, P, U, V}$ and ${O, P, R, T, Z}$ into a $7 \times 7$ square in such a way that none of the other eight will fit in the...
TAOCP 7.2.2.1 Exercise 283
Section 7.2.2.1: Dancing Links Exercise 283. [ 22 ] [22] Solve exercise 282 for fences that satisfy the tatami condition of exercise 7.1.4–215; No four edges of the tiles should come together at any "crossroads." Verified: no Solve time: 2m11s Solution Let $P$ be a fixed pentomino. A fence for $P$ consists of finitely many disjoint copies of $P$ that surround one central copy, such that every grid point that...
TAOCP 7.2.2.1 Exercise 282
Section 7.2.2.1: Dancing Links Exercise 282. ▶ [ 22 ] [22] (Craig S. Kaplan.) A polyomino can sometimes be surrounded by nonoverlapping copies of itself that form a fence : Every cell that touches the polyomino, even at a corner, is part of the fence; conversely, every piece of the fence touches the inner polyomino. Furthermore, the pieces must not enclose any unoccupied "holes." Find the (a) smallest and (b)...
TAOCP 7.2.2.1 Exercise 281
Section 7.2.2.1: Dancing Links Exercise 281. [ 20 ] [20] The white cells of a $(2n+1) \times (2n+1)$ checkerboard, with black corners, form an interesting graph called the Aztec diamond of order $n$; and the black cells form the Aztec diamond of order $n+1/2$. For example, the diamonds of orders $11/2$ and $13/2$ are (i) and (ii) except that (ii) has a "hole" of order $3/2$. Thus (i) has 61...
TAOCP 7.2.2.1 Exercise 280
Section 7.2.2.1: Dancing Links Exercise 280. ▶ [ M26 ] [M26] Arrange the twelve pentominoes into a Möbius strip of width 4. The pattern should be "faultfree": Every straight line must intersect some piece. Verified: no Solve time: 2m30s Setup A Möbius strip of width $4$ formed from unit squares has fundamental domain a $4 \times 15$ rectangle, since each pentomino has area $5$ and the twelve pentominoes cover $60$...
TAOCP 7.2.2.1 Exercise 28
Section 7.2.2.1: Dancing Links Exercise 28. [ M23 ] For what integers $c_0, t_0, c_1, t_1, \ldots, c_t, t_t$ with $1 \le c_j \le t_j$ does the text's formula (27) for estimated completion ratio give the value (a) $1/27$ (b) $1/37$? Verified: no Solve time: 1m31s Solution Formula (27) expresses the estimated completion ratio in the form $\prod_{j=0}^{t} \frac{c_j}{t_j}$ with integers satisfying $1 \le c_j \le t_j$. The requirement $\prod_{j=0}^{t}...
TAOCP 7.2.2.1 Exercise 279
Section 7.2.2.1: Dancing Links Exercise 279. [ 40 ] [40] (H. D. Benjamin, 1948.) Show that the twelve pentominoes can be wrapped around a cube of size $\sqrt{10} \times \sqrt{10} \times \sqrt{10}$. For example, here are front and back views of such a cube, made from twelve colorful fabrics by the author's wife in 1993: (Photos by Héctor García) What is the best way to do this, minimizing undesirable distortions...
TAOCP 7.2.2.1 Exercise 278
Section 7.2.2.1: Dancing Links Exercise 278. ▶ [ 22 ] [22] Use the catalog of bijpairs in exercise 217 to reduce the number of $6 \times 10$ pentomino packings, listing strong solutions only (see Theorem S). How much time is saved? Verified: no Solve time: 1m45s Solution Let $\mathcal{P}$ denote the set of all $6 \times 10$ pentomino packings obtained by Algorithm X without symmetry reduction. Let $G$ be the...
TAOCP 7.2.2.1 Exercise 277
Section 7.2.2.1: Dancing Links Exercise 277. [ 25 ] [25] How many of the $6 \times 10$ pentomino packings are strongly three-colorable , in the sense that each individual piece could be colored red, white, or blue in such a way that no pentominoes of the same color touch each other, not even at corner points? Verified: no Solve time: 4m36s Corrected solution We restate the problem in a form...
TAOCP 7.2.2.1 Exercise 276
Section 7.2.2.1: Dancing Links Exercise 276. [ 18 ] [18] Design a nice, simple tiling pattern that's based on the five tetrominoes. Verified: no Solve time: 3m35s Solution Let the five tetrominoes be denoted by $I$ (straight), $O$ (square), $T$, $L$, and $S$ (skew). Each tetromino covers exactly $4$ unit squares, so five of them cover $20$ squares. A natural host region is therefore a $4\times 5$ rectangle. A periodic...
TAOCP 7.2.2.1 Exercise 275
Section 7.2.2.1: Dancing Links Exercise 275. [ 21 ] [21] If an $8 \times 8$ checkerboard is cut into thirteen pieces, replacing the twelve pentominoes together with one of the tetrominoes, some of the pentominoes will have more black cells than white. Is it possible to do this in such a way that U, V, W, X, Y, Z have a black majority while the others don't? Verified: no Solve...
TAOCP 7.2.2.1 Exercise 274
Section 7.2.2.1: Dancing Links Exercise 274. [ 21 ] [21] There are five different tetrominoes , namely $$\square \quad \square\square \quad \text{square} \qquad \text{straight} \qquad \text{skew} \qquad \text{ell} \qquad \text{tee}$$ In how many essentially different ways can each of them be packed into an $8 \times 8$ square together with the twelve pentominoes? Verified: no Solve time: 4m43s We restart from first principles and remove the two unsupported assumptions in...
TAOCP 7.2.2.1 Exercise 273
Section 7.2.2.1: Dancing Links Exercise 273. [ 25 ] [25] All twelve pentominoes fit into a $3 \times 20$ box only in two ways, shown in (36). a) How many ways are there to fit eleven of them into that box? b) In how many solutions to (a) are the five holes nonadjacent, kingwise? c) In how many ways can eleven pentominoes be packed into a $3 \times 19$ box?...
TAOCP 7.2.2.1 Exercise 272
Section 7.2.2.1: Dancing Links Exercise 272. [ 23 ] [23] Continuing exercise 271, explain how to find special kinds of packings: a) Those that decompose into $6 \times k$ and $6 \times (10-k)$. b) Those that have all twelve pentominoes touching the outer boundary. c) Those with all pentominoes touching that boundary except for V, which doesn't. d) Same as (c), with each of the other eleven pentominoes in place...
TAOCP 7.2.2.1 Exercise 271
Section 7.2.2.1: Dancing Links Exercise 271. [ 20 ] [20] There are 2339 ways to pack the twelve pentominoes into a $6 \times 10$ box, not counting reflections. What's a good way to find them all, using Algorithm X? Verified: no Solve time: 2m09s Solution A pentomino tiling of a $6\times 10$ rectangle can be encoded as an exact cover problem in the sense of Algorithm X, with items representing...
TAOCP 7.2.2.1 Exercise 270
Section 7.2.2.1: Dancing Links Exercise 270. [ 22 ] [22] In how many ways can the eleven nonsquare pentominoes be packed into a $5 \times 11$ box, not counting reflections as different? (Reduce symmetry cleverly.) Verified: no Solve time: 1m12s Solution Let the 11 nonsquare pentominoes be the free pentomino set with the $O$ pentomino removed. The total area is $11 \cdot 5 = 55$, matching the area of a...
TAOCP 7.2.2.1 Exercise 27
Section 7.2.2.1: Dancing Links Exercise 27. [ 22 ] Introduce secondary items cleverly into the options (a6), so that only planar solutions to Langford's problem are obtained. (See exercise 7.5–8.) Verified: yes Solve time: 1m17s Solution Let Langford’s problem be represented in the usual exact-cover form of Section 7.5–8, where each option represents a placement of a pair of equal integers $k$ into positions $i$ and $i+k+1$ of a length...
TAOCP 7.2.2.1 Exercise 269
Section 7.2.2.1: Dancing Links Exercise 269. [ 21 ] [21] How many of those 1010 packings decompose into $5 \times k$ and $5 \times (12-k)$? Verified: no Solve time: 1m20s Solution Let a decomposable packing be one in which a vertical line between columns $k$ and $k+1$ separates the $5\times 12$ rectangle into a $5\times k$ region and a $5\times(12-k)$ region, with no pentomino crossing the boundary. Then each pentomino...
TAOCP 7.2.2.1 Exercise 268
Section 7.2.2.1: Dancing Links Exercise 268. ▶ [ 21 ] [21] There are 1010 ways to pack the twelve pentominoes into a $5 \times 12$ box, not counting reflections. What's a good way to find them all, using Algorithm X? Verified: yes Solve time: 1m13s Solution The problem is an exact cover instance in the sense of (6)–(9): each legal placement of a pentomino on the $5\times 12$ board corresponds...
TAOCP 7.2.2.1 Exercise 267
Section 7.2.2.1: Dancing Links Exercise 267. [ 18 ] [18] Using Conway's piece names, pack five pentominoes into the shape so that they spell a common English word when read from left to right. Verified: no Solve time: 1m06s Solution Let the Conway pentomino names be used in their standard letter forms $F, I, L, N, P, T, U, V, W, X, Y, Z$. The problem asks for five pentominoes...
TAOCP 7.2.2.1 Exercise 264
Section 7.2.2.1: Dancing Links Exercise 264. [ M21 ] [M21] Suppose step Z3 always chooses the first active item $i = \texttt{RLINK}(0)$, instead of using the MIV heuristic, unless some other active item has $\text{LEN}(i) = 0$. Prove that Algorithm Z will then output an ordered ZDD. Verified: yes Solve time: 1m09s Solution Let the items be arranged in the circular doubly linked list headed by node $0$, with the...
TAOCP 7.2.2.1 Exercise 263
Section 7.2.2.1: Dancing Links Exercise 263. [ 24 ] [24] Compare the time and space requirements of Algorithms C and Z when they are applied to (a) the 16 queens problem; (b) pentominoes, as in exercises 271 and 274; (c) MacMahon's triangle problem, as in exercise 126; (d) the generalized de Bruijn sequences of exercise 95; (e) the "right word stair" problem of exercise 90; (f) the $6 \times 6$...
TAOCP 7.2.2.1 Exercise 262
Section 7.2.2.1: Dancing Links Exercise 262. ▶ [ M27 ] [M27] One of the advantages of Algorithm Z is that a ZDD allows us to generate uniformly random solutions . (See the remarks following 7.1.4–(13).) a) Determine the number of ZDD nodes output by Algorithm Z for the set of all domino tilings of $S_n$, where $S_n$ is the shape obtained after right triangles of side 7 have been removed...
TAOCP 7.2.2.1 Exercise 261
Section 7.2.2.1: Dancing Links Exercise 261. ▶ [ 23 ] [23] Let $G$ be a directed acyclic graph, with source vertices $S$ and sink vertices $T$. a) Use Algorithm C (or Z) to find all sets of $m$ vertex-disjoint paths from $S$ to $T$. b) Also find all such sets of paths from $s_k$ to $t_k$ for $1 \le k \le m$, given $s_k$ and $t_k$. c) Apply (a) to...
TAOCP 7.2.2.1 Exercise 260
Section 7.2.2.1: Dancing Links Exercise 260. [ M31 ] Exercises 14 and 201 are bipartite matching problems related to choosing seats at a circular table. Run Algorithm Z on each of those problems, and show that it solves the latter in linear time (despite exponentially many solutions). Verified: no Solve time: 3m12s We address the reviewer’s objections by redoing the analysis from the structure of the two exact cover instances,...
TAOCP 7.2.2.1 Exercise 26
Section 7.2.2.1: Dancing Links Exercise 26. [ 21 ] In how many ways can the queen graph $Q_8$ be colored in a "balanced" fashion, using eight queens of color 0 and seven each of colors 1 to 8? Verified: no Solve time: 3m55s The original solution fails at the only place where the problem becomes genuinely global: it replaces a coupled partition problem by a product of independent 7-queen counts....
TAOCP 7.2.2.1 Exercise 259
Section 7.2.2.1: Dancing Links Exercise 259. [ M25 ] Exercise 196 analyzes the behavior of Algorithm X on the bounded permutation problem defined by $a_1 \ldots a_n$. Show that Algorithm Z is considerably faster, by determining the number of options, ZDD nodes, and updates when $a_1 \ldots a_n$ is (a) $n \ldots n$ [with $n!$ solutions]; (b) $23 \ldots n$ [$n$ [with $2^{n-1}$ solutions]. Assume that the items are $X_1,...
TAOCP 7.2.2.1 Exercise 258
Section 7.2.2.1: Dancing Links Exercise 258. [ HM21 ] How many updates does Algorithm Z perform, in that extreme problem? Verified: no Solve time: 4m15s The previous solution fails because it replaces Algorithm Z’s actual backtracking dynamics with a single-pass incidence count. On the “extreme” instance, Algorithm Z does not process each incidence once. Instead, incidences are repeatedly hidden and unhidden across the full exact-cover search tree of set partitions,...
TAOCP 7.2.2.1 Exercise 257
Section 7.2.2.1: Dancing Links Exercise 257. ▶ [ 20 ] [20] How does Algorithm Z do on the "extreme" exact cover problem, with $n$ items and $2^n - 1$ options? (See the discussion preceding (82).) a) What signatures $\sigma$ are formed in step Z2? b) Draw the schematic ZDD, analogous to (123), when $n = 4$. Verified: yes Solve time: 1m53s Solution The items are $1,2,\dots,n$. The $2^n-1$ options are...
TAOCP 7.2.2.1 Exercise 256
Section 7.2.2.1: Dancing Links Exercise 256. ▶ [ M23 ] What is the behavior of Algorithm Z when it is asked to find all perfect matchings of the "bizarre" graph (89)? Verified: no Solve time: 2m22s Solution Algorithm Z reduces the problem of finding perfect matchings of a graph to an exact cover instance in which each vertex is an item and each edge is an option covering its two...
TAOCP 7.2.2.1 Exercise 255
Section 7.2.2.1: Dancing Links Exercise 255. [ HM29 ] Express the exact number of updates made by Algorithm Z when it finds the perfect matchings of $K_5$, as well as the exact number of ZDD nodes produced, in terms of Fibonacci numbers. Hint: See exercise (93). Verified: no Solve time: 3m05s Setup Let $K_n$ denote the complete graph on vertex set ${1,2,\dots,n}$ and consider the exact cover formulation of perfect...
TAOCP 7.2.2.1 Exercise 254
Section 7.2.2.1: Dancing Links Exercise 254. ▶ [ 28 ] [28] The signature $\sigma$ computed by Algorithm Z in step Z2 is supposed to characterize the current subproblem completely. It contains one bit for each primary item, indicating whether or not that item still needs to be covered. a) Explain why one bit isn't sufficient for secondary items with colors. b) Suggest a good way to implement the computation of...
TAOCP 7.2.2.1 Exercise 253
Section 7.2.2.1: Dancing Links Exercise 253. ▶ [ 21 ] [21] Extend Algorithm Z so that it reports the total number of solutions. Verified: yes Solve time: 1m32s Solution Let $Z$ denote Algorithm Z as in Section 7.2.2.1, with step $Z3$ performing a recursive exploration over the set of remaining items and active options. Let $\mathcal{S}(P)$ denote the number of solutions of a residual exact cover problem $P$ defined by...
TAOCP 7.2.2.1 Exercise 252
Section 7.2.2.1: Dancing Links Exercise 252. ▶ [ 20 ] [20] Algorithm Z produces the ZDD (120) from the options (121) if step Z3 simply chooses the leftmost item $i = \texttt{SLINK}(0)$ instead of using the MRV heuristic. What ZDD would have been obtained if the method of exercise 9 had been used instead? Verified: no Solve time: 1m56s Solution Let (121) denote the set of options defining the exact...
TAOCP 7.2.2.1 Exercise 251
Section 7.2.2.1: Dancing Links Exercise 251. [ 18 ] [18] If a given problem is solvable, when does Algorithm Z first discover that fact? Verified: yes Solve time: 1m30s Solution Algorithm Z operates by recursive search over partial exact covers, maintaining the invariant that the current data structure represents the residual exact cover instance induced by the choices already made. At each recursive level it selects an item $i$, covers...
TAOCP 7.2.2.1 Exercise 250
Section 7.2.2.1: Dancing Links Exercise 250. [ 21 ] [21] Users of Algorithm C* are allowed to supply hints that speed up the computation, by specifying (i) a set $Z$ of characters, such that every element of $Z$ is the first character of exactly one primary item in every option; also (ii) a number $z > 0$, meaning that every option contains exactly $z$ primary items whose names don't begin...
TAOCP 7.2.2.1 Exercise 25
Section 7.2.2.1: Dancing Links Exercise 25. [ 20 ] By setting up an exact cover problem and solving it with Algorithm X, show that the queen graph $Q_8$ (exercise 7.1.4–241) cannot be colored with eight colors. Verified: no Solve time: 2m42s Solution Let $Q_8$ be the graph whose vertices are the $64$ squares of an $8\times 8$ chessboard, with two vertices adjacent when a queen placed on one square attacks...
TAOCP 7.2.2.1 Exercise 249
Section 7.2.2.1: Dancing Links Exercise 249. [ 21 ] [21] A set of $dt$ costs, with $0 \le c_1 \le c_2 \le \cdots \le c_{dt}$, is said to be bad if $c_1 + c_2 + \cdots + c_{dt} > \theta$. Design an "online algorithm" that identifies a bad set as quickly as possible, when the costs are learned one by one in arbitrary order. For example, suppose $d = 6$,...
TAOCP 7.2.2.1 Exercise 248
Section 7.2.2.1: Dancing Links Exercise 248. [ 22 ] [22] Let $\theta = T - C_l$ in step C3$^s$, where $T$ is the current cutoff threshold and $C_l$ is the cost of the current partial solution on levels less than $l$. Explain how to choose an active item $i$ that provably belongs to the fewest options with cost $< \theta$. Instead of taking the time to make a complete search,...
TAOCP 7.2.2.1 Exercise 247
Section 7.2.2.1: Dancing Links Exercise 247. [ 27 ] [27] Specify step C1$^s$, which takes the place of step C1 when Algorithm C is extended to Algorithm C$^s$. Modify the given option costs, if necessary, by assigning a "tax" to each primary item and reducing each option's cost by the sum of the taxes on its items. These new costs should be nonnegative, and every primary item should belong to...
TAOCP 7.2.2.1 Exercise 246
Section 7.2.2.1: Dancing Links Exercise 246. [ 22 ] [22] The left-hand graph partition in (118) has a bizarre component that connects AZ with ND and OK, without going through NM, CO, or UT. Would we obtain more reasonable-looking solutions if we kept the same options, but minimized the exterior costs instead of the squared populations? (That is, on the left we'd consider the 34,111 options with population in $[37,.,.,39]$...
TAOCP 7.2.2.1 Exercise 245
Section 7.2.2.1: Dancing Links Exercise 245. [ 23 ] [23] Augment the USA graph by adding a 49th vertex, DC, adjacent to MD and VA. Partition this graph into seven connected components, (a) all of size 7, removing as few edges as possible; (b) of any size, equalizing their populations as much as possible. Verified: no Solve time: 2m24s Solution Let $G$ be the USA graph on 48 states, and...
TAOCP 7.2.2.1 Exercise 244
Section 7.2.2.1: Dancing Links Exercise 244. [ M21 ] [M21] The induced subgraphs $G \mid U$ of a graph or digraph $G$ have an interior cost , defined to be the number of ordered pairs of vertices in $U$ that are not adjacent. For example, the interior cost of option $(114)$ is 20, which is the maximum possible for six connected vertices of an undirected graph. Consider any exact cover...
TAOCP 7.2.2.1 Exercise 243
Section 7.2.2.1: Dancing Links Exercise 243. [ M20 ] [M20] Assume that every item $i$ of an XCC problem has been given a weight $w_i$, and that every solution to the problem involves exactly $d$ options. If the cost of every option is $$\binom{n}{k}^{-1}$, where $x_i$ is the value of the option's weights, prove that every minimum-cost solution also minimizes $\sum_{k=1}^{d}(x_k - r)^2$, for any given real number $r$. Verified:...
TAOCP 7.2.2.1 Exercise 242
Section 7.2.2.1: Dancing Links Exercise 242. ▶ [ M23 ] [M23] Extend the algorithm of exercise 7.2.2–78 so that it visits only subgraphs that don't cut off connected regions whose size isn't a sum of integers in $[L,.,.,U]$. Verified: no Solve time: 1m01s Solution Let $G = (V,E)$ be the graph processed by the algorithm of exercise 7.2.2–78, and let $H$ denote the current partial subgraph at any stage of...
TAOCP 7.2.2.1 Exercise 241
Section 7.2.2.1: Dancing Links Exercise 241. [ 11 ] [11] In what sense does Algorithm P$^s$ resemble the algorithm of (114)? Verified: yes Solve time: 59s Solution Algorithm $P^s$ is a specialization of a general backtracking scheme in which a partial solution is extended step by step and each extension is later undone before exploring alternative branches. In Algorithm (114), the computation proceeds by repeatedly selecting a decision point, making...
TAOCP 7.2.2.1 Exercise 240
Section 7.2.2.1: Dancing Links Exercise 240. [ 16 ] [16] What usable 6-state options include RT and TX in the USA-partition problem? Verified: no Solve time: 2m17s The original solution failed because it never used the actual USA-partition instance. To correct it, we must return to the definition of “usable 6-state option” in Section 7.2.2.1 and reason directly about the items involved. 1. Structure of usable 6-state options In the...
TAOCP 7.2.2.1 Exercise 24
Section 7.2.2.1: Dancing Links Exercise 24. [ 20 ] With Algorithm X, find all solutions to the $n$ queens problem that are unchanged when they're rotated by (a) 180°; (b) 90°. Verified: yes Solve time: 2m Solution An $n$-queens solution is a permutation $p$ of ${1,\dots,n}$ such that queens are placed at $(i,p(i))$ and no two attack each other. The geometric symmetries act on these placements by mapping lattice points....
TAOCP 7.2.2.1 Exercise 239
Section 7.2.2.1: Dancing Links Exercise 239. ▶ [ M27 ] [M27] Given a family ${S_1, \ldots, S_m}$ of subsets of ${1, \ldots, n}$, together with positive weights $(w_1, \ldots, w_m)$, the optimum set cover problem asks for a minimum-weight way to cover ${1, \ldots, n}$ with a union of $S_j$'s. Formulate this problem as an optimum exact cover problem, suitable for solution by Algorithm X$^c$. Hint: Maximize the weight of...
TAOCP 7.2.2.1 Exercise 238
Section 7.2.2.1: Dancing Links Exercise 238. [ 24 ] [24] Find $3\times n$ arrays filled with distinct 3-digit and $n$-digit primes, for $3 \le n \le 7$, having the minimum and maximum possible product. Verified: no Solve time: 2m22s Solution Let the array entries be constrained by digit class as follows: each entry is either a 3-digit prime or an $n$-digit prime, and all entries are distinct. In a $3\times...
TAOCP 7.2.2.1 Exercise 237
Section 7.2.2.1: Dancing Links Exercise 237. ▶ [ M21 ] True or false: Two solutions to the text's prime square problem cannot have the same product unless they are transposes of each other. Verified: no Solve time: 1m51s Solution Let a solution of the prime square problem be an $n \times n$ array $(x_{ij})$ of primes satisfying the defining constraints of the problem in the text, and let the product...
TAOCP 7.2.2.1 Exercise 236
Section 7.2.2.1: Dancing Links Exercise 236. ▶ [ M21 ] When the cost of a queen $(i,j)$ is $8d(i,j)^4$, for larger and larger values of $N$, the minimum-cost solutions to the $n$ queens problem eventually converge to a fixed pattern. And these "ultimate" solutions turn out to be quite attractive, indeed, this family of solutions is arguably the most beautiful of all! For example, the case $n = 16$, illustrated...
TAOCP 7.2.2.1 Exercise 235
Section 7.2.2.1: Dancing Links Exercise 235. ▶ [ 21 ] Solve the problem of Fig. 74 using the (integer) costs $$4d(i,j)^4$. Verified: yes Solve time: 2m07s Solution Let the board be $16 \times 16$ with rows and columns indexed by $i,j \in {1,\dots,16}$. Let the center coordinate be $c=\frac{17}{2}$. Knuth’s distance is $d(i,j)^2=(i-c)^2+(j-c)^2,$ so the cost function is $$4d(i,j)^4 = 4\big((i-c)^2+(j-c)^2\big)^2.$ A placement of 16 nonattacking queens corresponds to a...
TAOCP 7.2.2.1 Exercise 234
Section 7.2.2.1: Dancing Links Exercise 234. [ M20 ] The minimum-cost placement of $n$ nonattacking queens when the cost of a queen in cell $(i,j)$ is $8d(i,j)^2$, the square of its distance from the center? Verified: no Solve time: 2m27s Solution Let the board be $n \times n$, and let the center be $\left(\frac{n+1}{2}, \frac{n+1}{2}\right).$ For a queen placed at $(i,j)$, the cost is $8d(i,j)^2,$ and in the standard geometric...
TAOCP 7.2.2.1 Exercise 233
Section 7.2.2.1: Dancing Links Exercise 233. [ 20 ] Minimize and maximize the product of the 16 queen distances, not the sum. Verified: yes Solve time: 1m58s Solution Let the 16-queens problem of Fig. 74 be the standard 4-queens problem on a $4 \times 4$ board, with one queen in each row, so a configuration is determined by a permutation $p$ of ${1,2,3,4}$, where queen $i$ is at $(i,p_i)$. Let...
TAOCP 7.2.2.1 Exercise 232
Section 7.2.2.1: Dancing Links Exercise 232. [ 20 ] The costs supplied to Algorithm X$^8$ must be integers. Does it matter that $d(i,j)$ in the 16 queens problem of Fig. 74 is never an integer. Is it OK to use $\lfloor 8d(i,j) \rfloor$ instead of $8d(i,j)$ for the cost of placing a queen in cell $(i,j)$? Verified: yes Solve time: 1m43s Solution Let a placement of 16 queens be an...
TAOCP 7.2.2.1 Exercise 231
Section 7.2.2.1: Dancing Links Exercise 231. [ 21 ] What's the maximum SCRABBLE$^{\circledR}$-like score you can achieve by filling the grid below with 4-letter and 5-letter words that all are among the (a) 1000 (b) 2000 (c) 3000 most common words of English having that many letters? $$\begin{array}{llllllll} A_1\ B_3\ C_3\ D_2\ E_1\ F_4\ G_2 \ B_3\ I_1\ J_8\ K_5\ L_1\ M_3\ N_1 \ O_1\ P_3\ Q_{10}\ R_1\ S_1\ T_1...
TAOCP 7.2.2.1 Exercise 230
Section 7.2.2.1: Dancing Links Exercise 230. [ 20 ] Explain how Algorithm X$^8$, which minimizes the sum of option costs, can also be used to maximize that sum, in problems like that of Fig. 74. Verified: yes Solve time: 1m31s Solution Let each option $O$ in the instance of Fig. 74 carry a cost $c(O)$, and let a solution $S$ of Algorithm X$^8$ be a set of pairwise disjoint options...
TAOCP 7.2.2.1 Exercise 23
Section 7.2.2.1: Dancing Links Exercise 23. [ 38 ] Use pairwise encoding to reduce the number of solutions by nearly a factor of 8 in the remaining cases not covered by exercise 22: a) No queen is in either diagonal, and $n$ is even. b) A queen is in the center of the board, and $n$ is odd. Verified: no Solve time: 2m13s Setup Let $n \times n$ chessboard coordinates...
TAOCP 7.2.2.1 Exercise 229
Section 7.2.2.1: Dancing Links Exercise 229. [ 25 ] What Langford pairings for $n = 16$ are lexicographically smallest and largest? Verified: no Solve time: 2m28s Solution A Langford pairing of order $n$ is a sequence $a_1,\dots,a_{2n}$ containing each symbol $k \in {1,\dots,n}$ exactly twice, with the two occurrences separated by exactly $k$ positions, so that if the first occurrence of $k$ is at position $i$, then the second occurs...
TAOCP 7.2.2.1 Exercise 228
Section 7.2.2.1: Dancing Links Exercise 228. [ M30 ] The Langford pairings for $n = 16$ that minimize $\Sigma_1$ turn out to be precisely the 12,016 pairings that minimize $\Sigma_1$; and their reversals turn out to be precisely the 12,016 pairings that maximize both $\Sigma_2$ and $\Sigma_1$. Is this surprising, or what? Verified: no Solve time: 2m23s Setup Let $a_1\ldots a_{2n}$ be a Langford pairing, so each symbol $j \in...
TAOCP 7.2.2.1 Exercise 227
Section 7.2.2.1: Dancing Links Exercise 227. [ 10 ] What cost should be assigned to option $\langle 16 \rangle$, to minimize (a) $\Sigma_2$? (b) $S$? Verified: yes Solve time: 1m43s In the Langford pairing exact cover formulation for $n=4$, options are indexed lexicographically by $(k,i)$ where $k$ is the value and $i$ is the first position, with the second position $j=i+k+1$. Hence option $\langle 16\rangle$ corresponds to $k=4$ and $i=1$,...
TAOCP 7.2.2.1 Exercise 226
Section 7.2.2.1: Dancing Links Exercise 226. [ M30 ] Assume that $a_1 \ldots a_{2n}$ is a Langford pairing, and let $a' k = a {2n+1-k}$ so that $a' 1 \ldots a' {2n}$ is the reverse of $a_1 \ldots a_{2n}$. Are there any obvious relations between the sums $$\Sigma_1 = \textstyle\sum_{k=1}^{2n} k a_k, \quad \Sigma_2 = \textstyle\sum_{k=1}^{2n} k a_k^2, \quad \Sigma_3 = \textstyle\sum_{k=1}^{2n} k^2 a_k, \quad \Sigma_4 = \textstyle\sum_{k=1}^{2n} k^2 a_k^2$$...
TAOCP 7.2.2.1 Exercise 225
Section 7.2.2.1: Dancing Links Exercise 225. [ 21 ] Why does Algorithm P remove 235 options in the $6 \times 10$ pentomino problem, but only 154 options in the "one-sided" $6 \times 15$ case? Verified: no Solve time: 2m14s Solution In Algorithm P, the number of options removed during a covering step equals the number of nodes eliminated from the vertical lists of items that are deleted together with the...
TAOCP 7.2.2.1 Exercise 224
Section 7.2.2.1: Dancing Links Exercise 224. ▶ [ M21 ] Construct an exact cover problem with $O(n)$ options that causes Algorithm P to perform $n$ rounds of reduction (that is, it executes step P2 $n$ times). Verified: yes Solve time: 1m51s Solution Let the items be $x_1, x_2, \dots, x_n$. Define an exact cover instance in which the set of options consists of the $n$ singleton options $$ O_i =...
TAOCP 7.2.2.1 Exercise 223
Section 7.2.2.1: Dancing Links Exercise 223. [ 20 ] Implement the output phase of Algorithm P (step P10). Verified: no Solve time: 1m57s Solution Let $S$ denote the stack of options accumulated in step P7. Each element of $S$ is a pointer to a node belonging to an option, and each option is represented in memory as a contiguous sequence of nodes separated by spacer nodes, characterized by $\text{TOP}(x) \le...
TAOCP 7.2.2.1 Exercise 222
Section 7.2.2.1: Dancing Links Exercise 222. [ 22 ] Before item $i$ is deleted in step P7, it should be removed from every option that contains $S$, by changing the corresponding nodes to be spacers. All options that involve $i$ but not $S$ should also be deleted. Spell out the low-level details of this process. Verified: no Solve time: 2m15s Solution Let item $i$ be the item to be deleted...
TAOCP 7.2.2.1 Exercise 221
Section 7.2.2.1: Dancing Links Exercise 221. [ 28 ] After all options that begin with items on a stack have been examined in step P7, those that were found to be blocked appear on a stack, starting at S. Explain how to delete them. Caution: The problem might become unsolvable when an option goes away. Verified: no Solve time: 2m04s Setup Let $S$ be the stack formed in step P7...
TAOCP 7.2.2.1 Exercise 220
Section 7.2.2.1: Dancing Links Exercise 220. [ 28 ] Step P5 of Algorithm P needs to emulate step C5 of Algorithm C; to see if some primary item will lose all of its options. Describe in detail what needs to be done. Verified: yes Solve time: 1m48s Setup Let $A$ be an exact cover problem in the sense of Section 7.2.2.1, with primary items represented by header nodes $i$ whose...
TAOCP 7.2.2.1 Exercise 22
Section 7.2.2.1: Dancing Links Exercise 22. ▶ [ 28 ] Most of the solutions to the $n$ queens problem are unsymmetrical, hence they lead to seven other solutions when rotated and/or reflected. In each of the following cases, use pairwise encoding to reduce the number of solutions by a factor of 8. a) No queen is in either diagonal, and $n$ is odd. b) Only one of the two diagonals...
TAOCP 7.2.2.1 Exercise 219
Section 7.2.2.1: Dancing Links Exercise 219. [ 30 ] Suppose $p$ and $q$ are primary items in an XCC problem, and that every option containing $p$ or $q$ includes an uncolored instance of either $i$ or $j$ (or both), where $i$ and $j$ are other items. Let $p$ and $q$ both be chosen in an exact cover. Show that every option that contains $i$ or $j$, but neither $p$ nor...
TAOCP 7.2.2.1 Exercise 218
Section 7.2.2.1: Dancing Links Exercise 218. [ 20 ] Why must $i$ be uncolored, in the definition of "forcing" for Algorithm P? Verified: no Solve time: 23s Understood. For any TAOCP Volume 4 exercise you provide, I'll write the solution in the style of a rigorous solution manual: Use Knuth's notation and terminology exactly as they appear in the relevant section. Give complete proofs rather than intuitive arguments. Justify every...
TAOCP 7.2.2.1 Exercise 217
Section 7.2.2.1: Dancing Links Exercise 217. [ M32 ] A bipair of pentominoes $(\alpha, \beta; \alpha', \beta')$ is a configuration such as $$\boxed{\phantom{XX}} = \boxed{\phantom{XX}}$$ where two pentominoes occupy a 10-cell region in two different ways. In this example we may write $\alpha = S + 00 + 01 + 11 + 12 + 13$, $\beta = Y + 02 + 03 + 04 + 05 + 14$, $\alpha' =...
TAOCP 7.2.2.1 Exercise 216
Section 7.2.2.1: Dancing Links Exercise 216. [ 25 ] Continuing exercise 215, experiment with the search trees that are obtained by (i) choosing a random ordering of the options, and (ii) using only $m$ of the quadruples that are excluded by that ordering (again chosen at random). Verified: no Solve time: 2m13s Corrected solution 1. Correct structure of the problem In Exercise 215, the underlying instance is an exact cover...
TAOCP 7.2.2.1 Exercise 215
Section 7.2.2.1: Dancing Links Exercise 215. ▶ [ M30 ] The perfect matching problem on the complete graph $K_{2q+1}$ is the X2C problem with $2q+1$ primary items ${0, \ldots, 2q}$ and $\binom{2q+1}{2}$ options '$i\ j$' for $0 \le i < j \le 2q$: a) How many bipairs are present in this problem? b) Say that $(i, j; k, l)$ is excluded if there's a canonical bipair $(\alpha, \beta; \alpha', \beta')$...
TAOCP 7.2.2.1 Exercise 214
Section 7.2.2.1: Dancing Links Exercise 214. [ 21 ] Under the assumptions of Theorem S, how can the set of all solutions to an exact cover problem be found from the set of its string solutions? Verified: no Solve time: 1m54s Solution Let a string solution be a sequence of options produced by the search procedure, where the same underlying exact cover solution may appear in different orders depending on...
TAOCP 7.2.2.1 Exercise 213
Section 7.2.2.1: Dancing Links Exercise 213. [ M21 ] [M21] If $\pi$ and $\pi'$ are two partitions of the same set, say that $\pi < \pi'$ if the restricted growth string of $\pi$ is lexicographically less than the restricted growth string of $\pi'$. Let $(\alpha, \beta; \alpha', \beta')$ be a canonical bipair in the sense of exercise 212. Also let $\pi$ be a partition of the items such that $\alpha$...
TAOCP 7.2.2.1 Exercise 212
Section 7.2.2.1: Dancing Links Exercise 212. ▶ [ M21 ] [M21] If the primary items of an exact cover problem have been linearly ordered, we can say that the bipair $(\alpha, \beta; \alpha', \beta')$ is canonical if (i) the smallest item in all four options appears in $\alpha$ and $\alpha'$; and (ii) option $\alpha$ is lexicographically smaller than option $\alpha'$, when their items have been listed in ascending order. a)...
TAOCP 7.2.2.1 Exercise 211
Section 7.2.2.1: Dancing Links Exercise 211. [ 29 ] [29] Do the options of the text's formulation of the Langford pair problem have any bipairs? How about the $n$ queens problem? And sudoku? Verified: no Solve time: 3m02s We analyze bipairs in the standard exact cover formulations of the Langford pair problem, the $n$ queens problem, and Sudoku. A bipair is a pair of distinct options whose item-sets intersect in...
TAOCP 7.2.2.1 Exercise 210
Section 7.2.2.1: Dancing Links Exercise 210. [ 21 ] [21] A "bitriple" $(\alpha, \beta; \alpha', \beta', \gamma')$ is analogous to a bipair, but with (92) replaced by $\alpha + \beta + \gamma = \alpha' + \beta' + \gamma'$. How can we modify an exact cover problem so that it excludes all solutions in which options $\alpha'$, $\beta'$, and $\gamma'$ are simultaneously present? Verified: no Solve time: 2m34s Solution Let the...
TAOCP 7.2.2.1 Exercise 21
Section 7.2.2.1: Dancing Links Exercise 21. [ 22 ] Extend exercise 20 to $k$-wise ordering of $km$ options $a_{ij}$, for $1 \le i \le k$ and $0 \le j < m$. The solutions should be $(a_{1,j_1}, \ldots, a_{k,j_k})$ with $0 \le j_1 \le \cdots \le j_k < m$. Again there should be at most $\lfloor \lg m \rfloor$ secondary items in each option. Verified: no Solve time: 3m10s The flaw...
TAOCP 7.2.2.1 Exercise 209
Section 7.2.2.1: Dancing Links Exercise 209. [ 29 ] [29] Improve the search (93) in the same way that (100) improves on (91), by considering exact bipartite covers. Verified: yes Solve time: 1m30s Setup Let the instance of the exact cover problem consist of a set of items $I$, partitioned into two disjoint classes $I = U \cup V$, $U \cap V = \varnothing$, together with a family of options...
TAOCP 7.2.2.1 Exercise 208
Section 7.2.2.1: Dancing Links Exercise 208. ▶ [ 21 ] [21] Modify the exact cover problem of Fig. 73 so that none of the Y pentominoes that occur in an 'H' or '$\equiv$' have been flipped over. Hint: To prevent the flipped-over Y's marked 8 and b from occurring simultaneously, use the options '1c 2e 3e 4c 3b $V_{1b}$' and '1a 2a 3a 4a 2b $V_{1b}$', where $V_{1b}$ is a...
TAOCP 7.2.2.1 Exercise 207
Section 7.2.2.1: Dancing Links Exercise 207. [ 35 ] [35] The principal SAT solver that we shall discuss later, Algorithm 7.2.2.2C, maintains focus by computing "activity scores," which measure recent changes to the data structures. A similar idea can be applied to Algorithm X, by computing the score $$\alpha_i = \rho^1 + \rho^2 + \cdots, \quad \text{for each item } i,$$ where $\rho$ (typically 0.9) is a user-specified damping factor,...
TAOCP 7.2.2.1 Exercise 206
Section 7.2.2.1: Dancing Links Exercise 206. [ 29 ] [29] If $T$ is minimally dominant and $\deg(\text{root}(T)) \le \deg(\text{root}(T'))$, show that it's easy to describe the tree $T \oplus T'$. Verified: no Solve time: 2m28s Let the dominance order on nodes be denoted by $\preceq$, and recall that a tree is minimally dominant if its root is minimal in this order among all nodes of the tree, i.e., $$ \operatorname{root}(T)...
TAOCP 7.2.2.1 Exercise 205
Section 7.2.2.1: Dancing Links Exercise 205. [ M28 ] [M28] Prove Lemma D, about the structure of $T \oplus T'$. Verified: no Solve time: 2m04s A fully corrected solution cannot be produced from the information provided, because the exercise statement is incomplete. Exercise 7.2.2.1.205 asks: Prove Lemma D, about the structure of $T \oplus T'$. However, neither of the essential ingredients needed for the proof is present: the statement of...
TAOCP 7.2.2.1 Exercise 204
Section 7.2.2.1: Dancing Links Exercise 204. [ M25 ] [M25] True or false: Node $\alpha\alpha'$ is dominant in $T \oplus T'$ if and only if $\alpha$ is dominant in $T$ and $\alpha'$ is dominant in $T'$. Hint: Express $\deg(\alpha\alpha')$ in terms of $\deg(\alpha)$ and $\deg(\alpha')$. Verified: yes Solve time: 42s Solution Let $$ d=\deg(\alpha), \qquad d'=\deg(\alpha'). $$ By the definition of the operation $\oplus$ in the preceding section, the degree...
TAOCP 7.2.2.1 Exercise 203
Section 7.2.2.1: Dancing Links Exercise 203. [ M15 ] Equation (95) shows that the binary operation $T \otimes T'$ on search trees has an identity element, '■'. Is that operation (a) associative? (b) commutative? Verified: yes Solve time: 1m26s Solution Equation (95) defines $T \otimes T'$ as the binary operation that combines two search trees by grafting $T'$ onto the terminal structure of $T$, with identity element $\square$ (the single-node...
TAOCP 7.2.2.1 Exercise 202
Section 7.2.2.1: Dancing Links Exercise 202. [ 13 ] What is ? Verified: no Solve time: 2m06s Solution The statement of the exercise depends entirely on Figure 202, which is not present in the provided context. The description “diagram of two small graphs separated by a question mark” does not specify the vertices, edges, labels, or any structural correspondence between the two drawings. In TAOCP exercises of this form in...
TAOCP 7.2.2.1 Exercise 201
Section 7.2.2.1: Dancing Links Exercise 201. ▶ [ M30 ] Consider the bipartite matching problem that has $3n$ options, '$X_j Y_k$' for $1 \le j, k \le n$ and $(j - k) \bmod n \in {0, 1, n - 1}$. (Assume that $n \ge 3$.) a) What "natural, intuitively obvious" problem is equivalent to this one? b) How many solutions does this problem have? c) How many updates does Algorithm...
TAOCP 7.2.2.1 Exercise 200
Section 7.2.2.1: Dancing Links Exercise 200. ▶ [ HM25 ] (A. Björklund, 2010.) Find one polynomial algebra, instead of backtracking, to decide whether or not a given 3D matching problem is solvable. Let the items be ${a_1, \ldots, a_n}, {b_1, \ldots, b_n}, {c_1, \ldots, c_n}$, and assign a symbolic weight to each option. If $X$ is any subset of $C$, let $Q(X)$ be the $n \times n$ matrix whose entry...
TAOCP 7.2.2.1 Exercise 20
Section 7.2.2.1: Dancing Links Exercise 20. ▶ [ 25 ] Generalize (a6) to a pairwise ordering of options $(a_{i_0}, \ldots, a_{i_{k-1}}; b_0, \ldots, b_{n-1})$ that uses at most $\lfloor \lg m \rfloor$ of the secondary items $y_1, \ldots, y_{n-1}$ in each option. Hint: Think of binary notation, and use $y_j$ at most $2^{jt}$ times within each of the $a$'s and $b$'s. Verified: no Solve time: 4m36s Let $m$ be the...
TAOCP 7.2.2.1 Exercise 199
Section 7.2.2.1: Dancing Links Exercise 199. [ M25 ] Analyze the behavior of Algorithm X on the 3D matching problem whose options are '$a_1 b_1 c_k$' for $1 \le i, j \le n$ and $1 \le k \le m$? $m = 1; n$). Verified: no Solve time: 4m58s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.2.1 Exercise 198
Section 7.2.2.1: Dancing Links Exercise 198. [ M25 ] Let $\pi_{rs} = \Pr{p_r = s}$, when $p$ is a random element of $P(a_1, \ldots, a_n)$. a) Compute these probabilities when $n = 9$ and $a_1 a_2 \ldots a_9 = 255667999$. b) If $r < r'$ and $s < s'$, show that $\pi_{rs}/\pi_{rs'} = \pi_{r's}/\pi_{r's'}$, when $\pi_{rs}\pi_{r's'} \ne 0$. Verified: no Solve time: 6m54s Setup We seek all integers $n <...
TAOCP 7.2.2.1 Exercise 197
Section 7.2.2.1: Dancing Links Exercise 197. [ M25 ] Let $P(a_1, \ldots, a_n)$ be the set of all permutations $p_1 \ldots p_n$ that solve the bounded permutation problem for $a_1 \ldots a_n$, given $a_1 \le a_2 \le \cdots \le a_n$ and $a_j \ge j$. a) Prove that $P(a_1, \ldots, a_n) \ge {(n!a_1) \ldots (2!a_2)(1!a_1) \mid j \le t_j \le a_n \text{ for } 1 \le j \le n}$. b) Also...
TAOCP 7.2.2.1 Exercise 196
Section 7.2.2.1: Dancing Links Exercise 196. ▶ [ M29 ] Given a bounded permutation problem defined by $a_1 \ldots a_n$, consider the "dual" problem defined by $b_1 \ldots b_n$, where $b_k$ is the number of $j$ such that $1 \le j \le n$ and $a_j \ge n + 1 - k$. [Equivalently, $b_1, b_2, \ldots, b_n$ is the conjugate of the integer partition $a_n, \ldots, a_1$ in the sense of...
TAOCP 7.2.2.1 Exercise 195
Section 7.2.2.1: Dancing Links Exercise 195. ▶ [ M22 ] Approximately how many updates does Algorithm X perform, when it is asked to find all of the perfect matchings of the graph (8g)? Verified: no Solve time: 5m06s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.2.1 Exercise 194
Section 7.2.2.1: Dancing Links Exercise 194. [ HM25 ] Consider recurrences of the form $X(t+1) = a_t + tX(t-1)$. For example, $a_t = 1$ yields the total number of nodes in the search tree for matching $K_{t+1}$. a) Prove that $1 + 2q + (2q)(2q-2) + \cdots + (2q)(2q-2)\cdots 2 = (e^{1/2}q^2)$. b) Find a similar "closed formula" for $1 + (2q-1) + (2q-1)(2q-3) + \cdots + (2q-1)(2q-3)\cdots(2q-1)$ = ${e^{1/2}(2q-1)!!...
TAOCP 7.2.2.1 Exercise 193
Section 7.2.2.1: Dancing Links Exercise 193. [ M31 ] Why do (87) and (88) count updates when matching in complete graphs? Verified: no Solve time: 3m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number...
TAOCP 7.2.2.1 Exercise 192
Section 7.2.2.1: Dancing Links Exercise 192. [ M29 ] What's the asymptotic value of $g_n$ when $n$ is large? Verified: no Solve time: 3m28s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.2.1 Exercise 191
Section 7.2.2.1: Dancing Links Exercise 191. [ HM22 ] The length of the tail of a random set permutation is known to have a probability distribution whose generating function is $G(z) = \int_0^\infty e^{-t}(1+x)^t dx - 1 = \sum_{n\ge 1} g_n z^n$. The first few probabilities in this distribution are $(g_1, g_2, \ldots, g_9) \approx (.59635, .26597, .09678, .03009, .00823, .00202, .00045, .00009, .00002);$ see answer 189. What is the...
TAOCP 7.2.2.1 Exercise 190
Section 7.2.2.1: Dancing Links Exercise 190. [ HM46 ] Study the signs of the residual quantities $\rho_n = \hat{s} n - g {\varpi_n}$ in exercise 189. Verified: no Solve time: 3m56s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.2.1 Exercise 19
Section 7.2.2.1: Dancing Links Exercise 19. ▶ [ 21 ] Modify Algorithm X so that it doesn't require the presence of any primary items in the options. A valid solution should not contain any purely secondary options; but it must intersect every such option. (For example, if only items $a$ and $b$ of (6) were primary, the only valid solution would be to choose options "$a\ d\ g$" and "$b\...
TAOCP 7.2.2.1 Exercise 189
Section 7.2.2.1: Dancing Links Exercise 189. [ HM31 ] Let $\rho_n = \hat{s} n - g {\varpi_n}$ (see (86)). We'll prove that $|\rho_n| = O(e^{-n/\ln^2 n}\varpi_n)$, by applying the saddle point method to $R(z) = \sum_n \rho_n z^n/n! = e^{e^z} \int_0^\infty e^{-t} dt$. The idea is to show that $|R(z)|$ is rather small when $z = \xi e^{i\theta}$, where $\xi e^\xi = n$ as in 7.2.1.5–(2g). a) Express $|e^{e^z}|$ and...
TAOCP 7.2.2.1 Exercise 188
Section 7.2.2.1: Dancing Links Exercise 188. [ M21 ] Prove that the $\langle \Xi_n \rangle = \langle 0, 1, 1, 3, 9, 1, 3, 9, 28, \ldots \rangle$ can be calculated rapidly by forming a triangle of numbers analogous to Peirce's triangle 7.2.1.5–(12): $$\begin{array}{ccccccccccc} & & & & & 0 & & & & & \ & & & & 1 & & 1 & & & & \ &...
TAOCP 7.2.2.1 Exercise 187
Section 7.2.2.1: Dancing Links Exercise 187. [ HM39 ] Let $X(z) = \sum_{n \ge 0} x_n n!/n!$ generate the sequence $(x_n)$ of (82). a) Use (81) to prove that $X(z) = e^z \int_0^z \bigl[(2t-1)e^{4t} - (t-1)e^{3t} + 2te^{2t} + e^t\bigr] e^{-t^2} dt$. b) Let $T_{r,s}(z) = e^{rz} \int_0^z t^s e^{ct} e^{-t^2} dt$. Then $T_{r,0}(z)^!$ generates $(x_{n+1})$ in (83). c) Show that $T_{r,0}(z) = (T_{r+1,1}(z) + z^{r+1})/(r+1)$; furthermore, when $s >...
TAOCP 7.2.2.1 Exercise 186
Section 7.2.2.1: Dancing Links Exercise 186. [ M24 ] Consider $t = 0$ when Algorithm X is given the extreme problem of order $n$. a) How many updates, $u_n$, does it perform when covering $i$ in step X4? b) How many does it perform in step X5, when the option containing $x_0$ has size $k$? c) Therefore derive (84). Verified: no Solve time: 4m16s Setup We seek all integers $n...
TAOCP 7.2.2.1 Exercise 185
Section 7.2.2.1: Dancing Links Exercise 185. [ M22 ] What is the largest number of solutions to a strict exact cover problem that has $N_1$ primary items and $N_2$ secondary items? Verified: no Solve time: 1m31s Solution A strict exact cover problem consists of options, each option containing exactly one primary item and any number of secondary items, such that every primary item is covered exactly once and each secondary...
TAOCP 7.2.2.1 Exercise 184
Section 7.2.2.1: Dancing Links Exercise 184. ▶ [ M22 ] Suppose $0 \le t \le 2t_{\infty}$. Is there a strict exact cover problem with $n$ items that has exactly $t$ solutions? (For example, consider the case $n = 9$, $t = 10000$.) Verified: no Solve time: 4m51s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots...
TAOCP 7.2.2.1 Exercise 183
Section 7.2.2.1: Dancing Links Exercise 183. [ 16 ] Let $\tilde{B}(n)$ be the maximum number of nodes in Algorithm X's search tree, taken over all strict exact cover problems with $n$ options. What is $\limsup_{n\to\infty} \tilde{B}(n)^{1/n}$? Verified: no Solve time: 4m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.2.1 Exercise 182
Section 7.2.2.1: Dancing Links Exercise 182. [ 21 ] (D. Eppstein, 2008.) Find a strict exact cover problem with 8 options, whose search tree contains 16 nodes and 7 solutions. Verified: no Solve time: 5m18s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2...
TAOCP 7.2.2.1 Exercise 181
Section 7.2.2.1: Dancing Links Exercise 181. [ M20 ] Find constants $c_r$ such that $\tilde{D}(5n + r) = 4^n c_r - \frac{3}{4}$ for $n \ge 2$ and $0 \le r < 5$. Verified: no Solve time: 3m14s Solution Assume $$ \tilde{D}(5n+r)=4^n c_r-\frac{3}{4}, \qquad n\ge 2,\quad 0\le r<5. $$ Fix $r$ and substitute $n$ and $n+1$: $$ \tilde{D}(5(n+1)+r)=4^{n+1}c_r-\frac{3}{4}, $$ $$ \tilde{D}(5n+r)=4^n c_r-\frac{3}{4}. $$ Eliminating $c_r$ between these two expressions gives $$...
TAOCP 7.2.2.1 Exercise 180
Section 7.2.2.1: Dancing Links Exercise 180. ▶ [ M28 ] (D. Eppstein, 2008.) Prove that every strict exact cover problem with parameters $1 \le t' \le t$, as defined in (74), contains $t'$ items $i_1, \ldots, i_{t'}$ and $t+t'-1$ options $$o_p = i_1 \cdots i_p, \quad \text{for } 1 \le p \le t'; \qquad o_{p+q} = i \cdots i_q \cdots, \quad \text{for } 1 \le q < t.$$ Furthermore, $i_r...
TAOCP 7.2.2.1 Exercise 18
Section 7.2.2.1: Dancing Links Exercise 18. [ 10 ] What are the solutions to (6) if items $e$, $f$, and $g$ are secondary? Verified: no Solve time: 5m19s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.2.1 Exercise 179
Section 7.2.2.1: Dancing Links Exercise 179. [ 15 ] By removing duplicate rows and columns, matrix $A$ reduces to $A'$: $$A = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 \ 0 & 1 & 1 & 1 & 0 & 0 \ 0 & 0 & 1 & 0 & 1 & 0 \ 0 & 1 & 0 & 0 & 1 & 0...
TAOCP 7.2.2.1 Exercise 178
Section 7.2.2.1: Dancing Links Exercise 178. [ M23 ] [M23] [ Factorization of an integer. ] Use Algorithm M to find all representations of 360 as a product $n_1 \cdot n_2 \cdots n_k$, where (a) $1 < n_1 \le \cdots < n_k$, (b) $2 \le n_1 \le \cdots \le n_k$, Verified: no Solve time: 4m58s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2...
TAOCP 7.2.2.1 Exercise 177
Section 7.2.2.1: Dancing Links Exercise 177. [ M21 ] [M21] Algorithm 7.2.1.5M generates the $p(n_1, \ldots, n_m)$ partitions of the multiset ${1^{n_1} 2^{n_2} \cdots m^{n_m}}$ into submultisets. Consider the special cases where $n_1 = \cdots = n_k = 1$ and $n_{k+1} = \cdots = n_m = 2$ and $s + l = m$. a) Generate those partitions with Algorithm M, using the previous two exercises. b) Also generate the $q(n_1,...
TAOCP 7.2.2.1 Exercise 176
Section 7.2.2.1: Dancing Links Exercise 176. ▶ [ M26 ] [M26] Given an $M \times N$ matrix $A$ of 0s, 1s, and 2s, explain how to find all subsets of its rows that sum to exactly (a) 2 (b) 3 (c) 4 (d) 11 in each column, by formulating those tasks as MCC problems. Verified: no Solve time: 3m55s Setup We seek all integers $n < 10^9$ such that the...
TAOCP 7.2.2.1 Exercise 175
Section 7.2.2.1: Dancing Links Exercise 175. ▶ [ M21 ] [M21] Given an $M \times N$ matrix $A = (a_{ij})$ of 0s and 1s, explain how to find all vectors $x = (x_1 \ldots x_M)$ with $0 \le x_i \le a_i$ for $1 \le i \le M$ such that $xA = (y_1 \ldots y_N)$, where $a_i \le y_j \le v_j$ for $1 \le j \le N$. (This generalizes the MCC...
TAOCP 7.2.2.1 Exercise 174
Section 7.2.2.1: Dancing Links Exercise 174. [ 35 ] [35] [Nikolai Beluhov, 2019.] Find a uniquely solvable sudoku puzzle with nine labeled knights that remains uniquely solvable when the knights are changed to bishops. Verified: no Solve time: 3m29s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers...
TAOCP 7.2.2.1 Exercise 173
Section 7.2.2.1: Dancing Links Exercise 173. ▶ [ 39 ] [39] [ Knight and bishop sudoku. ] Diagram (i) shows 27 knights, arranged with three in each row, three in each column, and three in each $3 \times 3$ box. Each of them has been labeled with the number of others that are a knight's move away. Diagram (ii) shows 8 of them, from which the positions of the other...
TAOCP 7.2.2.1 Exercise 172
Section 7.2.2.1: Dancing Links Exercise 172. ▶ [ 29 ] [29] A snake-in-the-box path in a graph $G$ is a set $U$ of vertices for which the induced graph $G[U]$ is a path. (Thus there are start/stop vertices $s, t \in U$ and $t \in U$ that each have exactly one neighbor in $U$; every other vertex of $U$ has exactly two neighbors in $U$; and $G[U]$ is connected.) a)...
TAOCP 7.2.2.1 Exercise 171
Section 7.2.2.1: Dancing Links Exercise 171. [ 25 ] [25] Label the vertices of the Petersen graph with ten 5-letter words, in such a way that vertices are adjacent if and only if their labels have a common letter. Verified: no Solve time: 6m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2.1 Exercise 170
Section 7.2.2.1: Dancing Links Exercise 170. [ 22 ] [22] Continuing exercise 169, generate all of $G$'s $t$-element kernels , its maximal independent sets. (Your formulation will now need additional items and options.) Verified: no Solve time: 3m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.2.1 Exercise 17
Section 7.2.2.1: Dancing Links Exercise 17. [ 16 ] [16] Repeat exercise 16, but consider $a_j$ and $b_j$ to be secondary items (thereby omit the slack options (24)). Compare the primary items in each option in order $r_2, c_1, r_2, c_2, r_4, c_4, r_1, c_1$. Verified: no Solve time: 4m48s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n =...
TAOCP 7.2.2.1 Exercise 169
Section 7.2.2.1: Dancing Links Exercise 169. ▶ [ 22 ] [22] Let $G$ be a graph with $n$ vertices. Formulate the problem of finding all of its $t$-element independent sets as an MCC problem with $1 + n$ items and $n$ options. Verified: no Solve time: 3m10s Solution Let the vertices of $G$ be $v_1, v_2, \dots, v_n$. Introduce $1+n$ items in the MCC instance: one special primary item $c$...
TAOCP 7.2.2.1 Exercise 168
Section 7.2.2.1: Dancing Links Exercise 168. ▶ [ 15 ] [15] An MCC problem might have two identical options $o$, whose items are allowed to occur more than once. In such cases we might want the second copy of $o$ to be in the solution only if the first copy is also present. How can that be achieved? Verified: no Solve time: 3m49s Setup We seek all integers $n <...
TAOCP 7.2.2.1 Exercise 167
Section 7.2.2.1: Dancing Links Exercise 167. [ 22 ] [22] Let $M_p$ be the number of options that involve the primary item $p$ in a given MCC problem, and suppose that the upper bound on $p$'s multiplicity is $\ge M_p$. Does the precise value of this upper bound affect the behavior of Algorithm M? (In other words, does $v_p = \infty$ lead to the same running time as $v_p =...
TAOCP 7.2.2.1 Exercise 166
Section 7.2.2.1: Dancing Links Exercise 166. [ 21 ] [21] Extend answer 9 to the more general situation that arises in Algorithm M: a) Let $\theta_p$ be the number of different choices that will be explored at the current position of the search tree if primary item $p$ is selected for branching. Express $\theta_p$ as a function of $\text{LEN}(p)$, $\text{SLACK}(p)$, and $\text{BOUND}(p)$. b) Suppose $\theta_p = \theta_{p'}$ and $\text{SLACK}(p) =...
TAOCP 7.2.2.1 Exercise 165
Section 7.2.2.1: Dancing Links Exercise 165. [ M30 ] [M30] Consider an MCC problem in which we must choose 2 of 4 options to cover item 1, and 5 of 7 options to cover item 2; the options are all distinct. a) What's the size of the search tree if we branch first on item 1, then on item 2? Would it better to branch first on item 2, then...
TAOCP 7.2.2.1 Exercise 164
Section 7.2.2.1: Dancing Links Exercise 164. [ 17 ] [17] When Algorithm M finds a solution $x_0 x_1 \ldots x_{t-1}$ in step M2, some of the nodes $x_j$ might represent the fact that some primary item will appear in no further options. Explain how to handle this "null" case, by modifying answer 13. Verified: no Solve time: 5m15s Setup We seek all integers $n < 10^9$ such that the equation...
TAOCP 7.2.2.1 Exercise 163
Section 7.2.2.1: Dancing Links Exercise 163. [ 20 ] [20] Explain the possible rules for setting $p$ in (12). Verified: no Solve time: 1m25s Solution In (12), the variable $p$ is used to traverse exactly the vertical list of nodes that correspond to active options containing item $i$. This vertical list is a circular doubly linked list whose header is the item node $i$, with $\mathrm{DLINK}(i)$ pointing to the first...
TAOCP 7.2.2.1 Exercise 162
Section 7.2.2.1: Dancing Links Exercise 162. [ 24 ] [24] Say that a $\mathcal{Q}_n$ is an $n \times n$ array of $n$ nonattacking queens. Sometimes a $\mathcal{Q}_m$ contains a $\mathcal{Q}_n$ for $m < n$; for example, eight of the possible $\mathcal{Q}_5$'s contain a $\mathcal{Q}_4$, and the $\mathcal{Q}_7$ illustrated here contains both a $\mathcal{Q}_3$ and a $\mathcal{Q}_5$. What is the smallest $n$ such that at least one $\mathcal{Q}_n$ contains (a) two...
TAOCP 7.2.2.1 Exercise 161
Section 7.2.2.1: Dancing Links Exercise 161. ▶ [ 23 ] [23] Three restricted queen-domination problems are prominent in the literature: i) No two queens of a solution attack each other. ii) Each queen of a solution is attacked by at least one of the others. iii) The queens of a solution form a clique. (The third and fourth examples in (6§) are instances of types (ii) and (i).) Explain how...
TAOCP 7.2.2.1 Exercise 160
Section 7.2.2.1: Dancing Links Exercise 160. [ 21 ] [21] The $n$-queens problem leads to an exact cover problem whose solutions are the 1860 solutions, with $u \to v$ when we can get from $u$ to $v$ by moving one queen. How many connected components does this graph have? Is one of them a "giant"? Verified: no Solve time: 3m31s Solution Let a configuration be a placement of $n$ queens...
TAOCP 7.2.2.1 Exercise 16
Section 7.2.2.1: Dancing Links Exercise 16. [ 16 ] [16] What are the solutions to the four queens problem, as formulated in (23) and (24)? What branches are taken at the top four levels of Algorithm X's search tree? Verified: no Solve time: 2m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2.1 Exercise 159
Section 7.2.2.1: Dancing Links Exercise 159. ▶ [ 21 ] [21] Suggest a way to speed up the text's solution to the 5-queens problem, by using the symmetries of a square to modify the items and options of (6$\frac{1}{2}$). Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2.1 Exercise 158
Section 7.2.2.1: Dancing Links Exercise 158. [ 25 ] [25] Another variation of the partridge puzzle when $2 \le n \le 7$ asks for the smallest rectangular area that will contain $k$ nonoverlapping squares of size $k \times k$ for $1 \le k \le n$. For example, here are solutions for $n = 2$, 3, and 4: (To show optimality for $n = 4$ one must prove that rectangles of...
TAOCP 7.2.2.1 Exercise 157
Section 7.2.2.1: Dancing Links Exercise 157. [ 22 ] [22] Continue the study of small partridges by extending (6a) to $n = 4$ and 7. Verified: no Solve time: 5m13s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let...
TAOCP 7.2.2.1 Exercise 156
Section 7.2.2.1: Dancing Links Exercise 156. ▶ [ 30 ] [30] Straightforward backtracking will solve the partridge puzzle for $n = 8$, using bitwise techniques to represent a partially filled $36 \times 36$ square in just 36 octabytes, instead of by treating it as the huge MCC problem (61) and applying a highly general solver such as Algorithm M. Compare these two approaches, by implementing them both. How many essentially...
TAOCP 7.2.2.1 Exercise 155
Section 7.2.2.1: Dancing Links Exercise 155. [ 20 ] [20] That "authentic" partridge puzzle has a square solution when $n = 6$. a) How many different solutions does it have in that case? b) The affinity score of a partridge packing is the number of internal edges that lie on the boundary between two squares of the same size. (In (6a) the scores are 165 and 67.) What solutions to...
TAOCP 7.2.2.1 Exercise 154
Section 7.2.2.1: Dancing Links Exercise 154. [ M30 ] (C. R. J. Singleton, 1982.) After twelve days of Christmas, the person who sings a popular carol has received twelve partridges in pear trees, plus eleven pairs of humming birds, . . . , plus one set of twelve drummers drumming, from his or her true love. Therefore an "authentic" partridge puzzle should try to pack $(n+1-k)$ squares of size $k...
TAOCP 7.2.2.1 Exercise 153
Section 7.2.2.1: Dancing Links Exercise 153. [ 25 ] [25] Here are six of the path dominoes, plus a "start" piece and a "stop" piece: a) Place them within a $4 \times 5$ array so that they define a path from "start" to "stop." b) How many distinct "start" or "stop" pieces are possible, if they're each supposed to contain a single subpath together with a single terminal point? c)...
TAOCP 7.2.2.1 Exercise 152
Section 7.2.2.1: Dancing Links Exercise 152. [ 30 ] The complete set of path dominoes includes also twelve more patterns: Arrange all 48 of them in an $8 \times 12$ array, forming a single loop. Verified: no Solve time: 4m15s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive...
TAOCP 7.2.2.1 Exercise 151
Section 7.2.2.1: Dancing Links Exercise 151. ▶ [ 30 ] (Path dominoes.) A domino has six natural attachment points on its boundary, where we could draw part of a path that connects to neighboring dominoes. Thus $\binom{6}{2} = 15$ different partial paths could potentially be drawn on it. However, only 9 distinct domino patterns with one subpath actually arise, because the other profiles are related under ISO(2); there are six...
TAOCP 7.2.2.1 Exercise 150
Section 7.2.2.1: Dancing Links Exercise 150. [ 24 ] Here's a classic 19th century puzzle that was the first of its kind: "Arrange all the pieces to fill the square … so that all the links of the Chain join together, forming an Endless Chain. The Chain may be any shape, so long as all the links join together, and all the pieces are used. This Puzzle can be done...
TAOCP 7.2.2.1 Exercise 15
Section 7.2.2.1: Dancing Links Exercise 15. [ 20 ] [20] The options in (16) give us every solution to the Langford pair problem twice, because the left-right reversal of any solution is also a solution. Show that, if a few of those options are removed, we get not only half as many solutions; the others will be the reversals of the solutions found. Verified: yes Solve time: 2m23s Solution Let...
TAOCP 7.2.2.1 Exercise 149
Section 7.2.2.1: Dancing Links Exercise 149. [ M22 ] (Vertex-colored tetrahedra.) The graph $\text{simplex}(3,3,3,3,3,0)$ is a tetrahedron of side 3 with 20 vertices. It has 60 edges, which come from 10 unit tetrahedra. There are ten ways to color the vertices of a unit tetrahedron with four of the five colors ${\mathbf{a}, \mathbf{b}, \mathbf{c}, \mathbf{d}, \mathbf{e}}$, because mirror reflections are distinct. Can those ten colored tetrahedra be packed into $\text{simplex}(3,3,3,3,3,0)$,...
TAOCP 7.2.2.1 Exercise 148
Section 7.2.2.1: Dancing Links Exercise 148. [ 24 ] Find all distinct cubes whose faces are colored a , b , or c , when opposite faces are required to have different colors. Then arrange them into a symmetric shape (with matching colors wherever they are in contact). Verified: no Solve time: 4m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots...
TAOCP 7.2.2.1 Exercise 147
Section 7.2.2.1: Dancing Links Exercise 147. [ 30 ] The 30 cubes of exercise 146 can be used to make "bricks" of various sizes $l \times m \times n$, by assembling $l \cdot m \cdot n$ of them into a cuboid that has solid colors on each exterior face, as well as matching colors on each interior face. For example, each cube naturally joins with its mirror image to form...
TAOCP 7.2.2.1 Exercise 146
Section 7.2.2.1: Dancing Links Exercise 146. ▶ [ M30 ] $[M30]$ There are 30 ways to paint the colors ${\mathbf{a}, \mathbf{b}, \mathbf{c}, \mathbf{d}, \mathbf{e}, \mathbf{f}}$ on the faces of a cube: (If $\mathbf{a}$ is on top, there are five choices for the bottom color, then six cyclic permutations of the remaining four.) Here's one way to arrange six differently painted cubes in a row, with distinct colors on top, bottom,...
TAOCP 7.2.2.1 Exercise 145
Section 7.2.2.1: Dancing Links Exercise 145. ▶ [ M28 ] $[M28]$ Many problems that involve an $l \times m \times n$ cuboid require a good internal representation of its $(l+1)(m+1)(n+1)$ vertices, its $l(m+1)(n+1) + (l+1)m(n+1) + (l+1)(m+1)n$ edges, and its $lm(n+1)+l(m+1)n+(l+1)mn$ faces, in addition to its $lmn$ individual cells. Show that there's a convenient way to do this with integer coordinates $(x, y, z)$ whose ranges are $0 \le x...
TAOCP 7.2.2.1 Exercise 144
Section 7.2.2.1: Dancing Links Exercise 144. [**] $[2\frac{1}{2}]$ The idea of exercise 142 applies also to triangles and hexagons, allowing us to do both vertex and edge matching with yet another set of 24 tiles: Here there's a vertex matching in the bottom five tiles of (i), and in the upper left five and bottom five in (ii), with edge matching elsewhere. In how many ways can the big hexagon...
TAOCP 7.2.2.1 Exercise 143
Section 7.2.2.1: Dancing Links Exercise 143. ▶ [ M25 ] $[M25]$ The graph $simplex(n, a, b, c, 0, 0, 0)$ in the Stanford GraphBase is the truncated triangular grid consisting of all vertices $xyz$ such that $$x + y + z = n,\quad 0 \le x \le a,\quad 0 \le y \le b,\quad 0 \le z \le c.$$ Two vertices are adjacent if their coordinates all differ by at most...
TAOCP 7.2.2.1 Exercise 142
Section 7.2.2.1: Dancing Links Exercise 142. ▶ [**] $[\tfrac{21}{2}]$ (Zdravko Zivković, 2008.) Edge and vertex matching can be combined into a single design if we replace MacMahon's 24 squares by 24 octagons. For example, illustrate $4 \times 6$ arrangements in which there's vertex matching in the (i) left half, (ii) bottom half, or (iii) northwest and southeast quadrants, while edge matching occurs elsewhere. (We get vertex matching when an octagon's...
TAOCP 7.2.2.1 Exercise 141
Section 7.2.2.1: Dancing Links Exercise 141. [**] $[\tfrac{21}{2}]$ Combining exercises 133 and 140, we can also adapt MacMahon's 24 tri-colored squares to vertex matching instead of edge matching. Noteworthy solutions are a) In how many essentially different ways can those 24 tiles be properly packed into rectangles of these sizes, leaving a hole in the middle of the $5 \times 5$? b) Discuss tiling the plane with such solutions. Verified:...
TAOCP 7.2.2.1 Exercise 140
Section 7.2.2.1: Dancing Links Exercise 140. [ 29 ] [29] (C. D. Langford, 1959.) MacMahon colored the edges of his tiles, but we can color the vertices instead. For example, we can make two parallelograms, or a truncated triangle, by assembling the 24 vertex-colored analogs of (58): Such arrangements are much rarer than those based on edge matching, because edges are common to only two tiles but vertices might involve...
TAOCP 7.2.2.1 Exercise 14
Section 7.2.2.1: Dancing Links Exercise 14. ▶ [ 20 ] [20] [ Problème des ménages. ] "In how many ways can $n$ male-female couples sit at a circular table, with men and women alternating, and with no couple together?" a) Suppose the women have already been seated, and let the vacant seats be $(S_0, S_1, \ldots, S_{n-1})$. Let $M_j$ be the spouse of the woman between seats $S_j$ and $S_{(j+1)...
TAOCP 7.2.2.1 Exercise 139
Section 7.2.2.1: Dancing Links Exercise 139. [**] [ M 25] Excellent human-scale puzzles have been made by choosing nine of the 24 tiles in exercise 138, redrawing them with whimsical illustrations in place of the triangles, and asking for a $3 \times 3$ arrangement in which heads properly match tails. a) How many of the $\binom{24}{9}$ choices of 9 tiles lead to essentially different puzzles? b) How many of those...
TAOCP 7.2.2.1 Exercise 138
Section 7.2.2.1: Dancing Links Exercise 138. [ 25 ] [25] [ Heads and tails. ] Here's a set of 24 square tiles that MacMahon missed(!): They each show two "heads" and two "tails" of triangles, in four colors that exhibit all possible permutations, with heads pointing to tails. The tiles can be rotated, but not flipped over. We can match them properly in many ways, such as where the $4...
TAOCP 7.2.2.1 Exercise 137
Section 7.2.2.1: Dancing Links Exercise 137. [ 22 ] [22] A popular puzzle called Drive Ya Nuts consists of seven "hex nuts" that have been decorated with permutations of the numbers ${1, 2, 3, 4, 5, 6}$. The object is to arrange them as shown, with numbers matching at the edges. a) Show that this puzzle has a unique solution, with that particular set of seven. (Reflections of the nuts...
TAOCP 7.2.2.1 Exercise 136
Section 7.2.2.1: Dancing Links Exercise 136. ▶ [ HM48 ] (J. H. Conway, 1958.) There are twelve ways to label the edges of a pentagon with ${0, 1, 2, 3, 4}$, if we don't consider rotations and reflections to be different: Cover a dodecahedron with these tiles, matching edge numbers. (Reflections are OK.) Verified: no Solve time: 4m56s Setup We seek all integers $n < 10^9$ such that the equation...
TAOCP 7.2.2.1 Exercise 135
Section 7.2.2.1: Dancing Links Exercise 135. [ 23 ] (H. L. Nelson, 1970.) Show that MacMahon's squares of exercise 133 can be used to wrap around the faces of a $2 \times 2 \times 2$ cube, matching colors wherever adjacent. Verified: no Solve time: 5m15s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has...
TAOCP 7.2.2.1 Exercise 134
Section 7.2.2.1: Dancing Links Exercise 134. [ 23 ] The nonwhite areas of the pattern in exercise 133 form polyominoes (rotated 45°); in fact, the lighter color has an S pentomino, while the darker color has both P and V. How often do each of the twelve pentominoes occur, among all of the solutions? Verified: no Solve time: 4m06s Setup We seek all integers $n < 10^9$ such that the...
TAOCP 7.2.2.1 Exercise 133
Section 7.2.2.1: Dancing Links Exercise 133. [ 21 ] (P. A. MacMahon, 1921.) A set of 24 square tiles can be constructed, analogous to the triangular tiles of (§8), if we restrict ourselves to just three colors. For example, they can be arranged in a $4 \times 6$ rectangle as shown, with all-white border. In how many ways can this be done? Verified: no Solve time: 5m13s Setup We seek...
TAOCP 7.2.2.1 Exercise 132
Section 7.2.2.1: Dancing Links Exercise 132. [ 40 ] (W. E. Philpott, 1971.) There are $4624 = 68^2$ tiles in a set like (§8), but it uses 24 different colors instead of 4. Can they be assembled into an equilateral triangle of size 68, with constant color on the boundary and with matching edges inside? Verified: no Solve time: 5m09s Setup We seek all integers $n < 10^9$ such that...
TAOCP 7.2.2.1 Exercise 131
Section 7.2.2.1: Dancing Links Exercise 131. [ 28 ] (P. A. MacMahon, 1921.) Instead of using the colored tiles of (§8), which yield (59), we can form hexagons from 24 different triangles in two other ways: The left diagram shows a "jigsaw puzzle" whose pieces have four kinds of edges. The right diagram shows "triple three triominoes," which have zero, one, two, or three spots at each edge; adjacent triominoes...
TAOCP 7.2.2.1 Exercise 130
Section 7.2.2.1: Dancing Links Exercise 130. [**] [2↑] Partition MacMahon's triangles (§8) into three sets of eight, each of which can be placed on the faces of an octahedron, with matching edge colors. Verified: no Solve time: 2m25s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.2.1 Exercise 13
Section 7.2.2.1: Dancing Links Exercise 13. [ 16 ] [16] When Algorithm X finds a solution in step X2, how can we use the values of $x_0, x_1, \ldots, x_{l-1}$ to figure out what that solution is? Verified: no Solve time: 4m10s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution...
TAOCP 7.2.2.1 Exercise 129
Section 7.2.2.1: Dancing Links Exercise 129. ▶ [ M14 ] The most beautiful patterns that can be made with MacMahon's triangles are those with attractive symmetries, which can be of two kinds: strong symmetry (a rotation or reflection that doesn't change the pattern, except for permutation of colors) or weak symmetry (a rotation or reflection that preserves the "color patches," the set of boundaries between different colors). Exactly how many...
TAOCP 7.2.2.1 Exercise 128
Section 7.2.2.1: Dancing Links Exercise 128. [ 25 ] [25] Eleven of MacMahon's triangles (28) involve only the first three colors (not black). Arrange them into a pleasant pattern that tiles the entire plane when replicated. Verified: no Solve time: 5m09s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.2.1 Exercise 127
Section 7.2.2.1: Dancing Links Exercise 127. [ M8 ] There are $4^{12}$ ways to prescribe the border colors of a hexagon like those in (59). Which of them can be completed to a color-matched placement of all 24 triangles? Verified: no Solve time: 4m16s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2.1 Exercise 126
Section 7.2.2.1: Dancing Links Exercise 126. [ 29 ] [29] Find all solutions of MacMahon's problem (59), by applying Algorithm C to a suitable set of items and options based on the coordinate system in exercise 124. How much time is saved by using the improved algorithm of exercise 122? Verified: no Solve time: 5m15s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2...
TAOCP 7.2.2.1 Exercise 125
Section 7.2.2.1: Dancing Links Exercise 125. [ M20 ] When a set of $s$ triangles is magnified by an integer $k$, we obtain $sk^2$ triangles. Describe the coordinates of those triangles, in terms of the coordinates of the originals, using the system of exercise 124. Verified: no Solve time: 5m15s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n =...
TAOCP 7.2.2.1 Exercise 124
Section 7.2.2.1: Dancing Links Exercise 124. [ M22 ] Devise a system of coordinates for representing the positions of equilateral triangles in patterns such as (59). Represent also the edges between them. Verified: no Solve time: 5m28s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1...
TAOCP 7.2.2.1 Exercise 123
Section 7.2.2.1: Dancing Links Exercise 123. [ M30 ] Apply the algorithm of exercise 122 to the following toy problem with parameters $m$ and $n$: There are $n$ primary items $p_i$ and $n$ secondary items $q_i$, for $1 \le k \le n$; and there are $n$ options $'p_k ; q_k z'$ for $1 \le k \le n$ and $1 \le z \le n$. (The solutions to this problem are the...
TAOCP 7.2.2.1 Exercise 122
Section 7.2.2.1: Dancing Links Exercise 122. ▶ [ 28 ] [28] Extend Algorithm C so that it finds only $1/d!$ of the solutions, in cases where the input options are totally symmetric with respect to $d$ of the color values, and where every solution contains each of those color values at least once. Assume that those values are ${v, v+1, \ldots, v+d-1}$, and that all other colors have values $<...
TAOCP 7.2.2.1 Exercise 121
Section 7.2.2.1: Dancing Links Exercise 121. [ M29 ] Exercise 2.3.4.3–5 discusses 92 types of tetrads that are able to tile the plane, and proves that no such tiling is toroidal (periodic). a) Show that the tile called $\delta U S$ in that exercise can't be part of any infinite tiling. In fact, it can appear in only $n+1$ cells of an $m \times n$ array, when $m, n \ge...
TAOCP 7.2.2.1 Exercise 120
Section 7.2.2.1: Dancing Links Exercise 120. [ M29 ] Section 2.3.4.3 discussed Hao Wang's "tetrad tiles," which are squares that have specified colors on each side. Find all ways in which the entire plane can be filled with tiles from the following families of tetrad types, always matching colors at the edges where adjacent tiles meet [see Scientific American 231 , 5 (Nov. 1965), 103, 106]: a) b) (The tetrad...
TAOCP 7.2.2.1 Exercise 12
Section 7.2.2.1: Dancing Links Exercise 12. ▶ [ 23 ] [23] Design an algorithm that prints the option associated with a given node $x$, cyclically ordering the option so that TOP$(x)$ is its first item. Also print the position of that option in the vertical list for that item. (For example, if $x = 21$ in Table 1, your algorithm should print '$d\ f\ a$' and state that it's option...
TAOCP 7.2.2.1 Exercise 119
Section 7.2.2.1: Dancing Links Exercise 119. [ 27 ] Show that all solutions to the problem of placing MacMahon's 24 triangles (§8) into a hexagon with an all-white border can be reflected so that the all-white triangle has the position that it occupies in (39b). Hint: Factorize. Verified: no Solve time: 5m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots +...
TAOCP 7.2.2.1 Exercise 118
Section 7.2.2.1: Dancing Links Exercise 118. [ 21 ] (Hypergraph coloring.) Color the 64 cells of a chessboard with four colors, so that no three cells of the same color lie in a straight line of any slope. Verified: no Solve time: 5m09s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.2.1 Exercise 117
Section 7.2.2.1: Dancing Links Exercise 117. ▶ [ 21 ] (Graph coloring.) Suppose we want to find all possible ways to label the vertices of graph $G$ with $c$ colors: adjacent vertices should have different colors. a) Formulate this as an exact cover problem, with one primary item for each vertex and with $d$ secondary items for each edge. b) Sometimes $G$'s edges are conveniently specified by giving a family...
TAOCP 7.2.2.1 Exercise 116
Section 7.2.2.1: Dancing Links Exercise 116. ▶ [ M25 ] Given a graph $G$ on vertices $V$, let $\mu(G)$ be obtained by (i) adding new vertices $V' = {v' \mid v \in V}$, with $u' \mathbin{-!!-} v$ when $u \mathbin{-!!-} v$; and also (ii) adding another vertex $w$, with $w \mathbin{-!!-} v'$ for all $v' \in V'$. If $G$ has $m$ edges and $n$ vertices, $\mu(G)$ has $3m+n$ edges and...
TAOCP 7.2.2.1 Exercise 115
Section 7.2.2.1: Dancing Links Exercise 115. [ M25 ] Continuing exercise 114, how many hypersudoku solutions have automorphisms of the following types? (a) transposition; (b) the transformation of exercise 67(d); (c) 90° rotation; (d) both (b) and (c). Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.2.1 Exercise 114
Section 7.2.2.1: Dancing Links Exercise 114. [ M25 ] Let $\alpha$ be a permutation of the cells of a $9 \times 9$ array that takes any sudoku solution into another sudoku solution. We say that $\alpha$ is an automorphism of the sudoku solution $S = (s_{ij})$ if there's a permutation $\pi$ of ${1, 2, \ldots, 9}$ such that $s_{ij\alpha} = \pi s_{ij}$ for $0 \le i, j \le 9$. For...
TAOCP 7.2.2.1 Exercise 113
Section 7.2.2.1: Dancing Links Exercise 113. [ 21 ] [21] An 'alphabet block' is a cube whose six faces are marked with letters. Is there a set of five alphabet blocks that are able to spell the 25 words TREES, NODES, STACK, AVAIL, FIRST, RIGHT, ORDER, LIST, GIVEN, LINKS, QUEUE, GRAPH, TIMES, BLOCK, VALUE, TABLE, FIELD, EDGE, ABOVE, POINT, THREE, LINK, HENCE, QUITE, DEBUG? (Each of these words appears more...
TAOCP 7.2.2.1 Exercise 112
Section 7.2.2.1: Dancing Links Exercise 112. ▶ [ 28 ] [28] A popular word puzzle in Brazil, called 'Torto' ('bent'), asks solvers to find as many words as possible that can be traced by a noncrossing king path in a given $6 \times 3$ array of letters. For example, each of the words THE, NATURE, ART, OF, COMPUTER, and PROGRAMMING can be found in the array shown here. a) Does...
TAOCP 7.2.2.1 Exercise 111
Section 7.2.2.1: Dancing Links Exercise 111. [ 21 ] [21] Find all $8 \times 8$ crossword puzzle diagrams that contain exactly (a) 12 3-letter words, 12 4-letter words, and 4 5-letter words; (b) 12 5-letter words, 8 2-letter words, and 4 8-letter words; and (c) would have no words of other lengths. Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1...
TAOCP 7.2.2.1 Exercise 110
Section 7.2.2.1: Dancing Links Exercise 110. [ 30 ] [30] What's the smallest wordcross square that contains the surnames of the first 44 U.S. presidents? (Use the names in exercise 108, but change VANBUREN to VAN BUREN.) Verified: no Solve time: 5m17s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution...
TAOCP 7.2.2.1 Exercise 11
Section 7.2.2.1: Dancing Links Exercise 11. ▶ [ 21 ] [21] Play through Algorithm X by hand, using exercise 9 in step X3 and the input in Table 1, until first reaching step X7. What are the contents of memory at that time? Verified: no Solve time: 5m11s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.2.1 Exercise 109
Section 7.2.2.1: Dancing Links Exercise 109. [ 28 ] [28] A "wordcross puzzle" is the challenge of packing a given set of words into a rectangle under the following conditions: (i) All words must read either across or down, as in a crossword puzzle. (ii) No letters are adjacent unless they belong to one of the given words. (iii) The words are rowwise connected. (iv) Words overlap only when one...
TAOCP 7.2.2.1 Exercise 108
Section 7.2.2.1: Dancing Links Exercise 108. ▶ [ 32 ] [32] The first 44 presidents of the U.S.A. had 38 distinct surnames: ADAMS, ARTHUR, BUCHANAN, BUSH, CARTER, CLEVELAND, CLINTON, COOLIDGE, EISENHOWER, FILL-MORE, FORD, GARFIELD, GRANT, HARDING, HARRISON, HAYES, HOOVER, JACKSON, JEFFERSON, JOHNSON, KENNEDY, LINCOLN, MADISON, MCKINLEY, MONROE, NIXON, OBAMA, PIERCE, POLK, REAGAN, ROOSEVELT, TAFT, TAYLOR, TRUMAN, TYLER, VANBUREN, WASHINGTON, WILSON. a) What's the smallest square into which all of these...
TAOCP 7.2.2.1 Exercise 107
Section 7.2.2.1: Dancing Links Exercise 107. ▶ [ 23 ] [23] Pack as many of the following words as possible into a $9 \times 9$ array, simultaneously satisfying the rules of both word search and sudoku: ACRE COMPARE CORPORATE MACRO MOTET ROAM ART COMPUTER CROP META PARAMETER TAME Verified: no Solve time: 5m21s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots...
TAOCP 7.2.2.1 Exercise 106
Section 7.2.2.1: Dancing Links Exercise 106. [ 22 ] [22] Also pack two copies of ONE, TWO, THREE, FOUR, FIVE into a $5 \times 5$ square. Verified: no Solve time: 5m11s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.2.1 Exercise 105
Section 7.2.2.1: Dancing Links Exercise 105. [ 22 ] [22] Using the "word search puzzle" conventions of Figs. 71 and 72, show that the words ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, ELEVEN, and TWELVE can all be packed into a $6 \times 6$ square, leaving one cell untouched. Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1...
TAOCP 7.2.2.1 Exercise 104
Section 7.2.2.1: Dancing Links Exercise 104. [ M28 ] Assume that $n + 1 = p$ is prime. Given an $n$-tone row $x = x_0 x_1 \ldots x_{n-1}$, define $y_k = x_{(k-1) \bmod p}$ whenever $k$ is not a multiple of $p$, and let $x^{(r)} = y_0 y_1 \ldots y_{n-1}$ be every $r$th element of $x^{\infty}$ (if $x_k$ is blank). For example, when $n = 12$, every 5th element of...
TAOCP 7.2.2.1 Exercise 103
Section 7.2.2.1: Dancing Links Exercise 103. [ M28 ] Musical pitches in the Western system of "equal temperament" are the notes whose frequency is $440 \cdot 2^{n/12}$ cycles per second, for some integer $n$. The pitch class of such a note is $n \bmod 12$, and seven of the twelve possible pitch classes are conventionally designated by letters: $$0 = \mathrm{A}, \quad 2 = \mathrm{B}, \quad 3 = \mathrm{C}, \quad...
TAOCP 7.2.2.1 Exercise 102
Section 7.2.2.1: Dancing Links Exercise 102. ▶ [ 25 ] [25] Explain how to find all solutions to a Japanese arrow puzzle with Algorithm C. (See exercise 7.2.2–68.) Verified: no Solve time: 5m12s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots...
TAOCP 7.2.2.1 Exercise 101
Section 7.2.2.1: Dancing Links Exercise 101. ▶ [ 25 ] [25] (The zebra puzzle.) Formulate the following query as an XCC problem: "Five people, from five different countries, have five different occupations, own five different pets, drink five different beverages, and live in a row of five differently colored houses. The Englishman lives in a red house. The yellow house holds a diplomat. The Norwegian's house is the leftmost. The...
TAOCP 7.2.2.1 Exercise 100
Section 7.2.2.1: Dancing Links Exercise 100. ▶ [ 30 ] [30] The general constraint satisfaction problem (CSP) is the task of finding all $n$-tuples $x_1 \ldots x_n$ that satisfy a given system of constraints $C_1, \ldots, C_m$, where each constraint is defined by a relation on a nonempty subset of the variables ${x_1, \ldots, x_n}$. For example, a unary constraint is a relation of the form $x_k \in D_{jk}$; a...
TAOCP 7.2.2.1 Exercise 10
Section 7.2.2.1: Dancing Links Exercise 10. [ 20 ] [20] In some applications the MRV heuristic of exercise 9 leads the search astray, because certain primary items have short lists yet convey little information about desirable choices. Modify answer 9 so that an item $p$ whose name does not begin with the character '#' will be chosen only if LEN$(p) \le 1$ or no other choices exist. (This tactic is...
TAOCP 7.2.2.1 Exercise 9
Section 7.2.2.1: Dancing Links Exercise 9. [ 18 ] [18] Explain how to branch in step X3 on an item $i$ for which LEN($i$) is minimum. If several items have that minimum value, $i$ should also be a minimum. (This choice is often called the "minimum remaining values" (MRV) heuristic.) Verified: no Solve time: 3m03s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2...
TAOCP 7.2.2.1 Exercise 8
Section 7.2.2.1: Dancing Links Exercise 8. [ 22 ] [22] Design an algorithm to set up the initial memory contents of an exact cover problem, as needed by Algorithm X and illustrated in Table 1. The input to your algorithm should consist of a sequence of lines with the following format: The very first line lists the names of all items. Each remaining line specifies the items of a particular...
TAOCP 7.2.2.1 Exercise 7
Section 7.2.2.1: Dancing Links Exercise 7. [ 16 ] [16] Why is TOP(23) $= -4$ in Table 1? Why is DLINK(23) $= 25$? Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.2.1 Exercise 6
Section 7.2.2.1: Dancing Links Exercise 6. [ 15 ] [15] If an exact cover problem has $N$ rows and $M$ options, and if the total length of all options is $L$, how many nodes are in the data structures used by Algorithm X? Verified: no Solve time: 3m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.2.1 Exercise 5
Section 7.2.2.1: Dancing Links Exercise 5. [ 18 ] [18] Among the many combinatorial problems that can be formulated in terms of 0–1 matrices, some of the most important deal with families of sets : The columns of the matrix represent elements of a given universe, and the rows represent subsets of that universe. The exact cover problem is to partition the elements of the universe into such subsets. In...
TAOCP 7.2.2.1 Exercise 4
Section 7.2.2.1: Dancing Links Exercise 4. [ M30 ] Given a graph $G$, construct a matrix with one row for each vertex $v$ and one column for each edge $e$, putting the value $[v \text{ touches } e]$ into column $e$ of row $v$. What do the exact covers of this "incidence matrix" represent? Verified: no Solve time: 2m22s Setup Let $G = (V, E)$ be a (simple, undirected) graph....
TAOCP 7.2.1.6 Exercise 99
Section 7.2.1.6: Generating All Trees Exercise 99. [ 30 ] Consider a series-parallel graph represented by a tree as in (53), together with node values that satisfy (55). These values define a spanning tree or a near tree, according as $v_p$ is 1 or 0 at the root $p$. Show that the following method will generate all of the other configs of the root: i) Begin with all memory nodes...
TAOCP 7.2.1.6 Exercise 98
Section 7.2.1.6: Generating All Trees Exercise 98. [ 16 ] What series-parallel graph corresponds to (53) if $A$ is taken to be serial ? Verified: no Solve time: 4m31s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.2.1 Exercise 3
Section 7.2.2.1: Dancing Links Exercise 3. [ 20 ] [20] An $m \times n$ matrix that's supposed to be exactly covered can be regarded as a set of $n$ simultaneous equations in $m$ unknowns. For example, (5) is equivalent to $$x_2 + x_3 = x_3 + x_5 + x_6 = x_2 + x_5 = x_3 + x_4 = x_1 + x_4 = x_2 + x_3 + x_4 + x_6 =...
TAOCP 7.2.2.1 Exercise 2
Section 7.2.2.1: Dancing Links Exercise 2. [ M30 ] Continuing exercise 1, we know that the original list will be restored if we use (2) to undelete the elements $a_1, \ldots, a_2, a_1$, reversing the order of deletion. a) Prove that it's restored also if we use the unreversed order $a_1, a_2, \ldots, a_1$. b) Is the original list restored if we undelete the elements in any order whatsoever? c)...
TAOCP 7.2.1.6 Exercise 97
Section 7.2.1.6: Generating All Trees Exercise 97. [ 15 ] Is (48) a series-parallel graph? Verified: no Solve time: 5m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms among $x_1,\dots,x_n$ that are...
TAOCP 7.2.2.1 Exercise 1
Section 7.2.2.1: Dancing Links Exercise 1. ▶ [ M25 ] A doubly linked list of $n$ elements, with a list head at 0, begins with $\text{LLINK}(k) = k - 1$ and $\text{RLINK}(k - 1) = k$ for $1 \le k \le n$; furthermore $\text{LLINK}(0) = n$ and $\text{RLINK}(n) = 0$, as in (3). But after we use operation (1) to delete elements $a_1, a_2, \ldots, a_n$, where $a_1 a_2 \ldots...
TAOCP 7.2.1.6 Exercise 96
Section 7.2.1.6: Generating All Trees Exercise 96. ▶ [ 28 ] Analyze the approximate running time of Algorithm S when the given graph is simply (a) a path $P_n$ of length $n-1$; (b) a cycle $C_n$ of length $n$. Verified: no Solve time: 4m32s We restart from the actual structure of Algorithm S in TAOCP §7.2.1.6 and avoid collapsing any of its internal mechanisms into unjustified constant-time or one-pass assumptions....
TAOCP 7.2.1.6 Exercise 95
Section 7.2.1.6: Generating All Trees Exercise 95. [ 26 ] Complete Algorithm S by implementing the bridge test in step S8. Verified: yes Solve time: 2m01s Setup Algorithm S operates on a connected graph $G = (V, E)$ and incrementally transforms a current spanning tree $T \subseteq E$ into other spanning trees by exchanging edges, as described in Section 7.2.1.6. In step S8, the algorithm requires a bridge test :...
TAOCP 7.2.1.6 Exercise 94
Section 7.2.1.6: Generating All Trees Exercise 94. [ 22 ] Algorithm S needs to "prime the pump" by finding an initial spanning tree in step S1. Explain how to do that task. Verified: yes Solve time: 2m14s Solution Algorithm S operates by transforming one spanning tree into another while maintaining a valid spanning tree structure throughout its execution. The mechanism assumes that an initial spanning tree of the input graph...
TAOCP 7.2.1.6 Exercise 93
Section 7.2.1.6: Generating All Trees Exercise 93. [ 20 ] When Algorithm S terminates, has it restored the graph to its original state? Verified: yes Solve time: 1m34s Solution Algorithm S enumerates spanning trees by performing a sequence of local transformations on the current graph representation, each transformation replacing one edge choice with another admissible edge while maintaining connectivity constraints. Each such modification is performed in a controlled search structure...
TAOCP 7.2.1.6 Exercise 92
Section 7.2.1.6: Generating All Trees Exercise 92. [ 15 ] Are the first and last spanning trees visited by Algorithm S adjacent, in the sense that they have $n-2$ edges in common? Verified: yes Solve time: 1m41s Solution Algorithm S enumerates all spanning trees of the complete graph $K_n$ via Prüfer sequences of length $n-2$ over the alphabet ${1,2,\ldots,n}$ in lexicographic order, as established in Section 7.2.1.6. The correspondence between...
TAOCP 7.2.1.6 Exercise 91
Section 7.2.1.6: Generating All Trees Exercise 91. [ M37 ] (Nijenhuis and Wilf.) Show that a random oriented tree can be generated with a procedure analogous to the random partition algorithm of exercise 7.2.1.4–47. Verified: yes Solve time: 1m56s Setup Let $T_n$ denote the set of rooted ordered trees with $n$ internal nodes in the sense of Algorithm B of Section 7.2.1.6, represented by left and right links $(l_1,\dots,l_n)$ and...
TAOCP 7.2.2 Exercise 79
Section 7.2.2: Backtracking Exercise 79. ▶ [ M30 ] The author and his wife own a pipe organ that contains 812 pipes, each of which is either playing or silent. Therefore $2^{812}$ different sounds (including silence) can potentially be created. However, the pipes are controlled by a conventional organ console, which has only $56+56+32=144$ keys and pedals that can be played by hands and feet, together with 20 on-off switches...
TAOCP 7.2.1.6 Exercise 90
Section 7.2.1.6: Generating All Trees Exercise 90. ▶ [ M37 ] If $p_1 \ldots p_n$ is a canonical sequence of parent pointers for an oriented forest, with the graph with vertices ${0, 1, \ldots, n}$ and edges ${k - p_k \mid 1 \le k \le n}$ is a free tree , namely a connected graph with no cycles. (See Theorem 2.3.4.1A.) Conversely, every free tree corresponds to at least one...
TAOCP 7.2.2 Exercise 78
Section 7.2.2: Backtracking Exercise 78. [ 22 ] [22] Extend the algorithm of exercise 77 to weighted graphs, in which every vertex has a nonnegative weight: Generate all of the connected induced subgraphs whose total weight $w$ satisfies $L \le w < U$. Verified: no Solve time: 5m25s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.1.6 Exercise 89
Section 7.2.1.6: Generating All Trees Exercise 89. [ M46 ] How often does step O5 set $p_k \leftarrow p_j$? Verified: no Solve time: 5m41s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.2 Exercise 77
Section 7.2.2: Backtracking Exercise 77. [ M22 ] A $v$-reachable subset of a directed graph $G$ is a nonempty set of vertices $H$ with the property that every $u \in H$ can be reached from $v$ by at least one oriented path in $G\langle H\rangle$. (In particular, $v$ itself must be in $H$.) a) The digraph $P_3' \mathbin{\square} P_3'$ is like $P_3 \mathbin{\square} P_3$ except that all arcs between vertices...
TAOCP 7.2.1.6 Exercise 88
Section 7.2.1.6: Generating All Trees Exercise 88. [ M20 ] Analyze Algorithm O: How often is step O4 performed? What is the total number of times $p_k$ is changed in step O5? Verified: no Solve time: 3m53s The previous solution failed by tying the execution of step O4 to a “parent-to-child transition” interpretation rather than to the actual control structure of Algorithm O. The correct way to reason is to...
TAOCP 7.2.1.6 Exercise 87
Section 7.2.1.6: Generating All Trees Exercise 87. [ M30 ] Let $F$ be an ordered forest in which the $k$th node in preorder appears on level $c_k$ and has parent $p_k$, where $p_k = 0$ if that node is a root. a) How many forests satisfy the condition $c_k = p_k$ for $1 \le k \le n$? b) Suppose $F$ and $F'$ have level codes $c_1 \ldots c_n$ and $c'_1...
TAOCP 7.2.2 Exercise 76
Section 7.2.2: Backtracking Exercise 76. [ 23 ] Use the algorithm of exercise 75 to generate all of the connected $n$-element subsets of a given graph $G$. How many such subsets does $P_m \mathbin{\square} P_n$ have, for $1 \le n \le 9$? Verified: no Solve time: 1m09s Solution Let $G = P_m \mathbin{\square} P_n$, where vertices are ordered pairs $(i,j)$ with $1 \le i \le m$, $1 \le j \le...
TAOCP 7.2.1.6 Exercise 86
Section 7.2.1.6: Generating All Trees Exercise 86. [ 15 ] If (a) is regarded as an oriented forest instead of an ordered forest, what monomial forests are possible? Specify that forest both by its level codes $c_1 \ldots c_{15}$ and its parent pointers $p_1 \ldots p_{15}$. Verified: no Solve time: 5m58s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n...
TAOCP 7.2.1.6 Exercise 85
Section 7.2.1.6: Generating All Trees Exercise 85. [ HM35 ] (Philippe Golle.) Let $V$ be any vector space contained in the set of all real $n$-dimensional vectors, but containing none of the unit vectors $(1, 0, \ldots, 0)$, $(0, 1, 0, \ldots, 0)$, …, $(0, \ldots, 0, 1)$. Prove that $V$ contains at most $M_n$ vectors whose components are all 0 or 1; furthermore the upper bound $M_n$ is achievable....
TAOCP 7.2.2 Exercise 75
Section 7.2.2: Backtracking Exercise 75. ▶ [ 30 ] (Connected subsets.) Let $v$ be a vertex of some graph $G$, and let $H$ be a connected subset of $G$ that contains $v$. The vertices of $H$ can be listed in a canonical way by starting with $v_0 = v$ and then letting $v_1, v_2, \ldots$ be the neighbors of $v_0$ that lie in $H$, followed by the neighbors of $v_1$...
TAOCP 7.2.1.6 Exercise 84
Section 7.2.1.6: Generating All Trees Exercise 84. ▶ [ HM27 ] (D. Kleitman.) Let $A$ be an $m \times n$ matrix of real numbers in which every column $v$ has length $|v| \ge 1$, and let $b$ be an $m$-dimensional column vector. Prove that at most $M_n$ column vectors $x = (a_1, \ldots, a_n)^T$, with components $a_j = 0$ or $1$, satisfy $|Ax - b| < \frac{1}{2}$. Hint: Use a...
TAOCP 7.2.1.6 Exercise 83
Section 7.2.1.6: Generating All Trees Exercise 83. [ M20 ] (G. Hansel.) Show that there are at most $3^{M_n}$ monotone Boolean functions $f(x_1, \ldots, x_n)$ of $n$ Boolean variables. Verified: no Solve time: 5m44s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.2 Exercise 74
Section 7.2.2: Backtracking Exercise 74. [ 21 ] The fifteenth mystery word in exercise 73 is $\underline{\phantom{xxxxx}}$. Why does its special form lead to a partial factorization of that problem? Verified: no Solve time: 5m11s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2...
TAOCP 7.2.1.6 Exercise 82
Section 7.2.1.6: Generating All Trees Exercise 82. ▶ [ M26 ] Let $E(f)$ be the number of times Algorithm II evaluates the function $f$. a) Show that $M_n \le E(f) \le M_{n+1}$, with equality when $f$ is constant. b) Among all $f$ such that $E(f) = M_n$, which one minimizes $\sum_{\sigma} f(\sigma)$? c) Among all $f$ such that $E(f) = M_n$, which one maximizes $\sum_{\sigma} f(\sigma)$? Verified: no Solve time:...
TAOCP 7.2.2 Exercise 73
Section 7.2.2: Backtracking Exercise 73. ▶ [ 30 ] (A clueless anacrostic.) The letters of 29 five-letter words $$\def\arraystretch{1.0} \begin{array}{ccccccccccc} \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \bar{\text{T}} & \cdots \end{array}$$ all belonging to WORDS(1000) , have been shuffled to form the following mystery text: $$\small \begin{array}{rrrrrrrrrrrrrrrrrr} 50 & 27 & 9 & 1 & 2 & 3 &...
TAOCP 7.2.1.6 Exercise 81
Section 7.2.1.6: Generating All Trees Exercise 81. [ M30 ] A bichapter of order $(n, n')$ is a family $S$ of bit strings $(\sigma, \sigma')$, where $|\sigma| = n$ and $|\sigma'| = n'$, with the property that distinct members $(\sigma, \sigma')$ and $(\tau, \tau')$ of $S$ are allowed to satisfy $\sigma \le \tau$ and $\sigma' \le \tau'$ only if $\sigma = \tau$ and $\sigma' \ne \tau'$. Use Christmas tree patterns...
TAOCP 7.2.1.6 Exercise 80
Section 7.2.1.6: Generating All Trees Exercise 80. [ 30 ] [30] Say that two bit strings are concordant if we can obtain one from the other via the transformations $010 \leftrightarrow 100$ or $101 \leftrightarrow 110$ on substrings. For example, the strings $$011100 \leftrightarrow 011010 \leftrightarrow 010110 \leftrightarrow 010101 \leftrightarrow 011001$$ $$\updownarrow$$ $$100110 \leftrightarrow 100101 \leftrightarrow 101001 \leftrightarrow 110001$$ are mutually concordant, but no other string is concordant with any...
TAOCP 7.2.1.6 Exercise 79
Section 7.2.1.6: Generating All Trees Exercise 79. [ M26 ] [M26] The number of permutations $p_1 \ldots p_n$ that have exactly one "descent" where $p_k > p_{k+1}$, is the Eulerian number $\langle {n \atop 1} \rangle = 2^n - n - 1$, according to Eq. 5.1.3–(12). The number of entries in the Christmas tree pattern, above the bottom row, is the same. a) Find a combinatorial explanation of this coincidence,...
TAOCP 7.2.2 Exercise 72
Section 7.2.2: Backtracking Exercise 72. [ HM28 ] Show that exercise 71 has a surprising, somewhat paradoxical answer if two changes are made to Table 666: 9(E) becomes '$c \in [39,..,43]$'; 15(C) becomes '${11}$'. Verified: no Solve time: 1m59s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers...
TAOCP 7.2.2 Exercise 71
Section 7.2.2: Backtracking Exercise 71. ▶ [ M29 ] (Donald R. Woods, 2000.) Find all ways to maximize the number of correct answers to the questionnaire in Table 666. Each question must be answered with a letter from A to E. Hint: Begin by clarifying the exact meaning of this exercise. What answers are best for the following two-question, two-letter "warmup problem"? Verified: no Solve time: 5m10s Setup We seek...
TAOCP 7.2.1.6 Exercise 78
Section 7.2.1.6: Generating All Trees Exercise 78. [ 20 ] [20] True or false: If $\sigma_1 \ldots \sigma_r$ is a row of the Christmas tree pattern, so is $\sigma_1^- \ldots \sigma_r^-$ (the reverse sequence of reverse complements). Verified: no Solve time: 5m44s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution...
TAOCP 7.2.2 Exercise 70
Section 7.2.2: Backtracking Exercise 70. [ HM40 ] (M. Bousquet-Mélou.) Consider self-avoiding paths from the upper left corner of an $m \times n$ grid to the lower right, where each step is either up, down, or to the right. If we generate such paths at random, making either 1 or 2 or 3 choices at each step as in Algorithm E, the expected value $\text{E},D_{mn}$ is the total number of...
TAOCP 7.2.1.6 Exercise 77
Section 7.2.1.6: Generating All Trees Exercise 77. [ 21 ] [21] Design an algorithm to generate the sequence of rightmost elements $a_1 \ldots a_n$ of the rows of the Christmas tree pattern of order $n$. Hint: These bit strings are characterized by the property that $a_1 + \cdots + a_k \ge k/2$ for $0 \le k \le n$. Verified: no Solve time: 5m57s Setup We seek all integers $n <...
TAOCP 7.2.2 Exercise 69
Section 7.2.2: Backtracking Exercise 69. [ 41 ] Is there a puzzle like exercise 68 whose clues contain more than 32 digits of $\pi$? Verified: no Solve time: 5m18s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.6 Exercise 76
Section 7.2.1.6: Generating All Trees Exercise 76. [ HM46 ] [HM46] Study the limiting shape of the Christmas tree patterns as $n \to \infty$. Does it, for example, have a fractal dimension under some appropriate scaling? Verified: no Solve time: 5m34s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.1.6 Exercise 75
Section 7.2.1.6: Generating All Trees Exercise 75. ▶ [ HM29 ] [HM29] Let $(r_1^{(n)}, r_2^{(n)}, \ldots, r_{c_n}^{(n)})$ be the row numbers in which the Christmas tree pattern of order $n$ has $n-1$ entries; for example, Table 4 tells us that $(r_1^{(3)}, r_2^{(3)}, r_3^{(3)}) = (20, 40, 54, 62, 66, 68, 69)$. Find formulas for $r_1^{(n)} - r_1^{(n)}$ and for $\lim_{n \to \infty} r_j^{(n)}/M_n$. Verified: no Solve time: 4m20s The solution...
TAOCP 7.2.1.6 Exercise 74
Section 7.2.1.6: Generating All Trees Exercise 74. [ M26 ] [M26] Continuing the previous exercise, how many rows precede that row? Verified: yes Solve time: 4m30s The reviewer correctly identifies that the previous solution made an incorrect leap : it treated a detected issue as a reason to terminate the ranking problem, and it also incorrectly output a numeric value. The correct resolution is to separate two logically distinct questions...
TAOCP 7.2.2 Exercise 68
Section 7.2.2: Backtracking Exercise 68. ▶ [ 28 ] (Johan de Ruiter, 14 March 2018.) Put a digit into each empty box, in such a way that every box names the exact number of identical digits that it points to. Verified: no Solve time: 2m03s The previous solution fails because it replaces the actual content of the diagram with assumptions. A corrected solution must treat the directed graph defined by...
TAOCP 7.2.2 Exercise 67
Section 7.2.2: Backtracking Exercise 67. ▶ [ 26 ] (The Royal Aquarium Thirteen Puzzle.) "Rearrange the nine cards of the right-hand illustration above, optionally rotating of them by $180°$, so that the six horizontal sums of gray letters and the six vertical sums of black letters all equal 13." (The current sums are $1+5+4 = 10$, $\ldots$, $7+5+7 = 19$.) The author of Hoffmann's Puzzles Old and New (1893) stated...
TAOCP 7.2.1.6 Exercise 73
Section 7.2.1.6: Generating All Trees Exercise 73. [ 15 ] [15] In the Christmas tree pattern of order 30, what are the first and last elements of the row that contains the bit string 011001001000011111011010111001? Verified: no Solve time: 4m22s The previous solution fails because it replaces Knuth’s recursive “Christmas tree” construction with an unrelated partition by Hamming weight. In §7.2.1.6, rows are not defined by global invariants of bitstrings....
TAOCP 7.2.2 Exercise 66
Section 7.2.2: Backtracking Exercise 66. ▶ [ 23 ] (The Fool's Disk.) "Rotate the four disks of the left-hand illustration below so that the four numbers on each ray sum to 12." (The current sums are $1+3+2+4 = 13$, etc.) Show that this problem factors nicely, so that it can be solved readily by hand. The Fool's Disk $\qquad\qquad\qquad\qquad\qquad$ The Royal Aquarium Thirteen Puzzle Verified: yes Solve time: 2m21s Let...
TAOCP 7.2.2 Exercise 65
Section 7.2.2: Backtracking Exercise 65. [ 25 ] Show that the generalized "Instant Insanity" problem, with $n$ cubes and $n$ colors on their faces, is NP-complete, even though cases with small $n$ are fairly easy. Verified: no Solve time: 4m05s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive...
TAOCP 7.2.1.6 Exercise 72
Section 7.2.1.6: Generating All Trees Exercise 72. [ M38 ] [M38] If you start with a single row $\sigma_1, \sigma_2, \ldots, \sigma_r$ of length $s$ and apply the growth rule (36) repeatedly $n$ times, how many rows do you obtain? Verified: no Solve time: 4m33s Setup Let a row be a string $\sigma_1 \sigma_2 \ldots \sigma_s$ of fixed length $s$. The growth rule (36) acts on a row to produce...
TAOCP 7.2.2 Exercise 64
Section 7.2.2: Backtracking Exercise 64. [**] [ 2↑ ] Assemble five cubes with uppercase letters on each face, using the patterns $$\begin{array}{ccccc} \text{P O E} & \text{S G S} & \text{A R T} & \text{D T E} & \text{U Y L} \ \text{Z}\overline{\text{O}}\text{H} & \text{N}\overline{\text{A}}\text{Z} & \text{H}\overline{\text{E}}\text{Z} & \text{U}\overline{\text{S}}\text{C} & \text{Z}\overline{\text{O}}\text{H} \end{array}$$ By extending the principles of "Instant Insanity," show that these cubes can be placed in a row so...
TAOCP 7.2.2 Exercise 63
Section 7.2.2: Backtracking Exercise 63. [ 10 ] Find five cubes, each of whose faces has one of five colors, and where every color occurs at least five times, such that the corresponding puzzle has a unique solution. Verified: no Solve time: 3m13s Let the colors be ${0,1,2,3,4}$ with arithmetic modulo $5$. Construct five cubes $C_0,\ldots,C_4$, each having six faces, by assigning colors as follows. For cube $C_i$, the faces...
TAOCP 7.2.2 Exercise 62
Section 7.2.2: Backtracking Exercise 62. ▶ [ 22 ] When the faces of four cubes are colored randomly with four colors, estimate the probability that the corresponding "Instant Insanity" puzzle has a unique solution. How many 2-regular graphs tend to appear during the "factored" solution process? Verified: no Solve time: 3m08s Solution Each cube has six faces colored independently with four colors. The faces are grouped into three opposite pairs,...
TAOCP 7.2.2 Exercise 61
Section 7.2.2: Backtracking Exercise 61. [ HM26 ] Let $P_n$ be the number of integer sequences $x_1 \ldots x_n$ such that $x_1 = 1$ and $1 \le x_{k+1} \le 2x_k$ for $1 \le k < n$. (The first few values are 1, 2, 6, 20, 76, 2280, ...; this sequence was introduced by A. Cayley in Philosophical Magazine (4) 13 (1857), 245–248, who showed that $P_n$ enumerates the partitions of...
TAOCP 7.2.1.6 Exercise 71
Section 7.2.1.6: Generating All Trees Exercise 71. [ M21 ] [M21] Let $M_{\sigma s}$ be the size of the largest possible set $S$ of $n$-bit strings with the property that, if $\sigma$ and $\tau$ are members of $S$ with $\sigma \le \tau$, then $\nu(\sigma) < \nu(\tau) + t$. (Thus, for example, $M_{n0} = M_n$ by Sperner's theorem.) Find a formula for $M_{ns}$. Verified: no Solve time: 2m14s Solution Let $B_n...
TAOCP 7.2.1.6 Exercise 70
Section 7.2.1.6: Generating All Trees Exercise 70. ▶ [ 20 ] [20] Find a simple rule that defines, for every bit string $\sigma$, another bit string $\sigma'$ called its mate , with the following properties: (i) $\sigma'' = \sigma$; (ii) $|\sigma'| = |\sigma|$; (iii) either $\sigma \le \sigma'$ or $\sigma' \le \sigma$; (iv) $\nu(\sigma) + \nu(\sigma') = |\sigma|$. Verified: yes Solve time: 1m42s Solution Let $\sigma = a_1 a_2 \cdots...
TAOCP 7.2.1.6 Exercise 69
Section 7.2.1.6: Generating All Trees Exercise 69. [ 20 ] [20] Are the Christmas tree patterns of orders 6 and 7 visible in Table 4, possibly in slight disguise? Verified: no Solve time: 4m17s The flaw in the previous solution is that it never identifies the actual objects in Table 4, nor uses the concrete form of the “Christmas tree” patterns. The argument must be rebuilt from the definition of...
TAOCP 7.2.2 Exercise 60
Section 7.2.2: Backtracking Exercise 60. ▶ [ 20 ] Experiment with biased random walks (see exercise 54), weighting each non-dead-end king move to a new vertex $v$ by $1 + \text{DIST}(v)^2$ instead of choosing every such move with the same probability. Does this strategy improve on Fig. 70? Verified: yes Solve time: 4m17s Which specific exercise or problem from TAOCP Volume 4 (and which section / fascicle) would you like...
TAOCP 7.2.1.6 Exercise 68
Section 7.2.1.6: Generating All Trees Exercise 68. [ 10 ] [10] What is the Christmas tree pattern of order 0? Verified: yes Solve time: 1m36s The Christmas tree pattern of order $n$ corresponds to the planar representation of a full binary tree (or equivalently a properly nested parenthesis structure) with $n$ internal nodes, drawn in its standard triangular “stacked” layout. For order $0$, there are no internal nodes and no...
TAOCP 7.2.2 Exercise 59
Section 7.2.2: Backtracking Exercise 59. [ 26 ] A ZDD with 3,174,197 nodes can be constructed to find (almost) all simple corner-to-corner king paths on a chessboard, using the method of exercise 7.1.4–225. Explain how to use this ZDD to compute (a) the total length of all paths; (b) the number of paths that touch any given subset of the center and/or corner points. Verified: no Solve time: 1m37s Setup...
TAOCP 7.2.1.6 Exercise 67
Section 7.2.1.6: Generating All Trees Exercise 67. [ M22 ] [M22] What is the generating function $S(z) = \sum_n S_n z^n$ for Schröder numbers? Verified: no Solve time: 3m10s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.2 Exercise 58
Section 7.2.2: Backtracking Exercise 58. [ 27 ] Consider using this mechanism is a special case of the general problem of counting simple paths from vertex $s$ to vertex $t$ in a given graph. We can generate such paths by random walks from $s$ that don't get stuck, if we maintain a table of values $\text{DIST}(v)$ for all vertices $v$ in the graph (or subgraph), representing the shortest distance from...
TAOCP 7.2.1.6 Exercise 66
Section 7.2.1.6: Generating All Trees Exercise 66. [ 21 ] [21] A Schröder tree is a binary tree in which every nonnull right link is colored either white or black. The number $S_n$ of $n$-node Schröder trees is $$\begin{array}{ccccccccccccc} n = & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \ S_n =...
TAOCP 7.2.2 Exercise 57
Section 7.2.2: Backtracking Exercise 57. [ HM21 ] Algorithm E can potentially follow $M$ different paths $X_1 \cdots X_{l-1}$ before it terminates, where $M$ is the number of leaves of the backtrack tree. Suppose the final values of $D$ at those leaves are $D^{(1)}, \ldots, D^{(M)}$. Prove that $(D^{(1)} \cdots D^{(M)})^{1/M} \ge M$. Verified: no Solve time: 5m06s Setup We seek all integers $n < 10^9$ such that the equation...
TAOCP 7.2.1.6 Exercise 65
Section 7.2.1.6: Generating All Trees Exercise 65. [ 38 ] [38] Generalize Rémy's algorithm (Algorithm R) to $t$-ary trees. Verified: no Solve time: 4m55s The earlier solution correctly described the growth process and the history-based bijection, but it made an unjustified leap from labeled histories to uniformity over unlabeled trees. The reviewer’s objection is decisive: the number of valid creation-time labelings depends on the tree shape, so one cannot cancel...
TAOCP 7.2.2 Exercise 56
Section 7.2.2: Backtracking Exercise 56. ▶ [ M25 ] The commafree code search procedure in Algorithm C doesn't actually fit the mold of Algorithm E, because it incorporates lookahead, dynamic ordering, reversible memory, and other enhancements to the basic backtrack paradigms. How could its running time be reliably estimated with Monte Carlo methods? Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation...
TAOCP 7.2.1.6 Exercise 64
Section 7.2.1.6: Generating All Trees Exercise 64. [ 20 ] [20] What sequence of $X$ values in Algorithm R corresponds to the decorated trees of (24), and what are the final values of $L_0 L_1 \ldots L_{32}$? Verified: no Solve time: 3m16s The exercise, as stated in your prompt, cannot be completed because it is missing the data that defines the computation. Exercise 7.2.1.6.64 is not a self contained mathematical...
TAOCP 7.2.2 Exercise 55
Section 7.2.2: Backtracking Exercise 55. [ M30 ] If all costs $c(x_1, \ldots, x_l)$ are positive, show that the biased probabilities of exercise 54 can be chosen in such a way that the estimate $S$ is always exact. Verified: no Solve time: 5m08s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.1.6 Exercise 63
Section 7.2.1.6: Generating All Trees Exercise 63. [**] [ If ] If the first two iterations of Rémy's algorithm have produced $\boxed{\square}\text{ }\boxed{\square}$, what decorated binary trees are possible after the next iteration? Verified: yes Solve time: 2m09s After the first iteration of Rémy's algorithm there is a single external node, carrying label $1$. During the second iteration there is only one existing node to choose, namely that external node....
TAOCP 7.2.1.6 Exercise 62
Section 7.2.1.6: Generating All Trees Exercise 62. [ 22 ] [22] A binary tree can also be specified by its right subtree bit strings $(l_j, r_j, r_1, \ldots, r_s)$, where $l_j$ and $r_j$ tell whether the left and right subtrees of node $j$ in preorder are nonempty. (See Theorem 2.3.1A.) Prove that if $l_1, l_s \ldots r_1, r_s$ is an arbitrary bit string where with $l_1 + \cdots + l_s...
TAOCP 7.2.2 Exercise 54
Section 7.2.2: Backtracking Exercise 54. [ M21 ] Instead of choosing each $y_i$ in step E5 with probability $1/d$, we could use a biased distribution where $\Pr{I = i \mid X_1, \ldots, X_{l-1}} = p_{X_1 \cdots X_{l-1}}(i) > 0$. How should the estimate $S$ be modified so that its expected value in this general scheme is still $C(t)$? Verified: no Solve time: 4m15s Setup We seek all integers $n <...
TAOCP 7.2.2 Exercise 53
Section 7.2.2: Backtracking Exercise 53. ▶ [ M30 ] $[M30]$ Extend Algorithm E so that it also computes the minimum, maximum, mean, and variance of the Monte Carlo estimates $S$ produced by Algorithm E. Verified: no Solve time: 4m55s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers...
TAOCP 7.2.1.6 Exercise 61
Section 7.2.1.6: Generating All Trees Exercise 61. ▶ [ M26 ] ( Raney's Cycle Lemma. ) Let $b_1 b_2 \ldots b_N$ be a string of nonnegative integers such that $f = N - b_1 - b_2 - \cdots - b_N > 0$. a) Prove that exactly $f$ of the cyclic shifts $b_{k+1} \ldots b_N b_1 \ldots b_k$ for $1 \le j \le N$ satisfy the preorder degree sequence property in...
TAOCP 7.2.2 Exercise 52
Section 7.2.2: Backtracking Exercise 52. ▶ [ HM25 ] $[HM25]$ Elmo uses Algorithm E with $D_k = {1, \ldots, n}$, $P_k = {x_1 > \cdots > x_k}$, $c = 1$. a) Alice flips $n$ coins independently, where coin $k$ yields "heads" with probability $1/k$. True or false: She obtains exactly $l$ heads with probability $\binom{n}{l}/n!$. b) Let $Y_1, Y_2, \ldots, Y_l$ be the numbers on the coins that come up...
TAOCP 7.2.1.6 Exercise 60
Section 7.2.1.6: Generating All Trees Exercise 60. ▶ [ M26 ] ( Balanced strings. ) A string $\alpha$ of nested parentheses is atomic if it has the form $(\alpha')$ where $\alpha'$ is nested; every nested string can be represented uniquely as a product of atoms $\alpha_1 \ldots \alpha_s$. A string with equal numbers of left and right parentheses is called balanced ; every balanced string can be represented uniquely as...
TAOCP 7.2.2 Exercise 51
Section 7.2.2: Backtracking Exercise 51. [ M22 ] $[M22]$ What's a simple martingale that corresponds to Theorem E? Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms among...
TAOCP 7.2.1.6 Exercise 59
Section 7.2.1.6: Generating All Trees Exercise 59. [ HM29 ] Similarly, let $T_{l_{\min}}$ count all $n$-node binary trees in which internal node $n$ appears at level $l$. Find a simple formula for $T_{nm} = \sum_{l \ge 1} T_{l_{\min}}$. Verified: no Solve time: 5m51s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.2 Exercise 50
Section 7.2.2: Backtracking Exercise 50. [ M15 ] $[M15]$ Interpret the value $E(D_1, \ldots, D_n)$ in the text's Monte Carlo algorithm. Verified: no Solve time: 5m15s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number...
TAOCP 7.2.1.6 Exercise 58
Section 7.2.1.6: Generating All Trees Exercise 58. [ HM34 ] $[HM34]$ Let $t_{mn}$ be the number of $n$-node binary trees in which each external node appears at level $l$ when the external nodes are numbered from 0 to $n$ in symmetric order. Also let $t_m = \sum_{n\ge 0} t_{mn}$, so that $t_{mn}/C_n$ is the average level of external node $m$; and let $t(w,z)$ be the super generating function $$\sum_{m,n} t_{mn}...
TAOCP 7.2.2 Exercise 49
Section 7.2.2: Backtracking Exercise 49. [ 20 ] $[20]$ Explain how the choices in Fig. 69 were determined from the "random" bits that are displayed. For instance, why was $X_4$ set to 1 in Fig. 69(b)? Verified: no Solve time: 5m43s I don’t see the exercise statement or the reviewer feedback yet. Please paste: The TAOCP exercise (or at least its full statement), and The proposed solution plus the reviewer’s...
TAOCP 7.2.2 Exercise 48
Section 7.2.2: Backtracking Exercise 48. [ M42 ] $[M42]$ Find a maximum-size commafree code of length 4 on $m = 5$ letters. Verified: yes Solve time: 1m31s Setup Let $A={1,2,3,4,5}$ and let $A^4$ be the set of all words $x_1x_2x_3x_4$ over $A$. A set $C \subseteq A^4$ is a commafree code of length $4$ if for any $u,v \in C$, the concatenation $uv$ contains no codeword of $C$ as a...
TAOCP 7.2.1.6 Exercise 57
Section 7.2.1.6: Generating All Trees Exercise 57. [ M28 ] $[M28]$ Express the sums $S_p(a,b) = \sum_{k\ge 0} \binom{2k}{k+a} \binom{2b}{b-k} k^p$ in closed form for $p = 0, 1, 2, 3$, and use these formulas to prove (30). Verified: no Solve time: 6m08s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.2 Exercise 47
Section 7.2.2: Backtracking Exercise 47. [ HM29 ] $[HM29]$ A commafree code on $m$ letters is equivalent to at most $2m!$ such codes if we permute the letters and/or replace each codeword by its left-right reflection. Determine all of the nonisomorphic commafree codes of length 4 on $m$ letters when $m$ is (a) 2 (b) 3 (c) 4 and there are (a) 3 (b) 18 (c) 57 codewords. Verified: no...
TAOCP 7.2.2 Exercise 46
Section 7.2.2: Backtracking Exercise 46. [ M35 ] $[M35]$ Is there a binary ($m = 2$) commafree code with one codeword in each of the $\bigl(\sum_{j,n} \phi(d) 2^{j/k}\bigr)/n$ cycle classes, for every word length $n$? Verified: no Solve time: 5m05s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive...
TAOCP 7.2.1.6 Exercise 56
Section 7.2.1.6: Generating All Trees Exercise 56. [ M25 ] $[M25]$ (Rényi–Szpankowski, 1990.) Prove the summation formula $$\sum_{k=0}^{m} C_k C_{n-1-k} = \frac{2n-m}{2n(n+1)} \binom{2n}{m} \binom{2n-2m}{n-m}, \quad \text{for } 0 \le m \le n.$$ Verified: no Solve time: 6m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1...
TAOCP 7.2.2 Exercise 45
Section 7.2.2: Backtracking Exercise 45. ▶ [ 28 ] $[28]$ Continuing exercise 44, spell out the details of step C3 when $x \ge 0$. a) What updates should be done to MEM when a blue word $x$ becomes red? b) What updates should be done to MEM when a blue word $x$ becomes green? c) Step C3 finishes its job by making $x$ green as in part (b). Explain how...
TAOCP 7.2.1.6 Exercise 55
Section 7.2.1.6: Generating All Trees Exercise 55. [ M33 ] $[M33]$ Evaluate $C_{pq}(1)$, the total area of all paths in exercise 46(a). Verified: no Solve time: 5m38s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.2 Exercise 44
Section 7.2.2: Backtracking Exercise 44. ▶ [ 25 ] $[25]$ Spell out the low-level implementation details of the candidate selection process in step C2 of Algorithm C. Use the routine store$(n, c)$ of (26) whenever changing the contents of MEM. Assume the following selection strategy: a) Find a class $c$ with the least number $r$ of blue words. b) If $r = 0$, set $x \leftarrow -1$; otherwise set $x$...
TAOCP 7.2.1.6 Exercise 54
Section 7.2.1.6: Generating All Trees Exercise 54. [ HM29 ] $[HM29]$ What are the mean and variance of $c_1 + \cdots + c_n$? (See exercise 46.) Verified: no Solve time: 5m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.2 Exercise 43
Section 7.2.2: Backtracking Exercise 43. [ 20 ] $[20]$ Suppose you're using the undoing scheme (26) and the operation $\sigma \leftarrow \sigma + 1$ has just bumped the current stamp $\sigma$ to zero. What should you do? Verified: no Solve time: 4m47s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution...
TAOCP 7.2.1.6 Exercise 53
Section 7.2.1.6: Generating All Trees Exercise 53. [ M28 ] $[M28]$ Let $X$ be the distance from the root of an extended binary tree to the leftmost external node. (a) What is the expected value of $X$, when all binary trees with $n$ nodes are equally likely? (b) What is the expected value of $X$ in a random binary search tree , constructed by Algorithm 6.2.2T from a random permutation...
TAOCP 7.2.2 Exercise 42
Section 7.2.2: Backtracking Exercise 42. [ 18 ] $[18]$ Why does Table 2 have (a) MEM[f8]=a7 and (b) MEM[a04]=ba? Verified: no Solve time: 5m Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.2 Exercise 41
Section 7.2.2: Backtracking Exercise 41. [ 17 ] $[17]$ What's the significance of (a) MEM[404]=5e and (b) MEM[904]=84 in Table 1? Verified: no Solve time: 4m55s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number...
TAOCP 7.2.1.6 Exercise 52
Section 7.2.1.6: Generating All Trees Exercise 52. [ M23 ] $[M23]$ Find the mean and variance of the quantity $d_n$ in Table 1, when nested parentheses $a_1 \ldots a_{2n}$ are chosen at random. Verified: no Solve time: 6m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.2 Exercise 40
Section 7.2.2: Backtracking Exercise 40. ▶ [ 15 ] $[15]$ Why do you think sequential data structures such as (16)–(23) weren't featured in Section 2.2.2 of this series of books (entitled "Sequential Allocation")? Verified: no Solve time: 5m10s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.1.6 Exercise 51
Section 7.2.1.6: Generating All Trees Exercise 51. [ M23 ] $[M23]$ Let $\hat{z}_1 \ldots \hat{z}_n$ be the $N$th combination of ${1, 2, \ldots, 2n}$ with respect to $2n$ in another words, $\hat{z}_j = 2n - z_j$, where $z_j$ is defined in (8). Show that if $\hat{z}_1 \hat{z}_2 \ldots \hat{z}_n$ is the $(N+1)$st $n$-combination of ${0, 1, \ldots, 2n-1}$ generated by Algorithm 7.2.1.3L, then $z_1 z_2 \ldots z_n$ is the $(N...
TAOCP 7.2.2 Exercise 39
Section 7.2.2: Backtracking Exercise 39. [ 18 ] $[18]$ Why can't a commafree code of length $(m^4 - m^2)/4$ contain 0001 and 2000? Verified: no Solve time: 5m06s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.1.6 Exercise 50
Section 7.2.1.6: Generating All Trees Exercise 50. [ 20 ] $[20]$ Design the inverse of Algorithm U: Given a string $a_1 \ldots a_{2n}$ of nested parentheses, determine its rank $N-1$ in lexicographic order. What is the rank of (1)? Verified: no Solve time: 5m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2 Exercise 38
Section 7.2.2: Backtracking Exercise 38. [ HM28 ] $[HM28]$ What is the probability that Eastman's algorithm finishes in one round? (Assume that $x$ is a random $m$-ary string of odd length $n > 1$, unequal to any of its other cyclic shifts. Use a generating function to express the answer.) Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2...
TAOCP 7.2.1.6 Exercise 49
Section 7.2.1.6: Generating All Trees Exercise 49. [ 17 ] $[17]$ What is the lexicographically millionth string of 15 nested parenthesis pairs? Verified: no Solve time: 5m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.2 Exercise 37
Section 7.2.2: Backtracking Exercise 37. ▶ [**] [ M 30] (W. L. Eastman, 1965.) The following elegant construction yields a commafree code of maximum size for any odd block length $n$, over any alphabet. Given a sequence $x = x_0 x_1 \ldots x_{n-1}$ of $n$ nonnegative integers, where $x$ differs from each of its other cyclic shifts $x_k \ldots x_{n-1} x_0 \ldots x_{k-1}$ for $0 < k < n$, the...
TAOCP 7.2.1.6 Exercise 48
Section 7.2.1.6: Generating All Trees Exercise 48. [ M28 ] $[M28]$ (Ruskey and Savage.) Prove that $C_{nn}(z) = (1+z)^{2n}/(1+z^{n+1}) - 1$, and use this result to show that no "perfect" Gray code for nested parentheses is possible when $n \ge 5$ is odd. Verified: no Solve time: 6m Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.2 Exercise 36
Section 7.2.2: Backtracking Exercise 36. [**] [ M 22] A two-letter block code on an $m$-letter alphabet can be represented as a digraph $D$ on $m$ vertices, with $a \to b$ if and only if $ab$ is a codeword. a) Prove that the code is commafree $\iff$ $D$ has no oriented paths of length 3. b) How many arcs can be in an $m$-vertex digraph with no oriented paths of...
TAOCP 7.2.2 Exercise 35
Section 7.2.2: Backtracking Exercise 35. ▶ [ 22 ] [22] Let $w_1, w_2, \ldots, w_n$ be four-letter words on an $m$-letter alphabet. Design an algorithm that accepts or rejects each $w_j$, according as $w_j$ is commafree or not with respect to the accepted words of ${w_1, \ldots, w_{j-1}}$. Verified: yes Solve time: 3m44s Let $A$ be an alphabet of size $m$. A set $S$ of four-letter words is commafree if...
TAOCP 7.2.1.6 Exercise 46
Section 7.2.1.6: Generating All Trees Exercise 46. [ M30 ] (Generalized Catalan numbers.) Generalize (21) by defining $$C_{pq}(x) = x^{p-q-1} C_{(p-1)q}(x) + x^{q} C_{(p-1)(q-1)}(x), \quad \text{if } 0 \le p \le q \ne 0; \quad C_{00}(x) = 1;$$ and $C_{pq}(x) = 0$ if $p < 0$ or $p > q$; thus $C_{pq} = C_{pq}(1)$. Also let $C_n(x) = C_{nn}(x)$, so that $(C_0(x), C_1(x), \ldots) = (1, 1, 1+x, 1+3x+x^2, 1+6x+6x^2+x^3,...
TAOCP 7.2.2 Exercise 34
Section 7.2.2: Backtracking Exercise 34. [ 15 ] [15] What's the largest commafree subset of the following words? aced babe bade bead beef cafe cede dada dead dear face fade feed Verified: no Solve time: 5m56s Each word has length 4. A set $S$ is commafree if for any $x,y \in S$, no word of $S$ appears as a nonaligned overlap across the boundary of $xy$. Equivalently, for $k=1,2,3$, the...
TAOCP 7.2.1.6 Exercise 45
Section 7.2.1.6: Generating All Trees Exercise 45. [ M26 ] Analyze the memory references made by the algorithm in exercise 22. How does it compare to Algorithm B? Verified: no Solve time: 5m43s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots...
TAOCP 7.2.2 Exercise 33
Section 7.2.2: Backtracking Exercise 33. [ 21 ] [21] Puzzlers who tried to construct word squares by hand found long ago that it was easier to work from bottom to top. They often compiled "reverse dictionaries," whose words appear in colex order. Does this idea speed up computer experiments? Verified: no Solve time: 2m53s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 +...
TAOCP 7.2.2 Exercise 32
Section 7.2.2: Backtracking Exercise 32. [ 22 ] [22] How many symmetric word squares of sizes $2 \times 2$, $3 \times 3$, $\ldots$, are supported by The Official SCRABBLE® Players Dictionary , fourth edition (Hasbro, 2005)? Verified: no Solve time: 5m05s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.1.6 Exercise 44
Section 7.2.1.6: Generating All Trees Exercise 44. ▶ [ M27 ] Prove that Algorithm B makes only $8\frac{1}{3} + O(n^{-1})$ references to memory per binary tree visited. Verified: no Solve time: 5m47s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge...
TAOCP 7.2.2 Exercise 31
Section 7.2.2: Backtracking Exercise 31. [ 39 ] [39] (Charles Babbage, 1864.) Do any of the symmetric $5 \times 5$ word squares also have valid words on both diagonals? Verified: no Solve time: 4m54s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.1.6 Exercise 43
Section 7.2.1.6: Generating All Trees Exercise 43. [ M11 ] Express $C_{pq}$ in terms of the Catalan numbers $C_0, C_1, C_2, \ldots$, aiming for a formula that is simple when $q - p$ is small. (For example, $C_{(p-1)q} = C_q - C_{q-1}$.) Verified: no Solve time: 5m36s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots...
TAOCP 7.2.2 Exercise 30
Section 7.2.2: Backtracking Exercise 30. [ 22 ] [22] Symmetric word squares, whose columns are the same as their rows, were popular in England during the 1850s. For example, A. De Morgan praised the square L E A V E E L L E Y A L O N E V E N E R E Y E R Y because it actually is "meaningful"! Determine the total number of...
TAOCP 7.2.1.6 Exercise 42
Section 7.2.1.6: Generating All Trees Exercise 42. [ M22 ] How many unlabeled forests with $n$ nodes are (a) self-conjugate? (b) self-transpose? (c) self-dual? (See exercises 11, 12, 19, and 26.) Verified: no Solve time: 6m09s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge...
TAOCP 7.2.2 Exercise 29
Section 7.2.2: Backtracking Exercise 29. [ 20 ] [20] Do any $5 \times 6$ word rectangles contain fewer than 11 different words? Verified: yes Solve time: 1m17s Solution Let a $5\times 6$ word rectangle be given in the sense of Section 7.2.2: there are words $R_1,\ldots,R_5$ of length $6$ (the rows) and words $C_1,\ldots,C_6$ of length $5$ (the columns) such that for all $1\le i\le 5$ and $1\le j\le 6$,...
TAOCP 7.2.2 Exercise 28
Section 7.2.2: Backtracking Exercise 28. ▶ [ 23 ] [23] The method of exercises 24 and 25 does $n$ levels of backtracking to fill the cells of an $m \times n$ rectangle one column at a time, using a trie to detect illegal prefixes in the rows. Devise a method that does $mn$ levels of backtracking and fills just one cell per level, using tries for both rows and columns....
TAOCP 7.2.1.6 Exercise 41
Section 7.2.1.6: Generating All Trees Exercise 41. [ M21 ] Show that the ballot numbers have a simple generating function $\sum C_{pq} n^p z^q$. Verified: no Solve time: 6m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.2 Exercise 27
Section 7.2.2: Backtracking Exercise 27. [ 22 ] [22] What profile and average node costs replace (13) and (14) when we ask the algorithm of exercise 25 for $6 \times 5$ word rectangles instead of $5 \times 6$? Verified: no Solve time: 3m29s I don’t have the exercise statement or the reviewer feedback yet. Please paste: The TAOCP exercise (or its full statement), and The proposed solution + the reviewer’s...
TAOCP 7.2.2 Exercise 26
Section 7.2.2: Backtracking Exercise 26. [ 21 ] [21] Can you find nice word rectangles of sizes $5 \times 7$, $5 \times 8$, $5 \times 9$, $5 \times 10$? Verified: no Solve time: 45s Understood. For each exercise, I'll write in the style of a TAOCP solution manual: Use Knuth's notation and terminology exactly as it appears in the relevant section. Give complete, rigorous proofs with every nontrivial step justified....
TAOCP 7.2.2 Exercise 25
Section 7.2.2: Backtracking Exercise 25. ▶ [ 25 ] [25] Explain how to use orthogonal lists , as in Fig. 13 of Section 7.2.6, so that it's easy to visit all 5-letter words whose $k$th character is $c$, given $1 \le k \le 5$ and $a \le c \le z$. Use those sublists to speed up the algorithm of exercise 24. Verified: yes Solve time: 48s Solution Let $W$ be...
TAOCP 7.2.1.6 Exercise 40
Section 7.2.1.6: Generating All Trees Exercise 40. [ M25 ] (a) Prove that $C_{pq}$ is odd if and only if $p\ &\ (q+1) = 0$, in the sense that the binary representations of $p$ and $q+1$ have no bits in common. (b) Therefore $C_n$ is odd if and only if $n+1$ is a power of 2. Verified: no Solve time: 6m07s Setup We seek all integers $n < 10^9$ such...
TAOCP 7.2.2 Exercise 24
Section 7.2.2: Backtracking Exercise 24. [ 20 ] [20] Customize Algorithm B so that it will find all $5 \times 6$ word rectangles. Verified: yes Solve time: 1m42s Solution A $5 \times 6$ word rectangle consists of $5$ rows, each a six-letter dictionary word, and $6$ columns, each a five-letter dictionary word. Algorithm B should therefore choose the rows as its search variables. Let $$ x_1,x_2,x_3,x_4,x_5 $$ denote the five...
TAOCP 7.2.2 Exercise 23
Section 7.2.2: Backtracking Exercise 23. [ 17 ] [17] We can often obtain one word rectangle from another by changing only a letter or two. Can you think of any $5 \times 6$ word rectangles that almost match (10)? Verified: no Solve time: 3m Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2 Exercise 22
Section 7.2.2: Backtracking Exercise 22. [ M26 ] [M26] Explore "loose Langford pairs": Replace '$j + k + 1$' in (7) by '$j + \lfloor 3k/2 \rfloor$'. Verified: no Solve time: 4m55s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge...
TAOCP 7.2.1.6 Exercise 39
Section 7.2.1.6: Generating All Trees Exercise 39. [ 22 ] Prove formula (23) by showing that the elements of $A_{pq}$ in (5) correspond to Young tableaux with two rows. Verified: no Solve time: 5m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.2 Exercise 21
Section 7.2.2: Backtracking Exercise 21. ▶ [ M25 ] [M25] If $x = x_1 x_2 \ldots x_{2n}$, let $x^D = (-x_{2n}) \ldots (-x_2)(-x_1) = -x^R$ be its dual. a) Show that if $x$ is odd and $x$ solves Langford's problem $(n)$, we have $x_k = n$ for some $k \le \lfloor n/2 \rfloor$ if and only if $x_k^D = n$ for some $k \le \lfloor n/2 \rfloor$. b) Find a...
TAOCP 7.2.1.6 Exercise 38
Section 7.2.1.6: Generating All Trees Exercise 38. [ M22 ] What is the total number of memory references performed by Algorithm L, as a function of $n$? Verified: no Solve time: 5m59s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge...
TAOCP 7.2.2 Exercise 20
Section 7.2.2: Backtracking Exercise 20. ▶ [ 21 ] [21] Extend Algorithm L so that it forces $x_l \leftarrow k$ whenever $k \notin {x_1, \ldots, x_{l-1}}$ and $l \ge 2n - k - 1$. Verified: no Solve time: 4m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers...
TAOCP 7.2.1.6 Exercise 37
Section 7.2.1.6: Generating All Trees Exercise 37. [ M40 ] Analyze the Zaks–Richards algorithm for generating all trees with a given distribution $n_0, n_1, n_2, \ldots, n_d$ of degrees (exercise 21). Hint: See exercise 2.3.4.4–32. Verified: no Solve time: 5m59s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive...
TAOCP 7.2.2 Exercise 19
Section 7.2.2: Backtracking Exercise 19. [ M10 ] [M10] What are the domains $D_l$ in Langford's problem (7)? Verified: no Solve time: 4m56s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms among...
TAOCP 7.2.2 Exercise 18
Section 7.2.2: Backtracking Exercise 18. [ 17 ] [17] Suppose that $n = 4$ and Algorithm L has reached step L2 with $l = 4$ and $x_1 x_2 x_3 = 241$. What are the current values of $x_5 x_5 x_6 x_7 x_8$, $p_0 p_1 p_2 p_3 p_4$, and $y_1 y_2 y_3$? Verified: no Solve time: 4m46s Setup We seek all integers $n < 10^9$ such that the equation $x_1 +...
TAOCP 7.2.1.6 Exercise 36
Section 7.2.1.6: Generating All Trees Exercise 36. ▶ [ M25 ] Analyze the ternary tree generation algorithm of exercise 20(b). Hint: There are $(2n+1)^{-1}\binom{3n}{n}$ ternary trees with $n$ internal nodes, by exercise 2.3.4.4–11. Verified: no Solve time: 6m03s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.2 Exercise 17
Section 7.2.2: Backtracking Exercise 17. [ 15 ] [15] Quick (a student noticed that the loop in step L2 of Algorithm L can be changed from 'while $x_j < 0$' to 'while $x_j \ne 0$', because $x_l$ cannot be positive at that point of the algorithm. So he decided to eliminate the minus signs and just set $x_{l+k+1} \leftarrow k$ in step L3. Was it a good idea? Verified: no...
TAOCP 7.2.1.6 Exercise 35
Section 7.2.1.6: Generating All Trees Exercise 35. [ HM37 ] (D. B. Tyler and D. R. Hickerson.) Explain why the denominators of the asymptotic formula (16) are all powers of 2. Verified: no Solve time: 5m48s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge...
TAOCP 7.2.2 Exercise 16
Section 7.2.2: Backtracking Exercise 16. [ 21 ] [21] Let $H(n)$ be the number of ways of keeping $n$ bees in a honeycomb so that no two are in the same line. (For example, the value of $H(4) = 7$ ways is shown here.) Compute $H(n)$ for small $n$. Verified: no Solve time: 4m46s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 +...
TAOCP 7.2.1.6 Exercise 34
Section 7.2.1.6: Generating All Trees Exercise 34. [ M25 ] (R. P. Stanley.) Show that the number of maximal chains in the Stanley lattice of order $n$ is $(n(n-1)/2)!/(1^{n-1}3^{n-2}\cdots(2n-3)^1(2n-3)!)$. Verified: no Solve time: 5m50s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.2 Exercise 15
Section 7.2.2: Backtracking Exercise 15. [ HM42 ] [HM42] (M. Simkin, 2021.) Show that $Q(n) \approx \sigma^n n!$ as $n \to \infty$, where $\sigma \approx 0.38068$. Verified: no Solve time: 4m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.1.6 Exercise 33
Section 7.2.1.6: Generating All Trees Exercise 33. ▶ [ M27 ] (Permutation representation of trees.) Let $\sigma$ be the cycle $(1\ 2\ \ldots\ n)$. a) Given any binary tree whose nodes are numbered 1 to $n$ in symmetric order, prove that there is a unique permutation $\lambda$ of ${1,\ldots,n}$ such that, for $1 \le k \le n$, $$\text{LLINK}[k] = \begin{cases} k\lambda, & \text{if } k\lambda < k \ 0, &...
TAOCP 7.2.2 Exercise 14
Section 7.2.2: Backtracking Exercise 14. [ M25 ] [M25] If exercise 12 has $T(n)$ toroidal solutions, show that $Q(mn) \ge Q(m)^2 T(n)$. Verified: no Solve time: 5m03s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.1.6 Exercise 32
Section 7.2.1.6: Generating All Trees Exercise 32. ▶ [ M30 ] [M30] Prove that if $F \dashv F'$, there is a forest $F''$ such that for all $G$ we have $$F' \sqcup G = F \quad \text{if and only if} \quad F \sqcap G \dashv F'.$$ Consequently the semidistributive laws hold in the Tamari lattice: $$F \sqcap G = F \sqcap H \quad \text{implies} \quad F \sqcap (G \sqcup H)...
TAOCP 7.2.2 Exercise 13
Section 7.2.2: Backtracking Exercise 13. [ M30 ] [M30] For which $n \ge 0$ does the $n$ queens problem have at least one solution? Verified: no Solve time: 5m06s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.6 Exercise 31
Section 7.2.1.6: Generating All Trees Exercise 31. ▶ [ M28 ] [M28] A binary tree with $n$ internal nodes is called degenerate if it has height $n$. a) How many $n$-node binary trees are degenerate? b) We've seen in Tables 1, 2, and 3 that binary trees and forests can be encoded by various $n$-tuples of numbers. For each of the encodings $c_1 \ldots c_n$, $d_1 \ldots d_n$, $e_1 \ldots...
TAOCP 7.2.2 Exercise 12
Section 7.2.2: Backtracking Exercise 12. [ M28 ] [M28] ( Wraparound queens. ) Replace (3) by the stronger conditions '$x_j \ne x_k$, $(x_k - x_j) \bmod n \ne k - j$, $(x_j - x_k) \bmod n \ne k - j$'. (The $n \times n$ grid becomes a torus.) Prove that the wraparound problem is solvable if and only if $n$ is not divisible by 2 or 3. Verified: no Solve...
TAOCP 7.2.2 Exercise 11
Section 7.2.2: Backtracking Exercise 11. [ M25 ] [M25] (W. Ahrens, 1910.) Both solutions of the $n$ queens problem when $n = 4$ have quartersurn symmetry : Rotation by 90° leaves them unchanged, but reflection doesn't. a) Can the $n$ queens problem have a solution with reflection symmetry? b) Show that quarterturn symmetry is impossible if $n \bmod 4 \in {2, 3}$. c) Sometimes the solution to an $n$ queens...
TAOCP 7.2.1.6 Exercise 30
Section 7.2.1.6: Generating All Trees Exercise 30. [ M26 ] [M26] The footprint of a forest is the bit string $f_1 \ldots f_n$ defined by $$f_j = [\text{node } j \text{ in preorder is not a leaf}].$$ a) If $F$ has footprint $f_1 \ldots f_n$, what is the footprint of $F^{D_2}$? (See exercise 27.) b) Two forests having the footprint 10101101111100001010100010110000? c) Prove that $f_j = [d_j = 0]$, for...
TAOCP 7.2.2 Exercise 10
Section 7.2.2: Backtracking Exercise 10. ▶ [ 22 ] [22] Adapt Algorithm W to the $n$ queens problem, using bitwise operations on $n$-bit numbers as suggested in the text. Verified: no Solve time: 5m09s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.1.6 Exercise 29
Section 7.2.1.6: Generating All Trees Exercise 29. [ HM31 ] [HM31] The covering graph of a Tamari lattice is sometimes known as an "associahedron," because of its connection with the associative law (§4), proved in exercise 27(b). The associahedron of order 4, depicted in Fig. 61, looks like it has three square faces and six faces that are regular pentagons. (Compare with Fig. 43 in exercise 7.2.1.2.60, which shows the...
TAOCP 7.2.2 Exercise 9
Section 7.2.2: Backtracking Exercise 9. [ 21 ] [21] Can a $4n$-queen placement have $4n$ queens on "white" squares? Verified: no Solve time: 5m03s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.1.6 Exercise 28
Section 7.2.1.6: Generating All Trees Exercise 28. [ M26 ] [M26] (The Stanley lattice.) Continuing exercises 26 and 27, let us define yet another partial ordering on $n$-node forests, saying that $F \sqsubseteq F'$ whenever the depth coordinates $c_1, \ldots, c_n$ and $c'_1, \ldots, c'_n$ satisfy $c_j \le c'_j$ for $1 \le j \le n$. (See Fig. 62.) a) Prove that this partial ordering is a lattice, by explaining how...
TAOCP 7.2.2 Exercise 8
Section 7.2.2: Backtracking Exercise 8. [ 20 ] [20] Are there two 8-queen placements with the same $x_1 x_2 x_3 x_4 x_5 x_6$? Verified: no Solve time: 5m Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.1.6 Exercise 27
Section 7.2.1.6: Generating All Trees Exercise 27. ▶ [ M35 ] [M35] (The Tamari lattice.) Continuing exercise 26, let us write $F \dashv F'$ if the $j$th node in preorder has at least as many descendants in $F'$ as it does in $F$, for all $j$. In other words, if $F$ and $F'$ are characterized by their scope sequences $s_1, \ldots, s_n$ and $s'_1, \ldots, s'_n$ as in Table 2,...
TAOCP 7.2.2 Exercise 7
Section 7.2.2: Backtracking Exercise 7. [ 20 ] [20] (T. B. Sprague, 1890.) Are there any values $n > 5$ for which the $n$ queens problem has a "framed" solution with $x_1 = 2$, $x_2 = n$, $x_{n-1} = 1$, and $x_n = n - 1$? Verified: no Solve time: 5m13s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n...
TAOCP 7.2.1.6 Exercise 26
Section 7.2.1.6: Generating All Trees Exercise 26. [ M31 ] [M31] (The Kreweras lattice.) Let $F$ and $F'$ be $n$-node forests with their nodes numbered 1 to $n$ in preorder. We write $F \prec F'$ ($F$ coalesces $F''$) if $j$ and $k$ are siblings in $F$ whenever they are siblings in $F'$, for $1 \le j < k \le n$. Figure 60 illustrates this partial ordering in the case $n...
TAOCP 7.2.2 Exercise 6
Section 7.2.2: Backtracking Exercise 6. [ 20 ] [20] Given $r$, with $1 \le r \le 8$, in how many ways can 7 nonattacking queens be placed on an $8 \times 8$ chessboard, if no queen is placed in row $r$? Verified: no Solve time: 5m02s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$...
TAOCP 7.2.1.6 Exercise 25
Section 7.2.1.6: Generating All Trees Exercise 25. ▶ [ 20 ] [20] (Pruning and grafting.) Representing binary trees as in Algorithm B, design an algorithm that visits all link tables $l_0 \ldots l_n$ and $r_1 \ldots r_n$ in such a way that, between visits, exactly one link changes from $j$ to 0 and another from 0 to $j$, for some index $j$. (In other words, every step removes some subtree...
TAOCP 7.2.2 Exercise 5
Section 7.2.2: Backtracking Exercise 5. [ 20 ] [20] Reformulate Algorithm B as a recursive procedure called $\textit{try}(l)$, having global variables $n$ and $x_1, \ldots x_n$, to be invoked by saying '$\textit{try}(1)$'. Can you imagine why the author of this book decided not to present the algorithm in such a recursive form? Verified: no Solve time: 4m19s Setup We seek all integers $n < 10^9$ such that the equation $x_1...
TAOCP 7.2.2 Exercise 4
Section 7.2.2: Backtracking Exercise 4. [ 16 ] [16] Using a chessboard and eight coins to represent queens, one can follow the steps of Algorithm B and essentially traverse the tree of Fig. 68 by hand in about three hours. Invent a trick to save half of the work. Verified: no Solve time: 4m01s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 +...
TAOCP 7.2.1.6 Exercise 24
Section 7.2.1.6: Generating All Trees Exercise 24. [ 22 ] [22] Using the notation of Table 3, what sequences $l_0 l_1 \ldots l_{15}$, $r_1 \ldots r_{15}$, $k_1 \ldots k_{15}$, $q_1 \ldots q_{15}$, and $u_1 \ldots u_{15}$ correspond to the binary tree $(4)$ and the forest $(2)$? Verified: no Solve time: 5m41s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n...
TAOCP 7.2.2 Exercise 3
Section 7.2.2: Backtracking Exercise 3. [ 20 ] [20] Let $T$ be any tree. Is it possible to define domains $D_k$ and cutoff properties $P_l(x_1, \ldots, x_l)$ so that $T$ is the backtrack tree traversed by Algorithm B? Verified: no Solve time: 5m12s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.1.6 Exercise 23
Section 7.2.1.6: Generating All Trees Exercise 23. [ 25 ] [25] (a) What is the last string visited by Algorithm N? (b) What is the last binary tree or forest visited by Algorithm L? Hint: See exercise 40 below. Verified: no Solve time: 5m43s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.2 Exercise 2
Section 7.2.2: Backtracking Exercise 2. [ 10 ] [10] True or false: We can choose $D_j$ so that $P_l(x_l)$ is always true. Verified: no Solve time: 5m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.1.6 Exercise 22
Section 7.2.1.6: Generating All Trees Exercise 22. ▶ [ 20 ] [20] (J. Korsh, 2004.) As an alternative to Algorithm B, show that binary trees can also be generated directly and efficiently in linked form if we produce them in order order of the numbers $d_1 \ldots d_{n-1}$ defined in (9). (The actual values of $d_1 \ldots d_{n-1}$ should not be computed explicitly; but the links $l_1 \ldots l_n$ and...
TAOCP 7.2.2 Exercise 1
Section 7.2.2: Backtracking Exercise 1. ▶ [ 22 ] [22] Explain how the tasks of generating (i) $n$-tuples, (ii) permutations of distinct items, (iii) combinations, (iv) integer partitions, (v) set partitions, and (vi) nested parentheses can all be regarded as special cases of backtrack programming, by presenting suitable domains $D_k$ and cutoff properties $P_l(x_1, \ldots, x_l)$ that satisfy (1) and (2). Verified: no Solve time: 5m09s Setup We seek all...
TAOCP 7.2.1.6 Exercise 21
Section 7.2.1.6: Generating All Trees Exercise 21. ▶ [ 26 ] [26] (S. Zaks and D. Richards, 1979.) Continuing exercise 20, explain how to generate the preorder degree sequences of all forests that have $N = n_0 + \cdots + n_k$ nodes, with exactly $n_j$ nodes of degree $j$. For example, when $n_0 = 4$, $n_1 = n_2 = n_3 = 1$, and $t = 3$, and the valid sequences...
TAOCP 7.2.1.6 Exercise 20
Section 7.2.1.6: Generating All Trees Exercise 20. [ 25 ] [25] Recall from Section 2.3 that the degree of a node in a tree is the number of children it has, and that an extended binary tree is characterized by the property that every node has degree either 0 or 2. In the extended binary tree (4), the sequence of node degrees is 22002220222022002002230220; in preorder, this string of 0s...
TAOCP 7.2.1.6 Exercise 19
Section 7.2.1.6: Generating All Trees Exercise 19. [ 28 ] [28] Let $F_1, F_2, \ldots, F_N$ be the sequence of unlabeled forests that correspond to the rooted plane trees generated by Algorithm P, and let $G_1, G_2, \ldots, G_N$ be the sequence of unlabeled forests that correspond to the binary trees generated by Algorithm B. Prove that $G_k = F_k^{PTB}$, in the notation of exercises 11 and 12. (The forest...
TAOCP 7.2.1.6 Exercise 18
Section 7.2.1.6: Generating All Trees Exercise 18. [ 30 ] [30] Two forests are said to be cognate if one can be obtained from the other by repeated operations of taking the conjugate and/or the transpose. The examples in exercises 11 and 12 show that all forests on 4 nodes belong to one of three cognate classes: $$\bullet \bullet \bullet \bullet = \begin{cases} \uparrow \ \end{cases}, \quad \underset{\displaystyle\uparrow}{\uparrow} \times =...
TAOCP 7.2.1.6 Exercise 17
Section 7.2.1.6: Generating All Trees Exercise 17. [ M16 ] [M16] Characterize all unlabeled forests $F$ such that $F^{BT} = F^{TR}$. (See exercise 14.) Verified: no Solve time: 5m45s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.6 Exercise 16
Section 7.2.1.6: Generating All Trees Exercise 16. [ 20 ] [20] If $F$ and $G$ are forests, let $FG$ be the forest obtained by placing the trees of $F$ to the left of the trees of $G$; also let $F{G = (G^T F^T)^T}$. Give an intuitive explanation of the operator ${$, and prove that it is associative. Verified: no Solve time: 5m59s Setup We seek all integers $n < 10^9$...
TAOCP 7.2.1.6 Exercise 15
Section 7.2.1.6: Generating All Trees Exercise 15. [ 20 ] [20] Suppose $B$ is the binary tree obtained from a forest $F$ by linking each node to its left sibling and its rightmost child, as in exercise 2.3.2–5 and the last column of Table 2. Let $F'$ be the forest that corresponds to $B$ in the normal way, via left-child and right-sibling links. Prove that $F' = F^{BT}$, in the...
TAOCP 7.2.1.6 Exercise 14
Section 7.2.1.6: Generating All Trees Exercise 14. ▶ [ 21 ] [21] Find all labeled forests $F$ such that $F^{BT} = F^{TR}$. Verified: no Solve time: 5m37s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.1.6 Exercise 13
Section 7.2.1.6: Generating All Trees Exercise 13. [ 20 ] [20] Continuing exercises 11 and 12, how do the preorder and postorder of a labeled forest $F$ relate to the preorder and postorder of (a) $F^{@}$ (b) $F^T$? Verified: no Solve time: 5m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.1.6 Exercise 124
Section 7.2.1.6: Generating All Trees Exercise 124. ▶ [ 40 ] [40] Experiment with methods for drawing extended binary trees that are inspired by simple models from nature. For example, we can assign a value $v(x)$ to each node $x$, called its Horton–Strahler number , as follows: Each external (leaf) node has $v(x) = 0$; an internal node with children $(l, r)$ has $v(x) = \max(v(l), v(r)) + [v(l) =...
TAOCP 7.2.1.6 Exercise 123
Section 7.2.1.6: Generating All Trees Exercise 123. [ 21 ] [21] Continuing the previous exercise, what are the smallest positive integers that cannot be represented using conventions (a), (b), (c)? Fig. 63. "Organic" illustrations of binary trees. Verified: no Solve time: 5m51s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution...
TAOCP 7.2.1.6 Exercise 122
Section 7.2.1.6: Generating All Trees Exercise 122. ▶ [ 31 ] [31] (Dudency's Digital Century puzzle.) There are many curious ways to obtain the number 100 by inserting arithmetical operators and possibly also parentheses into the sequence 123456789. For example, $$100 = 1 + 2 \times 3 + 4 \times 5 - 6 + 7 + 8 \times 9 = (1 + 2 - 3 - 4) \times (5 -...
TAOCP 7.2.1.6 Exercise 121
Section 7.2.1.6: Generating All Trees Exercise 121. [ M34 ] [M34] (F. Neuman, 1964.) The derivative of a graph $G$ is the graph $G^{(1)}$ obtained by removing all vertices of degree 1 and the edges touching them. Prove that, when $T$ is a free tree, its square $T^2$ contains a Hamiltonian path if and only if its derivative has no vertex of degree greater than 4 and the following two...
TAOCP 7.2.1.6 Exercise 120
Section 7.2.1.6: Generating All Trees Exercise 120. [ 22 ] [22] True or false: The square of a graph is Hamiltonian if the graph is connected and has no bridges. Verified: no Solve time: 6m Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2...
TAOCP 7.2.1.6 Exercise 12
Section 7.2.1.6: Generating All Trees Exercise 12. [ 15 ] [15] If $F$ is a forest, its transpose $F^T$ is the forest whose binary tree is obtained by interchanging left and right links in the binary tree representing $F$. For example, the transposes of the fourteen forests in Table 1 are respectively $$\underset{}{\bullet} \quad \underset{}{\bullet}\underset{}{\bullet} \quad \underset{}{\bullet}!\overset{}{\bullet} \quad \underset{}{\bullet\bullet\bullet} \quad \cdots$$ What is the transpose of the forest (2)? Verified:...
TAOCP 7.2.1.6 Exercise 119
Section 7.2.1.6: Generating All Trees Exercise 119. [ 21 ] [21] The twisted binomial tree $T_n$ of order $n$ is defined recursively by the rules $$\tilde{T}_0 = \bullet,, \qquad \tilde{T} n = \underbrace{\quad 0 \quad 1 \quad \cdots \quad n-1 \quad} {\tilde{T}_0^{(0)} \quad \tilde{T} 1^{(1)} \quad \cdots \quad \tilde{T} {n-1}^{(n-1)}} \quad \text{for } n > 0.$$ (Compare with 7.2.1.3–(2); we reverse the order of children on alternate levels.) Show that...
TAOCP 7.2.1.6 Exercise 118
Section 7.2.1.6: Generating All Trees Exercise 118. [ M28 ] [M28] How many lucky nodes are present in (a) the complete $t$-ary tree with $(t^k - 1)/(t - 1)$ internal nodes? (b) the Fibonacci tree of order $k$, with $F_{k+1} - 1$ internal nodes? (See 2.3.4.5–(6) and Fig. 8 in Section 6.2.1.) Verified: no Solve time: 5m48s Setup We seek all integers $n < 10^9$ such that the equation $x_1...
TAOCP 7.2.1.6 Exercise 117
Section 7.2.1.6: Generating All Trees Exercise 117. [ 21 ] [21] Continuing exercise 116, how many $n$-node forests contain no unlucky nodes? Verified: no Solve time: 5m39s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.1.6 Exercise 116
Section 7.2.1.6: Generating All Trees Exercise 116. ▶ [ 28 ] The nodes of a forest $F$ are labeled $1$ to $n$ in prepostorder; say that node $k$ is lucky if it is adjacent to node $k+1$ in $F$, unlucky if it is three steps away, and ordinary otherwise, for $1 \le k \le n$; in this definition, node $n+1$ is an imaginary super-root considered to be the parent of...
TAOCP 7.2.1.6 Exercise 115
Section 7.2.1.6: Generating All Trees Exercise 115. [ 20 ] Analyze Algorithm Q: How often is each step performed, during the complete traversal of a forest? Verified: no Solve time: 5m32s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.1.6 Exercise 114
Section 7.2.1.6: Generating All Trees Exercise 114. [ 15 ] If we want to traverse an entire forest in prepostorder using Algorithm Q, how should we begin the process? Verified: no Solve time: 5m07s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.1.6 Exercise 113
Section 7.2.1.6: Generating All Trees Exercise 113. ▶ [ 20 ] How do prepostorder and postpreorder of a forest $F$ relate to prepostorder and postpreorder of the extended forest $F^E$? (See exercise 13.) Verified: no Solve time: 3m39s Solution Let $F$ be a forest with $n$ nodes and let $F^E$ be its extended forest, formed by adjoining a new root node $\rho$ whose children are the roots of the trees...
TAOCP 7.2.1.6 Exercise 112
Section 7.2.1.6: Generating All Trees Exercise 112. [ 15 ] If node $p$ of a forest precedes node $q$ in prepostorder and follows it in postpreorder, what can you say about $p$ and $q$? Verified: no Solve time: 5m41s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers...
TAOCP 7.2.1.6 Exercise 111
Section 7.2.1.6: Generating All Trees Exercise 111. [ 05 ] List the nodes of the tree (58) in postpreorder. Verified: no Solve time: 5m44s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.1.6 Exercise 110
Section 7.2.1.6: Generating All Trees Exercise 110. ▶ [ M27 ] Prove that if $G$ is any connected multigraph without self-loops, it has $$c(G) \ge \sqrt{(d_1 - 1) \cdots (d_n - 1)}$$ spanning trees, where $d_j$ is the degree of vertex $j$. Verified: no Solve time: 5m50s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots...
TAOCP 7.2.1.6 Exercise 11
Section 7.2.1.6: Generating All Trees Exercise 11. [ 11 ] [11] If $F$ is a forest, its conjugate $F^{@}$ is obtained by left-to-right mirror reflection. For example, the fourteen forests in Table 1 are respectively $$\bullet \quad \bullet\bullet \quad \bullet,\text{\textasciicircum}!\bullet \quad \bullet\bullet\bullet \quad \bullet,\text{\textasciicircum}!\bullet\bullet \quad \text{...}$$ and their conjugates are respectively $$\bullet\bullet\bullet\bullet \quad \bullet\bullet,\text{\textasciicircum} \quad \text{...}$$ as in the colex forests of Table 2. If $F$ corresponds to the nested...
TAOCP 7.2.1.6 Exercise 109
Section 7.2.1.6: Generating All Trees Exercise 109. [ M46 ] Find a combinatorial explanation for the fact that (57) is the number of spanning trees in the $n$-cube. Verified: no Solve time: 5m56s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots...
TAOCP 7.2.1.6 Exercise 108
Section 7.2.1.6: Generating All Trees Exercise 108. [ HM40 ] Extend the results of exercises 104–106 to directed graphs. Verified: no Solve time: 5m36s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.1.6 Exercise 107
Section 7.2.1.6: Generating All Trees Exercise 107. [ M24 ] Determine the aspects of all connected graphs that have $n \le 5$ vertices and no self-loops or parallel edges. Verified: no Solve time: 5m28s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.1.6 Exercise 106
Section 7.2.1.6: Generating All Trees Exercise 106. ▶ [ HM7 ] Find the total number of spanning trees in (a) an $m \times n$ grid $P_m \mathbin{\square} P_n$; (b) an $m \times n$ cylinder $P_m \mathbin{\square} C_n$; (c) an $m \times n$ torus $C_m \mathbin{\square} C_n$. Do these numbers tend to have many small prime factors? Hint: Show that the numbers for $P_n$ and $C_n$ can be expressed as $4\sin^2\frac{j\pi}{2n}$...
TAOCP 7.2.1.6 Exercise 105
Section 7.2.1.6: Generating All Trees Exercise 105. [ HM18 ] Continuing exercise 104, we wish to prove that there is often an easy way to determine the aspects of $G$ when $G$ has been constructed from other graphs whose aspects are known. Suppose $G'$ has aspects $\alpha' 0, \ldots, \alpha' {s'-1}$ and $G''$ has aspects $\alpha'' 0, \ldots, \alpha'' {s''-1}$; what are the aspects of $G$ in the following cases?...
TAOCP 7.2.1.6 Exercise 104
Section 7.2.1.6: Generating All Trees Exercise 104. ▶ [ HM21 ] If $G$ is a graph on $n$ vertices ${V_1, \ldots, V_n}$, with $e_{ij}$ edges between $V_i$ and $V_j$, let $C(G)$ be the matrix with entries $c_{ij} = -e_{ij} + \delta_{ij} d_i$, where $d_i = e_{i1} + \cdots + e_{in}$ is the degree of $V_i$. Let us say that the aspects of $G$ are the eigenvalues of $C(G)$, namely the...
TAOCP 7.2.1.6 Exercise 103
Section 7.2.1.6: Generating All Trees Exercise 103. ▶ [ HM39 ] ( Sandpiles. ) Consider any digraph $D$ on vertices $V_0, V_1, \ldots, V_n$ with $e_{ij}$ arcs from $V_i$ to $V_j$, where $e_{ii} = 0$. Assume that $D$ has at least one oriented spanning tree rooted at $V_0$; this assumption means that, if we number the vertices appropriately, we have $e_{i0} + \cdots + e_{i,(i-1)} > 0$ for $1 \le...
TAOCP 7.2.1.6 Exercise 102
Section 7.2.1.6: Generating All Trees Exercise 102. [ 46 ] An oriented spanning tree of a directed graph $D$ on $n$ vertices, also known as a "spanning arborescence," is an oriented subtree of $D$ containing $n-1$ arcs. The matrix tree theorem (exercise 2.3.4.2–19) tells us that the oriented subtrees having a given root can readily be counted by evaluating an $(n-1) \times (n-1)$ determinant. Can those oriented subtrees be listed...
TAOCP 7.2.1.6 Exercise 101
Section 7.2.1.6: Generating All Trees Exercise 101. [ 46 ] Is there a simple revolving-door way to list all $n^{n-2}$ spanning trees of the complete graph $K_n$? (The order produced by Algorithm S is quite complicated.) Verified: no Solve time: 5m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.1.6 Exercise 100
Section 7.2.1.6: Generating All Trees Exercise 100. [ 40 ] Implement the text's "Algorithm S*" for revolving-door generation of all spanning trees, by combining Algorithm S with the ideas of exercise 99. Verified: no Solve time: 5m38s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1...
TAOCP 7.2.1.6 Exercise 10
Section 7.2.1.6: Generating All Trees Exercise 10. [ M20 ] [M20] ( Worm walks. ) Given a string of nested parentheses $a_1 a_2 \ldots a_{2n}$, let $w_j$ be the excess of left parentheses over right parentheses in $a_1 a_2 \ldots a_j$, for $0 \le j \le 2n$. Prove that $w_0 + w_1 + \cdots + w_{2n} = 2(c_1 + \cdots + c_n) + n$. Verified: no Solve time: 5m49s Setup...
TAOCP 7.2.1.6 Exercise 9
Section 7.2.1.6: Generating All Trees Exercise 9. [ M26 ] [M26] Show that the tables $c_1 \ldots c_n$ and $s_1 \ldots s_n$ are related by the law: $$c_k = \lfloor s_2 k - 1 \rfloor + \lfloor s_2 k - 2 \rfloor + \cdots + \lfloor s_2 k - 2 \rfloor + \cdots + \lfloor s_{k-1} \ge 1 \rfloor.$$ Verified: no Solve time: 5m54s Setup We seek all integers $n...
TAOCP 7.2.1.6 Exercise 8
Section 7.2.1.6: Generating All Trees Exercise 8. [ 15 ] [15] What tables $t_1 \ldots t_n$, $r_1 \ldots r_n$, $e_1 \ldots e_n$, and $s_1 \ldots s_n$ correspond to the example forest (2)? Verified: no Solve time: 5m46s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1...
TAOCP 7.2.1.6 Exercise 7
Section 7.2.1.6: Generating All Trees Exercise 7. [ 16 ] [16] (a) What is the state of the string $a_1 a_2 \ldots a_{2n}$ when Algorithm P terminates? (b) What do the arrays $l_1 l_2 \ldots l_n$ and $r_1 r_2 \ldots r_n$ contain when Algorithm B terminates? Verified: no Solve time: 5m30s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n...
TAOCP 7.2.1.6 Exercise 6
Section 7.2.1.6: Generating All Trees Exercise 6. ▶ [ 20 ] [20] What matching corresponds to (1)? (See the final column of Table 1.) Verified: no Solve time: 5m50s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.6 Exercise 5
Section 7.2.1.6: Generating All Trees Exercise 5. [ 15 ] [15] What tables $d_1 \ldots d_n$, $z_1 \ldots z_n$, $p_1 \ldots p_n$, and $c_1 \ldots c_n$ correspond to the nested parenthesis string (1)? Verified: no Solve time: 5m54s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying...
TAOCP 7.2.1.6 Exercise 4
Section 7.2.1.6: Generating All Trees Exercise 4. [ 20 ] [20] True or false: If the strings $a_1 \ldots a_{2n}$ are generated in lexicographic order, so are the corresponding tables $d_1 \ldots d_n$, $z_1 \ldots z_n$, $p_1 \ldots p_n$, and $c_1 \ldots c_n$. Verified: no Solve time: 4m57s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.1.6 Exercise 3
Section 7.2.1.6: Generating All Trees Exercise 3. ▶ [ 23 ] [23] Prove that (11) converts $z_1 z_2 \ldots z_n$ to the inversion table $c_1 c_2 \ldots c_n$. Verified: no Solve time: 5m50s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots...
TAOCP 7.2.1.6 Exercise 2
Section 7.2.1.6: Generating All Trees Exercise 2. [ 20 ] [20] (S. Zaks, 1980.) Modify Algorithm P so that it produces the combinations $z_1 z_2 \ldots z_n$ of (8) instead of the parenthesis strings $a_1 a_2 \ldots a_{2n}$. Verified: no Solve time: 5m49s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one...
TAOCP 7.2.1.6 Exercise 1
Section 7.2.1.6: Generating All Trees Exercise 1. [ 15 ] [15] If a worm crawls around the binary tree (4), how could it easily reconstruct the parentheses of (1)? Verified: no Solve time: 5m46s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge...
TAOCP 7.2.1.5 Exercise 82
Section 7.2.1.5: Generating All Set Partitions Exercise 82. [ 22 ] In how many ways can the following 15 dominoes, optionally rotated, be partitioned into three sets of five having the same sum when regarded as fractions? Just as in a single body there are pairs of individual members, called by the same name but distinguished as right and left, so when my speeches had postulated the notion of madness,...
TAOCP 7.2.1.5 Exercise 81
Section 7.2.1.5: Generating All Set Partitions Exercise 81. [ 29 ] Find a way to arrange an ordinary deck of 52 playing cards so that the following trick is possible: Five players each cut the deck (applying a cyclic permutation) as often as they like. Then each player takes a card from the top. A magician tells them to look at their cards and to form affinity groups, joining with...
TAOCP 7.2.1.5 Exercise 80
Section 7.2.1.5: Generating All Set Partitions Exercise 80. [ M25 ] Prove that universal sequences for ${1, 2, \ldots, n}$ exist in the sense of the previous exercise whenever $n \ge 4$. Verified: no Solve time: 5m48s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1...
TAOCP 7.2.1.5 Exercise 79
Section 7.2.1.5: Generating All Set Partitions Exercise 79. ▶ [ 22 ] A sequence $u_1, u_2, u_3, \ldots$ is called universal for partitions of ${1, \ldots, n}$ if its subsequences $(u_{m+1}, u_{m+2}, \ldots, u_{m+n})$ for $0 \le m \le \infty$, represent all possible set partitions under the convention "$*j = k$ if and only if $u_{m+j} = u_{m+k}$." For example, $(0, 0, 0, 1, 0, 2, 2)$ is a universal...
TAOCP 7.2.1.5 Exercise 78
Section 7.2.1.5: Generating All Set Partitions Exercise 78. [ 20 ] What partition of $(15, 10, 10, 11)$ leads to the permutations $\alpha_1$, $\alpha_2$, $\alpha_3$, and $\alpha_4$ shown in Table 1? Verified: no Solve time: 5m29s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge...
TAOCP 7.2.1.5 Exercise 77
Section 7.2.1.5: Generating All Set Partitions Exercise 77. [ HM46 ] Find the asymptotic value of $p(n, \ldots, n)$ when there are $n$ $n$s. Verified: no Solve time: 5m47s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.5 Exercise 76
Section 7.2.1.5: Generating All Set Partitions Exercise 76. [ HM16 ] Find the asymptotic value of $p(2, \ldots, 2)$ when there are $2n$ 2s. Verified: no Solve time: 5m46s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.5 Exercise 75
Section 7.2.1.5: Generating All Set Partitions Exercise 75. [ HM21 ] Find the asymptotic value of $p(n, n)$. Verified: no Solve time: 5m58s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms among...
TAOCP 7.2.1.5 Exercise 74
Section 7.2.1.5: Generating All Set Partitions Exercise 74. [ M46 ] Can $p(n, \ldots, n)$ be evaluated in polynomial time when there are $n$ $n$s? Verified: no Solve time: 5m51s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let...
TAOCP 7.2.1.5 Exercise 73
Section 7.2.1.5: Generating All Set Partitions Exercise 73. [ M33 ] Can $p(2, \ldots, n)$ be evaluated in polynomial time when there are $2n$? Verified: no Solve time: 9m18s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.5 Exercise 72
Section 7.2.1.5: Generating All Set Partitions Exercise 72. [ M26 ] Can $p(1, \ldots, n)$ be evaluated in polynomial time? Verified: no Solve time: 5m38s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of...
TAOCP 7.2.1.5 Exercise 71
Section 7.2.1.5: Generating All Set Partitions Exercise 71. [ M20 ] How many partitions of ${n_1, \ldots, n_m, m}$ have exactly 2 parts? Verified: no Solve time: 5m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.1.5 Exercise 70
Section 7.2.1.5: Generating All Set Partitions Exercise 70. [ M32 ] Analyze the number of $r$-block partitions possible in the $n$-element multisets (a) ${0, \ldots, 0; 1}$; (b) ${1, 2, \ldots, n-1}$. What is the total, summed over $r$? Verified: no Solve time: 5m33s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly...
TAOCP 7.2.1.5 Exercise 69
Section 7.2.1.5: Generating All Set Partitions Exercise 69. [ 22 ] Modify Algorithm M so that it produces only partitions into at most $r$ parts. Verified: no Solve time: 4m28s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let...
TAOCP 7.2.1.5 Exercise 68
Section 7.2.1.5: Generating All Set Partitions Exercise 68. [ 21 ] How large can variables $l$ and $b$ get in Algorithm M, when that algorithm is generating all $p(n_1, \ldots, n_t)$ partitions of ${1, \ldots, n}$? Verified: no Solve time: 4m36s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in...
TAOCP 7.2.1.5 Exercise 67
Section 7.2.1.5: Generating All Set Partitions Exercise 67. [ HM20 ] What are the mean and variance of $M$ in Stan's method (53)? Verified: no Solve time: 5m33s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.1.5 Exercise 66
Section 7.2.1.5: Generating All Set Partitions Exercise 66. [ M46 ] What partition of $n$ leads to the most partitions of ${1, \ldots, n}$? Verified: no Solve time: 5m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.5 Exercise 65
Section 7.2.1.5: Generating All Set Partitions Exercise 65. [ HM32 ] What is the variance of the number of blocks of size $k$ in a random partition of ${1, \ldots, n}$? Verified: no Solve time: 5m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge...
TAOCP 7.2.1.5 Exercise 64
Section 7.2.1.5: Generating All Set Partitions Exercise 64. [ HM41 ] Prove the approximate ratios following (36) and exercise 50. Verified: no Solve time: 6m20s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of...
TAOCP 7.2.1.5 Exercise 63
Section 7.2.1.5: Generating All Set Partitions Exercise 63. ▶ [ M35 ] (J. Pitman.) Prove that there is an elementary way to locate the maximum Stirling numbers, and many similar quantities, as follows: Suppose $0 \le p_k \le 1$. a) Let $f(z) = (1 + p_1(z-1)) \cdots (1 + p_n(z-1))$ and $a_k = [z^k] f(z)$; thus $a_k$ is the probability that $k$ heads turn up after $n$ independent coin flips...
TAOCP 7.2.1.5 Exercise 62
Section 7.2.1.5: Generating All Set Partitions Exercise 62. [ HM40 ] Prove rigorously that $\binom{n}{m}$ is maximum either when $m = \lceil e^{-1}n \rceil$ or when $m = \lfloor e^{-1}n \rfloor$. Verified: no Solve time: 5m29s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge...
TAOCP 7.2.1.5 Exercise 61
Section 7.2.1.5: Generating All Set Partitions Exercise 61. [ HM26 ] Prove that if $m = n - r$ where $r \le n^*$ and $z \le n^{1/2}$, Eq. (43) yields $$\left{ n \atop n-r \right} = \frac{n^{2r}}{2^r r!} \left(1 + O(n^{2r-1}) + O!\left(\frac{1}{r}\right)\right).$$ Verified: no Solve time: 5m50s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2...
TAOCP 7.2.1.5 Exercise 60
Section 7.2.1.5: Generating All Set Partitions Exercise 60. [ HM21 ] (a) Show that the partial sums in the identity $$\left{ n \atop m \right} = \frac{m^n}{m!} - \frac{(m-1)^n}{1!(m-1)!} + \frac{(m-2)^n}{2!(m-2)!} - \cdots + (-1)^n \frac{0^n}{n!0!}$$ alternately overestimate and underestimate the final value. (b) Calculate $\binom{10}{5}$. (c) Derive a similar result from (43). Verified: no Solve time: 6m03s Setup We seek all integers $n < 10^9$ such that the equation...
TAOCP 7.2.1.5 Exercise 59
Section 7.2.1.5: Generating All Set Partitions Exercise 59. ▶ [ HM25 ] What does (43) predict for the approximate value of $\binom{n}{m}$? Verified: no Solve time: 5m37s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the...
TAOCP 7.2.1.5 Exercise 45
Section 7.2.1.5: Generating All Set Partitions Exercise 45. ▶ [ HM23 ] Show that, in addition to (26), we also have the expansion $$\varpi_n = \frac{e^{e^t - 1}}{t^n \sqrt{2\pi(t+1)}} \Biggl( 1 + \frac{b_1'}{n} + \frac{b_2'}{n^2} + \cdots + \frac{b_m'}{n^m} + O!\left(\frac{1}{n^{m+1}}\right) \Biggr),$$ where $b_1' = -(2t^4 + 9t^3 + 6t^2 + 6t + 2)/(24(t+1)^3)$. Verified: no Solve time: 5m32s Setup We seek all integers $n < 10^9$ such that the...
TAOCP 7.2.1.5 Exercise 44
Section 7.2.1.5: Generating All Set Partitions Exercise 44. [ HM22 ] Explain how to compute $b_1, b_2, \ldots$ in (26) from $a_2, a_3, \ldots$ in (25). Verified: no Solve time: 5m31s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$....
TAOCP 7.2.1.5 Exercise 43
Section 7.2.1.5: Generating All Set Partitions Exercise 43. [ HM22 ] Justify replacing the integral in (23) by (25). Verified: no Solve time: 5m26s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.1.5 Exercise 42
Section 7.2.1.5: Generating All Set Partitions Exercise 42. [ HM23 ] Use the saddle point method to estimate $[z^{n-1}] e^{z^2}$ with relative error $O(1/n^2)$. Verified: no Solve time: 5m36s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$...
TAOCP 7.2.1.5 Exercise 41
Section 7.2.1.5: Generating All Set Partitions Exercise 41. [ HM21 ] Solve the previous exercise when $c = -1$. Verified: no Solve time: 5m53s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number of terms...
TAOCP 7.2.1.5 Exercise 40
Section 7.2.1.5: Generating All Set Partitions Exercise 40. [ HM20 ] Suppose the saddle point method is used to estimate $[z^{n-1}] e^z$. The text's derivation of (21) from (20) deals with the case $c = 1$; how should that derivation change if $c$ is an arbitrary positive constant? Verified: no Solve time: 5m52s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots...
TAOCP 7.2.1.5 Exercise 39
Section 7.2.1.5: Generating All Set Partitions Exercise 39. [ HM18 ] Evaluate $\int_0^\infty e^{-pt^q} t^r , dt$ when $p$ and $q$ are nonnegative integers. Hint: See exercise 1.2.5–20. Verified: no Solve time: 5m41s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots...
TAOCP 7.2.1.5 Exercise 38
Section 7.2.1.5: Generating All Set Partitions Exercise 38. ▶ [ M30 ] Let $\sigma_k$ be the cyclic permutation $(1, 2, \ldots, k)$. The object of this exercise is to study the sequences $k_1 k_2 \ldots k_n$, called $\sigma$-cycles, for which $\sigma_{k_1} \sigma_{k_2} \ldots \sigma_{k_n}$ is the identity permutation. For example, when $n = 4$ there are exactly 15 $\sigma$-cycles, namely $$1111,\ 1122,\ 1212,\ 1221,\ 1333,\ 2112,\ 2121,\ 2211,\ 2222,\ 2323,\...
TAOCP 7.2.1.5 Exercise 37
Section 7.2.1.5: Generating All Set Partitions Exercise 37. [ M18 ] Alexander Pushkin adopted an elaborate structure in his poetic novel Eugene Onegin (1833), based not only on "masculine" rhymes in which the sounds of accented final syllables agree with each other (pain–rain, form–warm, pun–fun, bucks–crux), but also on "feminine" rhymes in which one or two unstressed syllables also participate (humor–tumor, tetrameter–pentameter, lecture–conjecture, iguana–piranha). Every stanza of Eugene Onegin is...
TAOCP 7.2.1.5 Exercise 36
Section 7.2.1.5: Generating All Set Partitions Exercise 36. [ M21 ] [M21] Continuing exercise 35, what is the generating function $\sum_n \varpi'_n z^n/n!$? Verified: no Solve time: 5m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be...
TAOCP 7.2.1.5 Exercise 35
Section 7.2.1.5: Generating All Set Partitions Exercise 35. [ M22 ] [M22] Let $\varpi'_n$ be the number of $n$-line poems that are "completely rhymed," in the sense that every line rhymes with at least one other. Then we have $(\varpi'_0, \varpi'_1, \varpi'_2, \ldots) = (1, 0, 1, 1, 4, 11, 41, \ldots)$. Give a combinatorial proof of the fact that $\varpi' n = \varpi' {n+1} - \varpi_n$. Verified: no Solve...
TAOCP 7.2.1.5 Exercise 34
Section 7.2.1.5: Generating All Set Partitions Exercise 34. [ 14 ] [14] Many poetic forms involve rhyme schemes , which are partitions of the lines of a stanza with the property that $j \equiv k$ if and only if line $j$ rhymes with line $k$. For example, a "limerick" is generally a 5-line poem with certain rhythmic constraints and with a rhyme scheme described by the restricted growth string $00110$....
TAOCP 7.2.1.5 Exercise 33
Section 7.2.1.5: Generating All Set Partitions Exercise 33. [ M21 ] [M21] How many partitions of ${1, 2, \ldots, n}$ are there in which every block has at most $k-1$ elements, where $n \bmod 6 = (1, 2, 3, 4, 5, 0)$? Prove that $\delta_n = (-1, 0, -1, 0, 1, 0)$ when $n \bmod 6 = (1, 2, 3, 4, 5, 0)$. Verified: no Solve time: 5m41s Setup We...
TAOCP 7.2.1.5 Exercise 32
Section 7.2.1.5: Generating All Set Partitions Exercise 32. [ M22 ] [M22] Let $\delta_n$ be the number of restricted growth strings $a_1 \ldots a_n$ for which the sum $a_1 + \cdots + a_n$ is even minus the number for which $a_1 + \cdots + a_n$ is odd. Prove that $$\delta_n = (-1,, 0,, -1,, 0,, 1,, 0) \quad \text{when } n \bmod 6 = (1,, 2,, 3,, 4,, 5,, 0).$$...
TAOCP 7.2.1.5 Exercise 31
Section 7.2.1.5: Generating All Set Partitions Exercise 31. [ HM21 ] [HM21] Generalizing (15), show that the elements of Peirce's triangle have a simple generating function, if we compute the sum $$\sum_n \varpi_n(x, y) \frac{z^{n-k}}{(n-k)!,(k-1)!}.$$ Verified: no Solve time: 4m30s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive...
TAOCP 7.2.1.5 Exercise 30
Section 7.2.1.5: Generating All Set Partitions Exercise 30. [ HM30 ] [HM30] The generalized Stirling number $\begin{Bmatrix}n\m\end{Bmatrix}_q$ is defined by the recurrence $$\begin{Bmatrix}n+1\m\end{Bmatrix}_q = (1+q+\cdots+q^{m-1})\begin{Bmatrix}n\m\end{Bmatrix}_q + \begin{Bmatrix}n\m-1\end{Bmatrix}_q, \qquad \begin{Bmatrix}0\m\end{Bmatrix} q = \delta {m0}.$$ Thus $\begin{Bmatrix}n\m\end{Bmatrix}_q$ is a polynomial in $q$ and $\begin{Bmatrix}n\m\end{Bmatrix}_1 = \begin{Bmatrix}n\m\end{Bmatrix}$, because it satisfies the recurrence relation in Eq. 1.2.6--(46). a) Prove that the generalized Stirling number $\varpi_n(x, y) = R(n-1, \ldots, 1)$ of exercise 28(e) has...
TAOCP 7.2.1.5 Exercise 29
Section 7.2.1.5: Generating All Set Partitions Exercise 29. [ M26 ] [M26] Continuing the previous exercise, let $H_r(a_1, \ldots, a_m) = [x^r] R(a_1, \ldots, a_m)$ be the polynomial in $y$ that enumerates free cells when $r$ rooks are placed. a) Show that the number of ways to place $r$ rooks on an $m \times n$ board, leaving $f$ cells free, is the number of permutations of ${1, \ldots, n}$ that...
TAOCP 7.2.1.5 Exercise 28
Section 7.2.1.5: Generating All Set Partitions Exercise 28. ▶ [ M25 ] [M25] ( Generalized rook polynomials. ) Consider an arrangement of $a_1 + a_2 + \cdots + a_k$ square cells in rows and columns, where row $k$ contains cells in columns $1, \ldots, a_k$. Place zero or more "rooks" into the cells, with at most one rook in each row and at most one in each column. An empty...
TAOCP 7.2.1.5 Exercise 27
Section 7.2.1.5: Generating All Set Partitions Exercise 27. ▶ [ M35 ] [M35] A "vacillating tableau loop" of order $n$ is a sequence of integer partitions $\lambda_0 = \alpha_1 \alpha_2 \alpha_3 \ldots$ with $\alpha_1 \ge \alpha_2 \ge \alpha_3 \ge \cdots$ for $0 \le k \le 2n$, such that $\lambda_0 = \lambda_{2n} = \epsilon_0$ and $\lambda_i = \lambda_{i-1} + \epsilon_j$ for some $j$, with $0 \le j \le n$, here $\epsilon_j$...
TAOCP 7.2.1.5 Exercise 26
Section 7.2.1.5: Generating All Set Partitions Exercise 26. [ M2 ] [M2] According to the recurrence equations (13), the numbers $\varpi_{nk}$ in Peirce's triangle count the paths from $\binom{0}{0}$ to $\binom{n}{k}$ in the infinite directed graph Explain why each path from $\binom{0}{0}$ to $\binom{n}{k}$ corresponds to a partition of ${1, \ldots, n}$. Verified: no Solve time: 5m43s Setup We seek all integers $n < 10^9$ such that the equation $x_1...
TAOCP 7.2.1.5 Exercise 25
Section 7.2.1.5: Generating All Set Partitions Exercise 25. [ M32 ] [M32] Prove that $\varpi_n / \varpi_{n-1} \le \varpi_{n+1} / \varpi_n \le \varpi_{n+1} / \varpi_n + 1$. Verified: no Solve time: 5m43s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge...
TAOCP 7.2.1.5 Exercise 24
Section 7.2.1.5: Generating All Set Partitions Exercise 24. [ HM35 ] [HM35] Continuing the previous exercise, because the Bell numbers satisfy the periodic law $\varpi_{n+p^{p-1} \cdot N} \equiv \varpi_n \pmod{p^r}$, if $p$ is an odd prime. [ Hint: Show that $$x^p \equiv g_{r}(x) + p^{r-1} g_{r-1}(x) + \cdots + g_1(x) \pmod{p^r}$$ where $g_r(x) = g_r(x, p^{r-1}g_{r-1}(x), \ldots, p \cdot g_1(x))$ and $g_s(x) = (x^p - x)^s$.] Verified: no Solve time:...
TAOCP 7.2.1.5 Exercise 23
Section 7.2.1.5: Generating All Set Partitions Exercise 23. [ HM30 ] [HM30] If $f(z) = \sum_{k} a_k z^k$ is a polynomial, let $\hat{f}(\varpi)$ stand for $\sum a_k \varpi_k$. a) Prove the symbolic formula $f(\varpi + 1) = \pi \hat{f}(\varpi)$. (For example, if $f(x)$ is the polynomial $x^2$, this formula states that $\varpi_2 + 2\varpi_1 + \varpi_0 = \varpi_2$.) b) Similarly, prove that $f(\varpi + k) = \pi^k \hat{f}(\varpi)$ for all...
TAOCP 7.2.1.5 Exercise 22
Section 7.2.1.5: Generating All Set Partitions Exercise 22. [ M2 ] [M2] If $X$ is a random variable with a given distribution, the expected value of $X^n$ is called the $n$th moment of that distribution. What is the $n$th moment when $X$ is (a) a Poisson deviate with mean 1 [Eq. 3.4.1–(40)]? (b) the number of fixed points of a random permutation of ${1, \ldots, m}$, when $m \ge n$...
TAOCP 7.2.1.5 Exercise 21
Section 7.2.1.5: Generating All Set Partitions Exercise 21. [ M27 ] [M27] How many partitions of ${1, \ldots, n}$ are self-conjugate? Verified: no Solve time: 5m42s Setup We seek all integers $n < 10^9$ such that the equation $x_1 + x_2 + \cdots + x_n = x_1 x_2 \cdots x_n$ has exactly one solution in positive integers satisfying $x_1 \ge x_2 \ge \cdots \ge x_n$. Let $k$ be the number...