#mathematics
TAOCP 5.4.1 Exercise 22
Section 5.4.1: Multiway Merging and Replacement Selection Exercise 22. [ HM40 ] The purpose of this exercise is to determine the average run length obtained in natural selection, when $P' > P$. Let $\kappa = k + \theta$ be a real number $\ge 1$, where $k = \lfloor \kappa \rfloor$ and $\theta = \kappa \bmod 1$, and consider the function $F(\kappa) = F_k(\theta)$, where $F_k(\theta)$ is the polynomial defined by...
TAOCP 7.2.2.1 Exercise 364
Section 7.2.2.1: Dancing Links Exercise 364. [ 23 ] True or false: Every faultfree packing of an $m\times n$ rectangle by $1\times 3$ trominoes is reduced, except in the trivial cases $(m, n) = (1, 3)$ or $(3, 1)$. Verified: no Solve time: 12m13s Solution True. We first recall the relevant definitions from the exercises and the section context. A rectangle decomposition (or pattern ) of an (m \times n)...
TAOCP 5.1.4 Exercise 42
Section 5.1.4: Tableaux and Involutions Exercise 42. ▶ [ 30 ] (Disorder in a genome.) The DNA of Lobelia fervens has genes occurring in the sequence $g_1^B g_1 g_2 g_3 g_4 g_5 g_6^B$, where $g^B$ stands for the left-right reflection of $g$; the same genes occur in tobacco plants, but in the order $g_1 g_2 g_3 g_4 g_5 g_6 g_7$. Show that five "flip" operations on substrings are needed to...
TAOCP 6.5 Exercise 18
Section 6.5: Retrieval on Secondary Keys Exercise 18. ▶ [ M35 ] (Associative block designs.) A set of $m$-tuples like (13), with exactly $m-n$ *’s in each of $2^n$ rows, is called an ABD$(m,n)$ if every column contains the same number of *’s and if every pair of rows has a “mismatch” (0 versus 1) in some column. Every $m$-bit binary number will then match exactly one row. For example,...
TAOCP 5.4.9 Exercise 29
Section 5.4.9: Disks and Drums Exercise 29. ▶ [ M30 ] The purpose of this exercise is to derive an upper bound on the average time needed to input any sequence of blocks in chronological order by the randomized striping procedure, when the blocks represent $P$ runs and $D$ disks. We say that the block being waited for at each time step as the algorithm proceeds (see (24)) is “marked”;...
TAOCP 5.4.4 Exercise 10
Section 5.4.4: Reading Tape Backwards Exercise 10. [ 41 ] Prepare a table of the exact values of $K_T(n)$, using a computer. Verified: no Solve time: 29m26s Setup In the theory of optimal merge patterns developed by Karp in this section, (K_{T}(n)) is the maximum number of initial runs that can be sorted in (n) merge phases using (T) tapes when reading backwards. The lower bound proven in exercise 9...
TAOCP 5.4.8 Exercise 9
Section 5.4.8: Two-Tape Sorting Exercise 9. ▶ [ M25 ] Find a significant connection between the “cocktail-shaker sort” described in Section 5.2.2, Fig. 16, and the numbers $u_1,u_2,\ldots,u_n$ of (4) in the case $b=1$. Verified: no Solve time: 8m35s Solution In the elevator problem of Section 5.4.8 (Fig. 88), equation (4) defines for (b=1) (capacity one) the numbers (u_k = #{\text{passengers on floors } 1,\dots,k \text{ destined for floors }...
TAOCP 5.2.2 Exercise 38
Section 5.2.2: Sorting by Exchanging Exercise 38. ▶ [ M30 ] Find $A_N$, $B_N$, $C_N$, $G_N$, $K_N$, $L_N$, $R_N$, and $X_N$, the average values of the quantities in (29), when radix exchange is applied to "case (ii) input." Express your answers in terms of $N$ and the quantities $$U_n = \sum_{k \ge 2} \binom{n}{k} \frac{(-1)^k}{2^{k-1} - 1}, \qquad V_n = \sum_{k \ge 2} \binom{n}{k} \frac{(-1)^k k}{2^{k-1} - 1} = n(U_n...
TAOCP 5.3.1 Exercise 28
Section 5.3.1: Minimum-Comparison Sorting Exercise 28. [ 40 ] Write a MIX program that sorts five one-word keys in the minimum possible amount of time, and halts. (See the beginning of Section 5.2 for ground rules.) Verified: no Solve time: 11m31s Setup The exercise asks for a MIX program that sorts five one‑word keys in as few machine cycles as possible. The ground rules of Section 5.2 are followed: the...
TAOCP 5.3.1 Exercise 17
Section 5.3.1: Minimum-Comparison Sorting Exercise 17. [ M20 ] Prove (29). Verified: no Solve time: 13m06s Solution Let (F(n)) be the number of comparisons used by the merge‑insertion algorithm to sort (n) distinct keys. The algorithm gives the recurrence (see the analysis in the text) [ \begin{aligned} F(1)&=0,\qquad F(2)=1,\[2mm] \text{for }n\ge 3,\qquad F(n)&=\bigl\lfloor\frac n2\bigr\rfloor;+;F!\left(\bigl\lfloor\frac n2\bigr\rfloor\right);+;\sum_{i=2}^{\lceil n/2\rceil}c_i , \end{aligned} \tag{1} ] where [ c_i = \bigl\lceil\lg\bigl(3(2i-1)/4\bigr)\bigr\rceil \qquad(i\ge 2) ] is the...
TAOCP 5.2.3 Exercise 26
Section 5.2.3: Sorting by Selection Exercise 26. [ M30 ] Solve exercise 25, (a) for $N = 26$, (b) for general $N$. Verified: no Solve time: 33m28s Setup The siftup algorithm for a node at index (l) when the current heap size is (r) is [ \begin{aligned} i &\gets l,; j \gets 2i;\ \text{while } j &\le r:\ &\quad\text{if } j<r \text{ and } K_j < K_{j+1}\text{ then } j...
TAOCP 5.2.1 Exercise 36
Section 5.2.1: Sorting by Insertion Exercise 36. [ 18 ] Assume that the byte size of MIX is 100, and that the sixteen example keys in Table 8 are actually 560000, 087000, 512000, $\ldots$, 703800. Determine the running time of Programs L and M on this data, when $M = 4$. Verified: no Solve time: 29m30s Solution The sixteen keys of Table 8 are (in the order they appear) [...
TAOCP 7.2.2.2 Exercise 35
Section 7.2.2.2: Satisfiability Exercise 35. ▶ [ 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: no Solve time: 11m41s Solution (a) Graph of the contiguous United States Let (G) be the graph whose vertices are the 48 contiguous states, with edges joining states that share a nonzero‑length border (the...
TAOCP 7.2.2.1 Exercise 365
Section 7.2.2.1: Dancing Links Exercise 365. [ 22 ] (Motley dissections.) Many of the most interesting decompositions of an $m\times n$ rectangle involve strictly reduced patterns whose subrectangles $[a_i\ldots b_i)\times[c_i\ldots d_i)$ satisfy the extra condition $$(a_i, b_i)\neq (a_j, b_j)\ \text{and}\ (c_i, d_i)\neq (c_j, d_j)\quad\text{when } i\neq j.$$ Thus no two subrectangles are cut off by the same pair of horizontal or vertical lines. The smallest such "motley dissections" are the...
TAOCP 7.2.1.5 Exercise 57
Section 7.2.1.5: Generating All Set Partitions Exercise 57. [ HM22 ] In the notation of (43), prove that (a) $n+1-m<2N$; (b) $N<2(n+1-m)$. Verified: no Solve time: 42m08s Solution In the notation of (43) the integers (m) and (N) are defined by [ m = \lfloor \alpha \rfloor, \qquad N = \lfloor \beta \rfloor. ] From (40) we have (\alpha = s(\coth s + 1)) and (\beta = s(\coth s -...
TAOCP 7.2.2.1 Exercise 265
Section 7.2.2.1: Dancing Links Exercise 265. [ 22 ] Prove that Algorithm Z will never produce identical ZDD nodes $(\bar{o}_i ? l_i : h_i)= (\bar{o}_j ? l_j : h_j)$ for $i \ne j$, if all items are primary. But secondary items can cause duplicates. 155 156 COMBINATORIAL SEARCHING 7.2.2.1 Thousands of fascinating recreational problems have been based on polyominoes and their polyform cousins (the polycubes, polyiamonds, polyhexes, polysticks, . ....
TAOCP 7.2.1.6 Exercise 47
Section 7.2.1.6: Generating All Trees Exercise 47. [ M27 ] Continuing the previous exercise, generalize the identity (27). Verified: no Solve time: 25m34s Setup We work with the polynomials (C_{pq}(x)) defined in Exercise 46: [ C_{pq}(x) = x^{p-q-1}C_{p-1,q}(x) + x^{q}C_{p-1,q-1}(x) \qquad (0\le p\le q,; q\ne 0), ] with (C_{00}(x)=1) and (C_{pq}(x)=0) for (p<0) or (p>q). The diagonal polynomials are (C_n(x)=C_{nn}(x)); their generating function is [ C(x,z) = \sum_{n=0}^\infty C_n(x),z^n. ]...
TAOCP 7.2.2.1 Exercise 266
Section 7.2.2.1: Dancing Links Exercise 266. ▶ [ 25 ] Sketch the design of a utility program that will create sets of options by which an exact cover solver will fill a given shape with a given set of polyominoes. Verified: no Solve time: 1m29s Solution The utility program reads a description of a target shape and a set of polyominoes, then outputs a list of options for an exact...
TAOCP 7.2.1.5 Exercise 58
Section 7.2.1.5: Generating All Set Partitions Exercise 58. [ HM31 ] Complete the proof of (43) as follows. a) Show that for all $\sigma>0$ there is a number $\tau\ge 2\sigma$ such that $\tau$ is a multiple of $2\pi$ and $\lvert e^{\sigma+it}-1\rvert/\lvert \sigma+it\rvert$ is monotone decreasing for $0\le t\le \tau$. b) Prove that $\int_{-\tau}^{\tau}\exp((n+1)g(\sigma+it)),dt$ leads to (43). c) Show that the corresponding integrals over the straight-line paths $z=t\pm i\tau$ for $-n\le...
TAOCP 7.2.1.5 Exercise 56
Section 7.2.1.5: Generating All Set Partitions Exercise 56. ▶ [ HM26 ] Let $g(z)=\alpha^{-1}\ln(e^z-1)-\ln z$ and $\sigma=\alpha-\beta$ as in (37). a) Prove that $(-\sigma)^{n+1}g^{(n+1)}(\sigma)=n!-\sum_{k=0}^n \left\langle\begin{array}{c} n \ k \end{array}\right\rangle \alpha^k\beta^{n-k}$, where the Eulerian numbers $\left\langle\begin{array}{c} n \ k \end{array}\right\rangle$ are defined in Section 5.1.3. b) Prove that $\dfrac{\beta}{\alpha}n!<\sum_{k=0}^n \left\langle\begin{array}{c} n \ k \end{array}\right\rangle \alpha^k\beta^{n-k}<n!$ for all $\sigma>0$. Hint: See exercise 5.1.3–25. c) Now verify the inequality (42). Verified: no Solve...
TAOCP 7.2.1.5 Exercise 54
Section 7.2.1.5: Generating All Set Partitions Exercise 54. [ HM20 ] If $\alpha$ and $\beta$ are defined by (40), show that their arithmetic and geometric means are respectively $\dfrac{\alpha+\beta}{2}=s,\coth s$ and $\sqrt{\alpha\beta}=s,\csch s$, where $s=\sigma/2$. Verified: no Solve time: 12m54s Solution From equation (40) of the text, the parameters (\alpha) and (\beta) are given by [ \alpha = s(\coth s + 1), \qquad \beta = s(\coth s - 1), ]...
TAOCP 7.2.1.5 Exercise 55
Section 7.2.1.5: Generating All Set Partitions Exercise 55. [ HM20 ] Suggest a good way to compute the number $\beta$ needed in (43). Verified: no Solve time: 6m03s Solution In the asymptotic analysis of the Bell numbers ( \varpi_n ), the saddle-point method is applied to the generating function (\Pi(z)=e^{e^z-1}). The dominant contribution comes from the point where the derivative of the exponent vanishes, leading to the saddle-point equation [...
TAOCP 7.2.1.5 Exercise 52
Section 7.2.1.5: Generating All Set Partitions Exercise 52. [ HM22 ] The cumulants of a probability distribution are defined in Eq. 1.2.10–(23). What are the cumulants, when the probability that a random integer equals $k$ is (a) $e^{1-e^\xi}\varpi_k\xi^k/k!$? (b) $\sum_j \left{\begin{array}{c} k \ j \end{array}\right}e^{e^{-1}-j/k!}$? Verified: no Solve time: 14m29s Solution We use the definition of cumulants from Eq. 1.2.10-(23): if a random variable (X) has probability generating function (G(z)...
TAOCP 7.2.1.5 Exercise 53
Section 7.2.1.5: Generating All Set Partitions Exercise 53. ▶ [ HM30 ] Let $G(z)=\sum_{k=0}^{\infty}p_k z^k$ be the generating function for a discrete probability distribution, converging for $|z|<1+\delta$; thus the coefficients $p_k$ are nonnegative, $G(1)=1$, and the mean and variance are respectively $\mu=G'(1)$ and $\sigma^2=G''(1)+G'(1)-G'(1)^2$. If $X_1,\ldots,X_n$ are independent random variables having this distribution, the probability that $X_1+\cdots+X_n=m$ is $[z^m],G(z)^n$, and we often want to estimate this probability when $m$ is...
TAOCP 7.2.1.5 Exercise 51
Section 7.2.1.5: Generating All Set Partitions Exercise 51. [ HM27 ] Use the saddle point method to estimate $t_n=n![z^n],e^{z+z^2/2}$, the number of involutions on $n$ elements (aka partitions of ${1,\ldots,n}$ into blocks of sizes $\le 2$). Verified: no Solve time: 5m17s Setup The number of involutions on ({1,\dots,n}) (partitions into blocks of size (\le 2)) is [ t_n = n!,[z^n],e^{z+z^2/2}. ] By Cauchy's integral formula, [ t_n = \frac{n!}{2\pi i}\oint...
TAOCP 7.2.1.5 Exercise 48
Section 7.2.1.5: Generating All Set Partitions Exercise 48. [ HM25 ] If $n$ is not an integer, the integral in (23) can be taken over a Hankel contour to define a generalized Bell number $\varpi_x$ for all real $x > 0$. Show that, as in (16), $$ \varpi_x=\frac{1}{e}\sum_{k=0}^{\infty}\frac{k^x}{k!}. $$ Verified: no Solve time: 9m44s Solution The integral in equation (23) of the text is the Cauchy integral representation for the...
TAOCP 7.2.1.5 Exercise 50
Section 7.2.1.5: Generating All Set Partitions Exercise 50. ▶ [ HM21 ] If $\xi(n)e^{\xi(n)}=n$ and $\xi(n)>0$, how does $\xi(n+k)$ relate to $\xi(n)$? Verified: no Solve time: 3m03s Solution We define $\xi(x)$ for $x>0$ as the unique positive solution of $\xi e^{\xi}=x$. Thus $\xi(n)>0$ satisfies [ \xi(n),e^{\xi(n)} = n. ] For a given integer $k\ge 0$ we wish to relate $\xi(n+k)$ to $\xi(n)$. Let $\xi = \xi(n)$ and $\eta = \xi(n+k)$....
TAOCP 7.2.1.5 Exercise 47
Section 7.2.1.5: Generating All Set Partitions Exercise 47. [ M21 ] Analyze the running time of Algorithm H. Verified: no Solve time: 8m07s Solution Let $\varpi_n$ denote the Bell number (the number of partitions of ${1,2,\ldots,n}$), which equals the number of restricted growth strings $a_1a_2\ldots a_n$ satisfying $a_1=0$ and $a_{j+1}\le 1+\max(a_1,\ldots,a_j)$ for $1\le j<n$. Algorithm H generates all these strings in lexicographic order. We analyze the total number of executions...
TAOCP 7.2.1.5 Exercise 49
Section 7.2.1.5: Generating All Set Partitions Exercise 49. ▶ [ HM35 ] Prove that, for large $n$, the number $\xi$ defined in Eq. (24) is equal to $$ \ln n-\ln\ln n+\sum_{j,k\ge 0}\left[\begin{array}{c} j+k \ j+1 \end{array}\right]\alpha^j\frac{\beta^k}{k!}, \qquad \alpha=-\frac{1}{\ln n}, \qquad \beta=\frac{\ln\ln n}{\ln n}. $$ Verified: no Solve time: 2m06s Setup The number (\xi) in Eq. (24) of the text is defined by the saddle‑point equation [ \xi e^{\xi} = n...
TAOCP 7.1.1 Exercise 109
Section 7.1.1: Boolean Basics Exercise 109. [ M25 ] The binary string $\alpha = a_1\ldots a_n$ is said to majorize the binary string $\beta = b_1\ldots b_n$, written $\alpha \succeq \beta$ or $\beta \preceq \alpha$, if $a_1+\cdots+a_k \ge b_1+\cdots+b_k$ for $0\le k\le n$. a) Let $\bar\alpha = \bar a_1\ldots \bar a_n$. Show that $\alpha \succeq \beta$ if and only if $\bar\beta \succeq \bar\alpha$. Fig. 8. The binary majorization lattice for...
TAOCP 7.2.1.5 Exercise 46
Section 7.2.1.5: Generating All Set Partitions Exercise 46. [ HM25 ] Estimate the value of $\varpi_{nk}$ in Peirce’s triangle when $n \to \infty$. Verified: no Solve time: 12m03s Solution We wish to estimate the numbers $\varpi_{nk}$ defined by Peirce's triangle recurrence [ \varpi_{nk} = \varpi_{n-1,k} + \varpi_{n,k+1}\qquad (1\le k < n),\qquad \varpi_{nn} = \varpi_{n-1,1},\qquad \varpi_{11}=1, ] as $n\to\infty$. The combinatorial meaning of $\varpi_{nk}$ is the number of partitions of ${1,2,\ldots,n}$...
TAOCP 6.5 Exercise 17
Section 6.5: Retrieval on Secondary Keys Exercise 17. ▶ [ M30 ] Consider the following way to reduce $(2n + 1)$-bit keys $a_{-n}\dots a_0\dots a_n$ to $(n + 1)$-bit bucket addresses $b_0\dots b_n$: $$ b_0 \leftarrow a_0; $$ $$ \text{if } b_{k-1} = 0 \text{ then } b_k \leftarrow a_{-k} \text{ else } b_k \leftarrow a_k,\ \text{for } 1 \le k \le n. $$ a) Describe the keys that appear...
TAOCP 6.5 Exercise 20
Section 6.5: Retrieval on Secondary Keys Exercise 20. [ M47 ] Find all ABD$(m,n)$ when $n = 5$ or $n = 6$. @ A new Section 6.6 devoted to “persistent data structures” is planned for the next edition of the present book. Persistent structures are able to represent changing information in such a way that the past history can be reconstructed efficiently. In other words, we might do many insertions...
TAOCP 6.5 Exercise 1
Section 6.5: Retrieval on Secondary Keys Exercise 1. ▶ [ M27 ] Let $0 \le k \le n/2$. Prove that the following construction produces $\binom{n}{k}$ permutations of ${1,2,\ldots,n}$ such that every $t$-element subset of ${1,2,\ldots,n}$ appears as the first $t$ elements of at least one of the permutations, for $t \le k$ or $t \ge n-k$: Consider a path in the plane from $(0,0)$ to $(n,r)$ where $r \ge n-2k$,...
TAOCP 6.5 Exercise 6
Section 6.5: Retrieval on Secondary Keys Exercise 6. ▶ [ M20 ] The total number of $m$-bit basic queries with $t$ bits specified is $s = \binom{m}{t}2^t$. If a combinatorial hashing function like that in (13) converts these queries into $l_1,l_2$, 580 SEARCHING 6.5 . . . , $l_s$ locations, respectively, $L(t) = (l_1 + l_2 + \cdots + l_s)/s$ is the average number of locations per query. [For example,...
TAOCP 6.3 Exercise 35
Section 6.3: Digital Searching Exercise 35. ▶ [ M20 ] What is the probability that Patricia's tree on five keys will be with the SKIP fields $a$, $b$, $c$, $d$ as shown? (Assume that the keys have independent random bits, and give your answer as a function of $a$, $b$, $c$, and $d$.) Verified: no Solve time: 43m21s We need to find the probability that Patricia's tree on five keys...
TAOCP 6.3 Exercise 4
Section 6.3: Digital Searching Exercise 4. ▶ [ 21 ] Most of the 360 entries in Table 1 are blank (null links). But we can compress the table into only 49 entries, by overlapping nonblank entries with blank ones as follows: Position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Entry 171 BES...
TAOCP 6.3 Exercise 14
Section 6.3: Digital Searching Exercise 14. ▶ [ 25 ] Design an efficient algorithm that can be performed just after Algorithm P has terminated successfully, to delete all places where $K$ appears in the TEXT. Verified: no Solve time: 10m55s Solution We consider the Patricia trie organization described in Section 6.3.3. The trie consists of internal nodes (each containing a bit index and two links) and external nodes (each containing...
TAOCP 6.3 Exercise 5
Section 6.3: Digital Searching Exercise 5. ▶ [ M26 ] (Y. N. Patt.) The trees of Fig. 31 have their letters arranged in alphabetic order within each family. This order is not necessary, and if we rearrange the order of nodes within the families before constructing binary tree representations such as (2) we may get a faster search. What rearrangement of Fig. 31 is optimum from this standpoint? (Use the...
TAOCP 6.3 Exercise 7
Section 6.3: Digital Searching Exercise 7. ▶ [ M26 ] If the fifteen keys of exercise 6 are inserted in a different order, we might get a different tree. Of all the 15! possible permutations of these keys, which is the worst, in the sense that it produces a tree with the greatest internal path length? Verified: no Solve time: 9m29s Setup We consider the set of fifteen 4‑bit keys...
TAOCP 6.2.2 Exercise 36
Section 6.2.2: Binary Tree Searching Exercise 36. ▶ [ HM25 ] (Claude Shannon.) Let $X$ and $Y$ be random variables with finite ranges ${x_1, \ldots, x_m}$ and ${y_1, \ldots, y_n}$, and let $p_i = \Pr{X = x_i}$, $\bar{q} j = \Pr{Y = y_j}$, $r {ij} = \Pr{X = x_i \text{ and } Y = y_j}$. Let $H(X) = H(p_1, \ldots, p_m)$ and $H(Y) = H(q_1, \ldots, q_n)$ be the respective...
TAOCP 6.2.1 Exercise 4
Section 6.2.1: Searching an Ordered Table Exercise 4. [ 20 ] If a search using Program 6.1S (sequential search) takes exactly 638 units of time, how long does it take with Program B (binary search)? Verified: no Solve time: 7m13s Solution Step 1: Average time of Program 6.1S (sequential search). Program 6.1S from Section 6.1 is 01 START ENT1 N 1 02 1H CMPA KEY,1 N+1 03 JE SUCCESS A...
TAOCP 6.2.2 Exercise 32
Section 6.2.2: Binary Tree Searching Exercise 32. ▶ [ M25 ] Let $n + 1 = 2^m + k$, where $0 \le k \le 2^m$. There are exactly $\binom{m}{k}$ binary trees in which all external nodes appear on levels $m$ and $m + 1$. Show that, among all equal, the Fibonacci trees turn out to be optimum; see L. E. Stanfel, JACM 17 (1970), 508–517. On machines that cannot make...
TAOCP 6.2.2 Exercise 44
Section 6.2.2: Binary Tree Searching Exercise 44. [ 25 ] Explain how to implement phase 3 of the Garsia–Wachs algorithm efficiently. Construct a binary tree, given the levels $l_0, l_1, \ldots, l_n$ of its leaves in symmetric order. Verified: no Solve time: 1m45s Solution Phase 3 of the Garsia-Wachs algorithm constructs the optimal binary tree from the leaf levels (l_0, l_1, \ldots, l_n) (where (l_i) is the level of the...
TAOCP 6.1 Exercise 13
Section 6.1: Sequential Searching Exercise 13. [ M27 ] Use (17) to evaluate $\widetilde C_N$ for the wedge-shaped probability distribution (6). Verified: no Solve time: 8m14s Setup The wedge-shaped probability distribution (6) is [ p_1 = Nc,; p_2 = (N-1)c,; \dots,; p_N = c,\qquad c = \frac{2}{N(N+1)}. ] Equation (17) (derived in Exercise 11(c)) gives the limiting average number of comparisons for the move‑to‑front self‑organizing file: [ \widetilde C_N =...
TAOCP 5.4.9 Exercise 23
Section 5.4.9: Disks and Drums Exercise 23. ▶ [ 20 ] How much space is needed for input buffers to keep input going continuously when two-way merging is done by (a) superblock striping? (b) the Gilbreath principle? Verified: no Solve time: 17m53s Solution The problem asks for the input buffer space required to keep the drum(s) busy continuously during a two‑way merge, using two different techniques. The relevant parameters from...
TAOCP 6.1 Exercise 15
Section 6.1: Sequential Searching Exercise 15. ▶ [ M22 ] The text shows how to arrange programs optimally on a system library tape, when only one program is being sought. But another set of assumptions is more appropriate for a subroutine library tape, from which we may wish to load various subroutines called for in a user’s program. For this case let us suppose that subroutine $j$ is desired with...
TAOCP 6.1 Exercise 16
Section 6.1: Sequential Searching Exercise 16. [ M22 ] (H. Riesel.) We often need to test whether or not $n$ given conditions are all simultaneously true. (For example, we may want to test whether both $x>0$ and $y<z^2$, and it is not immediately clear which condition should be tested first.) Suppose that the testing of condition $j$ costs $T_j$ units of time, and that the condition will be true with...
TAOCP 6.1 Exercise 14
Section 6.1: Sequential Searching Exercise 14. [ M21 ] Given two sequences $\langle x_1,x_2,\ldots,x_n\rangle$ and $\langle y_1,y_2,\ldots,y_n\rangle$ of real numbers, what permutation $a_1a_2\ldots a_n$ of the subscripts will make $\sum_i x_i y_{a_i}$ a maximum? What permutation will make it a minimum? Verified: no Solve time: 2m07s Solution Let (x_1, x_2, \dots, x_n) and (y_1, y_2, \dots, y_n) be two sequences of real numbers. We wish to find a permutation (a_1...
TAOCP 6.1 Exercise 12
Section 6.1: Sequential Searching Exercise 12. [ M23 ] Use (17) to evaluate the average number of comparisons needed to search the self-organizing file when the search keys have the binary probability distribution (5). Verified: no Solve time: 2m37s Solution Equation (17) gives the limiting average number of comparisons for the move‑to‑front self‑organizing file: [ \widetilde C_N = 1 + \sum_{1\le i<j\le N} \frac{2p_i p_j}{p_i+p_j}. \tag{17} ] The binary probability...
TAOCP 5.4.9 Exercise 19
Section 5.4.9: Disks and Drums Exercise 19. ▶ [ 25 ] (B. T. Bennett and A. C. McKellar.) Consider the following approach to keysorting, illustrated on an example file with 10 keys: i) Original file: $(50,I_0)(08,I_1)(51,I_2)(06,I_3)(90,I_4)(17,I_5)(89,I_6)(27,I_7)(65,I_8)(42,I_9)$ ii) Key file: $(50,0)(08,1)(51,2)(06,3)(90,4)(17,5)(89,6)(27,7)(65,8)(42,9)$ iii) Sorted (ii): $(06,3)(08,1)(17,5)(27,7)(42,9)(50,0)(51,2)(65,8)(89,6)(90,4)$ iv) Bin assignments (see below): $(2,1)(2,3)(2,5)(2,7)(2,8)(2,9)(1,0)(1,2)(1,4)(1,6)$ v) Sorted (iv): $(1,0)(2,1)(1,2)(2,3)(1,4)(2,5)(1,6)(2,7)(2,8)(2,9)$ vi) (i) distributed into bins using (v): Bin 1: $(50,I_0)(51,I_2)(90,I_4)(89,I_6)$ Bin 2: $(08,I_1)(06,I_3)(17,I_5)(27,I_7)(65,I_8)(42,I_9)$ vii) The result...
TAOCP 6.1 Exercise 4
Section 6.1: Sequential Searching Exercise 4. ▶ [ 17 ] Does the idea of Algorithm Q carry over from subscript notation to linked-memory notation? (See exercise 2.) Verified: no Solve time: 56s Solution Yes, the sentinel technique of Algorithm Q adapts directly to linked-memory representation. Assume the linked-memory conventions of Exercise 2: each record has fields $\mathit{KEY}$, $\mathit{INFO}$, and $\mathit{LINK}$; $\mathit{FIRST}$ points to the first record; the last record has...
TAOCP 5.5 Exercise 4
Section 5.5: Summary, History, and Bibliography Exercise 4. ▶ [ 28 ] A sorting algorithm is called parsimonious if it makes decisions entirely by comparing keys, and if it never makes a comparison whose outcome could have been predicted from the results of previous comparisons. Which of the methods listed in Table 1 are parsimonious? 5. [46] It is much more difficult to sort nonrandom data with numerous equal keys...
TAOCP 5.4.4 Exercise 19
Section 5.4.4: Reading Tape Backwards Exercise 19. ▶ [ 22 ] (R. M. Karp.) Find a binary tree that is not 3-fifo. Verified: no Solve time: 1h02m Solution The binary tree that is not 3-fifo is the tree depicted in the invalid configurations (4') of the text. In the read‑forward (FIFO) tree representation, the children of a node are ordered according to the “first formed, first grown on” rule. The...
TAOCP 5.4.9 Exercise 21
Section 5.4.9: Disks and Drums Exercise 21. ▶ [ M15 ] How many blocks of an $L$-block file go on disk $j$ when the file is striped on $D$ disks? Verified: no Solve time: 45s Solution Let the file consist of (L) blocks, indexed (0,1,\dots,L-1). The file is striped across (D) disks, meaning that block (k) is placed on disk ((k \bmod D)). Disks are numbered (0,1,\dots,D-1). We want the...
TAOCP 5.4.9 Exercise 20
Section 5.4.9: Disks and Drums Exercise 20. ▶ [ 25 ] Modern hardware/software systems provide programmers with a virtual memory: Programs are written as if there were a very large internal memory, able to contain all of the data. This memory is divided into pages, only a few of which are in the actual internal memory at any one time; the others are on disks or drums. Programmers need not...
TAOCP 5.4.9 Exercise 17
Section 5.4.9: Disks and Drums Exercise 17. ▶ [ HM25 ] (R. W. Floyd, 1980.) Show that the lower bound of Theorem F can be improved to $$\frac{n(b\ln n-\ln b-1)}{\ln n+b(1+\ln(1+m/b))},$$ in the sense that some initial configuration must require at least this many stops. [Hint: Count the configurations that can be obtained after $s$ stops.] Verified: no Solve time: 23m51s Solution We consider the elevator problem as defined in...
TAOCP 5.4.9 Exercise 4
Section 5.4.9: Disks and Drums Exercise 4. ▶ [ M21 ] Consider a modified form of the square root buffer allocation scheme, in which all $P$ of the input buffers have equal length, but the output buffer size should be chosen so as to minimize seek time. a) Derive a formula corresponding to (2), for the running time of an $L$-character $P$-way merge. b) Show that the construction in Theorem...
TAOCP 5.4.9 Exercise 3
Section 5.4.9: Disks and Drums Exercise 3. [ M15 ] Suppose the internal memory is limited so that 10-way merging is not feasible. How can recurrence relations (3), (4), (5) be modified so that $A_1(n)$ is the minimum value of $\alpha D(T)+\beta E(T)$, over all $n$-leaved trees $T$ having no internal nodes of degree greater than 9? Verified: no Solve time: 3m36s Solution The text defines (A_1(n)) as the minimum...
TAOCP 5.4.8 Exercise 5
Section 5.4.8: Two-Tape Sorting Exercise 5. ▶ [ M23 ] True or false: After step K1 of the algorithm in Theorem K, nobody on the elevator has a lower destination than any person on floors $<k$. Verified: no Solve time: 6m25s Solution The statement is false . Counterexample. Consider the elevator algorithm given in Theorem K (the standard SCAN/elevator algorithm). The algorithm services requests in both directions. Suppose the elevator...
TAOCP 5.4.4 Exercise 15
Section 5.4.4: Reading Tape Backwards Exercise 15. [ M39 ] Karp’s preorder construction in the text yields trees with one-way merges at several terminal nodes. Prove that when $T = 3$ it is possible to construct asymptotically optimal 3-lifo trees in which two-way merging is used throughout. In other words, let $\hat K_T(n)$ be the minimum external path length over all $T$-lifo trees with $n$ external nodes, such that every...
TAOCP 5.4.7 Exercise 6
Section 5.4.7: External Radix Sorting Exercise 6. ▶ [ 20 ] A certain file contains two-digit keys 00, 01, . . . , 99. After performing Mauchly’s radix sort on the least significant digits, we can repeat the same scheme on the most significant digits, interchanging the roles of tapes T2 and T4. In what order will the keys finally appear on T2? Verified: no Solve time: 12m23s Solution We...
TAOCP 5.4.4 Exercise 21
Section 5.4.4: Reading Tape Backwards Exercise 21. [ 18 ] Draw the tree representation for the read-forwards merge pattern defined by the vectors in exercise 7. Is this tree strongly 3-fifo? Verified: no Solve time: 14m43s Solution Vectors from Exercise 7 Exercise 7 gives the vector representation for the polyphase merge on three tapes with 13 initial runs. The final output is on tape 1, so [ \mathbf{y}^{(0)} = (1,0,0)....
TAOCP 5.4.4 Exercise 22
Section 5.4.4: Reading Tape Backwards Exercise 22. [ 28 ] (R. M. Karp.) Show that the tree representations for polyphase and cascade merging with perfect distributions are exactly the same for both the read-backward and the read-forward case, except for the numbers that label the internal nodes. Find a larger class of vector representations of merging patterns for which this is true. Verified: no Solve time: 1m16s I'm ready to...
TAOCP 5.4.4 Exercise 20
Section 5.4.4: Reading Tape Backwards Exercise 20. ▶ [ 22 ] Formulate the condition “strongly $T$-fifo” in terms of a fairly simple rule about invalid configurations of tape labels, analogous to (4′). Verified: no Solve time: 10m09s Solution A tree is strongly $T$-fifo if and only if it can be labeled with $T$ labels (tape numbers) so that the following two invalid configurations never appear: A node with two children...
TAOCP 5.4.4 Exercise 18
Section 5.4.4: Reading Tape Backwards Exercise 18. ▶ [ M38 ] Suppose that $T$ tape units are available, for some $T \ge 3$, and that T1 contains $N$ records while the remaining tapes are empty. Is it possible to reverse the order of the records on T1 in fewer than $\Omega(N \log N)$ steps, without reading backwards? (The operation is, of course, trivial if backwards reading is allowed.) See exercise...
TAOCP 5.4.4 Exercise 17
Section 5.4.4: Reading Tape Backwards Exercise 17. ▶ [ 28 ] (Richard D. Pratt.) To achieve ascending order in a read-backward cascade merge, we could insist on an even number of merging passes; this suggests a technique of initial distribution that is somewhat different from Algorithm 5.4.3C. a) Change 5.4.3–(1) so that it shows only the perfect distributions that require an even number of merging passes. b) Design an initial...
TAOCP 5.4.4 Exercise 13
Section 5.4.4: Reading Tape Backwards Exercise 13. [ 16 ] Make (12) more efficient, by removing as many of the one-way merges as possible so that preorder still gives a valid labeling of the internal nodes. Verified: no Solve time: 14m28s Solution The pure cascade merge for 14 initial runs on four tapes (read backwards) is described by the vector representation in the text. Its merge pattern corresponds to a...
TAOCP 5.4.4 Exercise 12
Section 5.4.4: Reading Tape Backwards Exercise 12. [ 22 ] Prove that Karp’s preorder construction always yields a labeled tree satisfying conditions (a), (b), and (c). Verified: no Solve time: 11m33s Solution We recall Karp's preorder construction as given in the text. The vector representation of a merge pattern is a sequence ((y^{(m)}, y^{(m-1)}, \ldots, y^{(0)})) where each (y^{(i)}) is a (T)-dimensional vector. For (1 \le i \le m), the...
TAOCP 5.4.4 Exercise 16
Section 5.4.4: Reading Tape Backwards Exercise 16. [ M46 ] In the notation of exercise 15, is $\hat K_T(n) = n\log_{T-1} n + O(n)$ for all $T \ge 3$, when $n \equiv 1 \pmod{T-2}$? 310 SORTING 5.4.4 Verified: no Solve time: 1m40s Setup A (T)-lifo tree is a rooted ordered tree that represents a merge pattern for (T) tapes with backward reading. Each internal node corresponds to a merge; its...
TAOCP 5.4.4 Exercise 14
Section 5.4.4: Reading Tape Backwards Exercise 14. [ 40 ] Devise an algorithm that carries out the preorder merge without explicitly representing the tree in steps P2 and P3, using only $O(\log S)$ words of memory to control the merging pattern. Verified: no Solve time: 6m07s Setup The preorder merge algorithm (Algorithm P in the text) controls an optimal read‑backward merge pattern using Karp’s tree representation. The merge tree (...
TAOCP 5.4.4 Exercise 8
Section 5.4.4: Reading Tape Backwards Exercise 8. [ 23 ] Prove that (8) is an optimum way to merge, reading backwards, when $S = 7$ and $T = 4$, and that all methods that avoid one-way merging are inferior. Verified: no Solve time: 16m46s Solution The tree representation (8) for $S=7$, $T=4$ read-backward merging is the following pattern (shown in the text as equation (8)). In vector notation, with tapes...
TAOCP 5.4.4 Exercise 9
Section 5.4.4: Reading Tape Backwards Exercise 9. [ M22 ] Prove the lower bound (9). Verified: no Solve time: 13m23s Solution We consider a read-backward merge pattern on (T) tapes that sorts (S) initial runs in (m) merge phases. A phase consists of repeatedly merging one run from each of (k) input tapes ((2 \le k \le T-1)) onto a single empty output tape until one input tape is exhausted;...
TAOCP 5.4.4 Exercise 11
Section 5.4.4: Reading Tape Backwards Exercise 11. ▶ [ 20 ] True or false: Any read-backward merge pattern that uses nothing but $(T-1)$-way merging must always have the runs alternating $ADAD \ldots$ on each tape; it will not work if two adjacent runs appear in the same order. Verified: no Solve time: 10m09s Solution False. The statement claims that in any read‑backward merge pattern using only ((T-1))-way merges, the runs...
TAOCP 5.4.4 Exercise 5
Section 5.4.4: Reading Tape Backwards Exercise 5. ▶ [ 23 ] What formulas for the strings of merge numbers replace (8), (9), (10), and (11) of Section 5.4.2, when read-backward polyphase merging is used? Show the merge numbers for the fifth level distribution on six tapes, by drawing a diagram like Fig. 71(a). Verified: no Solve time: 10m24s Solution Formulas for the strings of merge numbers In standard polyphase merging...
TAOCP 5.4.4 Exercise 7
Section 5.4.4: Reading Tape Backwards Exercise 7. [ 16 ] Draw the tree representation for the read-backward merge pattern defined by the following sequence of vectors: $$ \begin{aligned} v^{(33)} &= (20,,9,,5) & y^{(16)} &= (+1,+1,-1)\ y^{(33)} &= (+1,-1,+1) & y^{(15)} &= (+1,+1,-1)\ y^{(32)} &= (+1,+1,-1) & y^{(14)} &= (+1,-1,+1)\ y^{(31)} &= (+1,+1,-1) & y^{(13)} &= (+1,-1,+1)\ y^{(30)} &= (+1,+1,-1) & y^{(12)} &= (-1,+1,+1)\ y^{(29)} &= (+1,-1,+1) & y^{(11)} &= (+1,+1,-1)\...
TAOCP 5.4.4 Exercise 3
Section 5.4.4: Reading Tape Backwards Exercise 3. ▶ [ 20 ] Prove that when read-backward polyphase merging is used with the perfect distributions of (1), we will always obtain an $A$ run on tape $T1$ when sorting is complete, if $T1$ originally starts with $ADA\ldots$ and $T2$ through $T5$ start with $DAD\ldots$. Verified: no Solve time: 15m17s Solution We consider the read‑backward polyphase merge on six tapes (T1,…,T6) using the...
TAOCP 5.4.4 Exercise 6
Section 5.4.4: Reading Tape Backwards Exercise 6. [ 07 ] What is the vector representation of the merge pattern whose tree representation is (8)? Verified: no Solve time: 3m34s The tree representation (8) illustrates the balanced merge on four tapes with eight initial runs, as summarized in the tableau of the section. The merge steps, in chronological order, are: Merge one run from T1 and one from T2 → T3...
TAOCP 5.4.4 Exercise 4
Section 5.4.4: Reading Tape Backwards Exercise 4. [ M22 ] Is it a good idea to do read-backward polyphase merging after distributing all runs in ascending order, imagining all the $D$ positions to be initially filled with dummies? Verified: no Solve time: 2m02s Solution No, it is not a good idea. The read‑backward polyphase merge relies on an invariant that the runs on every tape alternate between ascending (A) and...
TAOCP 5.4.4 Exercise 2
Section 5.4.4: Reading Tape Backwards Exercise 2. [ 20 ] Will the columns of an array like (1) always be nondecreasing, or is there a chance that we will have to “subtract” runs from some tape as we go from one level to the next? Verified: no Solve time: 11m29s Solution The array (1) in the text shows the distribution of runs for the read‑backward polyphase merge on six tapes,...
TAOCP 5.4.2 Exercise 14
Section 5.4.2: The Polyphase Merge Exercise 14. [ M35 ] Let $T_n(x) = \sum_{k \ge 0} T_{nk}x^k$, where $T_n(x)$ is the polynomial defined in (16). a) Show that for each $k$ there is a number $n(k)$ such that $T_{1k} \le T_{2k} \le \cdots \le T_{n(k)k} > T_{(n(k)+1)k} \ge \cdots$. b) Given that $T_{n'k'} < T_{nk}$ and $n' < n$, prove that $T_{n'k} \le T_{nk}$ for all $k \ge k'$. c)...
TAOCP 5.4.4 Exercise 1
Section 5.4.4: Reading Tape Backwards Exercise 1. [ 17 ] It is often convenient, during read-forward merging, to mark the end of each run on tape by including an artificial sentinel record whose key is $+\infty$. How should this practice be modified, when reading backwards? Verified: no Solve time: 4m31s Solution In read-forward merging, runs are written in ascending order and each run is terminated by an artificial sentinel record...
TAOCP 5.3.4 Exercise 65
Section 5.3.4: Networks for Sorting Exercise 65. [ M38 ] Given a pair sequence $(a_1, b_1)\ldots(a_M, b_M)$ as in exercise 64, let $c_i$ be the number of pairs $(j, k)$ such that $j < k < i$ and $(a_i, b_i)$, $(a_j, b_j)$, $(a_k, b_k)$ forms a triangle. a) Prove that the average number of comparisons made by the restricted uniform sorting algorithm is $\sum_{i=1}^{M} 2/(c_i + 2)$. b) Use the...
TAOCP 5.3.4 Exercise 68
Section 5.3.4: Networks for Sorting Exercise 68. [ 25 ] The Ph.D. thesis “Electronic Data Sorting” by Howard B. Demuth (Stanford University, October 1956) was perhaps the first publication to deal in any detail with questions of computational complexity. Demuth considered several abstract models for sorting devices, and established lower and upper bounds on the mean and maximum execution times achievable with each model. His simplest model, the “circular nonreversible...
TAOCP 5.3.4 Exercise 66
Section 5.3.4: Networks for Sorting Exercise 66. [ M29 ] In the worst case, quicksort does $\binom{N}{2}$ comparisons. Do all restricted uniform sorting algorithms (in the sense of exercise 64) perform $\binom{N}{2}$ comparisons in their worst case? Verified: no Solve time: 14m07s We need to solve Exercise 66 from Volume 3, Section 5.3.4. The exercise asks: "In the worst case, quicksort does $\binom{N}{2}$ comparisons. Do all restricted uniform sorting algorithms...
TAOCP 5.3.4 Exercise 60
Section 5.3.4: Networks for Sorting Exercise 60. [ 26 ] If $n = N$, prove that the first pass can be guaranteed to place the smallest key into position $R_1$ if and only if $h[k + 1] \le 2h[k]$ for $1 \le k < m$. Verified: no Solve time: 23m25s Setup We consider the multihead sorting method described in Exercise 57 with $n=N$. The head sequence is $1 = h_1...
TAOCP 5.3.4 Exercise 67
Section 5.3.4: Networks for Sorting Exercise 67. [ M48 ] (H. L. Beus.) Does quicksort have the minimum average number of comparisons, over all (restricted) uniform sorting algorithms? Verified: no Solve time: 2m32s Setup A uniform sorting algorithm (Exercise 64) processes all $\binom{N}{2}$ pairs $(a,b)$ with $1\le a<b\le N$ in a fixed sequence $(a_1,b_1), (a_2,b_2), \ldots, (a_M,b_M)$, $M=\binom{N}{2}$. It compares $K_{a_i}:K_{b_i}$ only if the outcome is not already forced by...
TAOCP 5.3.4 Exercise 64
Section 5.3.4: Networks for Sorting Exercise 64. [ 24 ] ( Uniform sorting. ) The tree of Fig. 34 in Section 5.3.1 makes the comparison $2!:!3$ in both branches on level 1, and on level 2 it compares $1!:!3$ in each branch unless that comparison would be redundant. In general, we can consider the class of all sorting algorithms whose comparisons are uniform in that way; assuming that the $M...
TAOCP 5.3.4 Exercise 62
Section 5.3.4: Networks for Sorting Exercise 62. [ 49 ] Study the largest $N$ for which $m$-head perfect sorters exist, given $m$. Is $N = O(m^2)$? Verified: no Solve time: 14m42s Setup A multihead sorter consists of $m$ read/write heads fixed at positions $1 = h_1 < h_2 < \dots < h_m = N$ on a tape of length $N$. The tape moves from left to right past the heads....
TAOCP 5.3.4 Exercise 63
Section 5.3.4: Networks for Sorting Exercise 63. [ 23 ] (V. Pratt.) When each head $h_k$ is in position $2^{k-1}$ for $1 \le k \le m$, how many passes are necessary to sort the sequence $z_1 z_2 \ldots z_{2^{m-1}}$ of 0s and 1s where $z_j = 0$ if and only if $j$ is a power of 2? Verified: no Solve time: 9m44s Solution We first recall the model of a...
TAOCP 5.3.4 Exercise 61
Section 5.3.4: Networks for Sorting Exercise 61. [ 34 ] (J. Hopcroft.) A “perfect sorter” for $N$ elements is a multihead sorter with $N = n$ that always finishes in one pass. Exercise 59 proves that the sequence $\langle h_1, h_2, h_3, h_4, . . . , h_m \rangle = \langle 1, 2, 4, 7, . . . , 1 + \binom{m}{2} \rangle$ gives a perfect sorter for $N =...
TAOCP 5.3.4 Exercise 59
Section 5.3.4: Networks for Sorting Exercise 59. ▶ [ 30 ] (Armstrong and Nelson.) Given that $h[k + 1] \le h[k] + k$ for $1 \le k < m$, and $N \ge n - 1$, prove that the largest $n - 1$ elements always move to their final destination on the first pass. [ Hint: Use the zero-one principle; when sorting 0s and 1s, with fewer than $n$ 1s, prove...
TAOCP 5.3.4 Exercise 57
Section 5.3.4: Networks for Sorting Exercise 57. [ M35 ] The even-odd merge is similar to Batcher’s odd-even merge, except that when $mn > 2$ it recursively merges the sequence $\langle x_{m\bmod 2+1},\ldots,x_{m-3},x_{m-1}\rangle$ with $\langle y_1,y_3,\ldots,y_{2\lceil n/2\rceil-1}\rangle$ and $\langle x_{(m+1)\bmod 2+1},\ldots,x_{m-2},x_m\rangle$ with $\langle y_2,y_4,\ldots,y_{2\lfloor n/2\rfloor}\rangle$ before making a set of $\lceil m/2\rceil+\lceil n/2\rceil-1$ comparison-interchanges analogous to (1). Show that the even-odd merge achieves the optimum delay time $\lceil \lg(m+n)\rceil$ of...
TAOCP 5.3.4 Exercise 56
Section 5.3.4: Networks for Sorting Exercise 56. ▶ [ 25 ] Suppose the bit vector $x \in D_n$ is not sorted. Show that there is a standard $n$-network $\alpha_x$ that fails to sort $x$, although it sorts all other elements of $D_n$. Verified: no Solve time: 17m12s Solution We prove the following statement by induction on (n): For any unsorted bit vector (x \in D_n) (where (D_n) is the set...
TAOCP 5.3.4 Exercise 58
Section 5.3.4: Networks for Sorting Exercise 58. [ 21 ] (James Dugundji.) Prove that if $h[k + 1] = h[k] + 1$ for some $k$, $1 \le k < m$, the multihead sorter defined above will eventually sort any input file in a finite number of passes. But if $h[k + 1] \ge h[k] + 2$ for $1 \le k < m$, the input might never become sorted. Verified: no...
TAOCP 5.3.4 Exercise 54
Section 5.3.4: Networks for Sorting Exercise 54. [ 42 ] Study the properties of sorting networks made from $m$-sorter modules instead of 2-sorters. (For example, G. Shapiro has constructed the network which sorts 16 elements using fourteen 4-sorters. Is this the best possible? Prove that $m^2$ elements can be sorted with at most 16 levels of $m$-sorters, when $m$ is sufficiently large.) Verified: no Solve time: 21m28s Setup An (m)-sorter...
TAOCP 5.3.4 Exercise 55
Section 5.3.4: Networks for Sorting Exercise 55. [ 23 ] A permutation network is a sequence of modules $[i_1:j_1] \dots [i_r:j_r]$ where each module $[i:j]$ can be set by external controls to pass its inputs unchanged or to switch $x_i$ and $x_j$ (irrespective of the values of $x_i$ and $x_j$), and such that each permutation of the inputs is achievable on the output lines by some setting of the modules....
TAOCP 5.3.4 Exercise 53
Section 5.3.4: Networks for Sorting Exercise 53. [ 30 ] ( Periodic sorting networks. ) The following two 16-networks illustrate general recursive constructions of $t$-level networks for $n = 2^t$ in the case $t = 4$: Fig. 53. Periodic sorting networks: (a) bitonic style; (b) odd-even style. If we number the input lines from $0$ to $2^t - 1$, the $l$th level in case (a) has comparators $[i:j]$ where $i...
TAOCP 5.3.4 Exercise 46
Section 5.3.4: Networks for Sorting Exercise 46. ▶ [ 30 ] (M. Aigner.) Show that the minimum number of stages needed to merge $m$ elements with $n$, using any algorithm that does simultaneous disjoint comparisons as in exercise 6, is at least $\lceil \lg(m + n) \rceil$; hence the bitonic merging network has optimum delay. Verified: no Solve time: 38m24s Solution We prove that any network that merges two sorted...
TAOCP 5.3.4 Exercise 52
Section 5.3.4: Networks for Sorting Exercise 52. ▶ [ 32 ] (M. O. Rabin, 1980.) Prove that it is intrinsically difficult to decide in general whether a sequence of comparators defines a sorting network, by considering networks of the form sketched in Fig. 60. It is convenient to number the inputs $x_0$ to $x_N$, where $N = 2mn + m + 2n$; the positive integers $m$ and $n$ are parameters....
TAOCP 5.3.4 Exercise 48
Section 5.3.4: Networks for Sorting Exercise 48. ▶ [ 26 ] We can interpret sorting networks in another way, letting each line carry a multiset of $m$ numbers instead of a single number; under this interpretation, the operation $[i : j]$ replaces $x_i$ and $x_j$, respectively, by $x_i \wedge x_j$ and $x_i \vee x_j$, the least $m$ and the greatest $m$ of the $2m$ numbers $x_i \uplus x_j$. (For example,...
TAOCP 5.3.4 Exercise 51
Section 5.3.4: Networks for Sorting Exercise 51. ▶ [ M25 ] (R. L. Graham.) The comparator $[i:j]$ is called redundant in the network $\alpha_1[i:j]\alpha_2$ if either $(x\alpha_1)_i \le (x\alpha_1)_j$ for all vectors $x$, or $(x\alpha_1)_i \ge (x\alpha_1)_j$ for all vectors $x$. Prove that if $\alpha$ is a network with $r$ irredundant comparators, there are at least $r$ distinct ordered pairs $(i,j)$ of distinct indices such that $(x\alpha)_i \le (x\alpha)_j$ for...
TAOCP 5.3.4 Exercise 50
Section 5.3.4: Networks for Sorting Exercise 50. [ HM46 ] Explore the properties of the $\wedge$ and $\vee$ operations defined in exercise 48. Is it possible to characterize all of the identities in this algebra in some nice way, or to derive them all from a finite set of identities? In this regard, identities such as $x \wedge x \wedge x = x \wedge x$, or $x \wedge (x \vee...
TAOCP 5.3.4 Exercise 49
Section 5.3.4: Networks for Sorting Exercise 49. [ M23 ] Show that, in the notation of exercise 48, $(x \wedge y) \wedge z = x \wedge (y \wedge z)$ and $(x \vee y) \vee z = x \vee (y \vee z)$; however $(x \vee y) \wedge z$ is not always equal to $(x \wedge z) \vee (y \wedge z)$, and $(x \wedge y) \vee (x \wedge z) \vee (y \wedge...
TAOCP 5.3.4 Exercise 47
Section 5.3.4: Networks for Sorting Exercise 47. [ 47 ] Is the function $T(n)$ of exercise 6 strictly less than $\hat{T}(n)$ for some $n$? Verified: no Solve time: 11m37s Setup Let (T(n)) be the minimum number of stages required to sort (n) numbers by an adaptive parallel algorithm that in each stage performs any set of disjoint comparisons (the choice of comparisons in a stage may depend on the outcomes...
TAOCP 5.3.4 Exercise 33
Section 5.3.4: Networks for Sorting Exercise 33. ▶ [ M22 ] Not all $\delta_n$ of the functions of $\langle x_1, \ldots, x_n \rangle$ in exercise 31 can appear in comparator networks. In fact, prove that the function $(x_1 \wedge x_2) \vee (x_2 \wedge x_3) \vee (x_3 \wedge x_4)$ cannot appear as an output of any comparator network on $\langle x_1, \ldots, x_n \rangle$. Verified: no Solve time: 1h20m Solution Assume,...
TAOCP 5.3.4 Exercise 45
Section 5.3.4: Networks for Sorting Exercise 45. [ M20 ] Prove that any $(1, n)$-merging network without multiple fanout must have at least $\lceil \lg(n + 1) \rceil$ levels of delay. Verified: no Solve time: 13m09s Solution We prove the lower bound by using the zero‑one principle and analyzing the information flow in a comparator network without multiple fanout. Zero‑one principle By the zero‑one principle (see Section 5.3.4), a comparator...
TAOCP 5.3.4 Exercise 42
Section 5.3.4: Networks for Sorting Exercise 42. ▶ [ 25 ] (D. Van Voorhis.) Prove that $\hat{S}(n) \ge \hat{S}(n-1) + \lceil \lg n \rceil$. Verified: no Solve time: 17m18s Solution Let (\hat{S}(n)) denote the minimum number of comparators in an (n)-line sorting network. We prove (\hat{S}(n) \ge \hat{S}(n-1) + \lceil \lg n \rceil) by induction on (n). The cases (n \le 2) are easily checked. Assume (n \ge 3) and...
TAOCP 5.3.4 Exercise 43
Section 5.3.4: Networks for Sorting Exercise 43. [ 48 ] Find an $(m, n)$-merging network with fewer than $C(m, n)$ comparators, or prove that no such network exists. Verified: no Solve time: 2m51s Setup An ((m,n))-merging network is a comparator network that accepts two sorted sequences (\langle x_1,\dots,x_m\rangle) and (\langle y_1,\dots,y_n\rangle) as inputs and produces the sorted merge of length (m+n) as output. The number of comparators used by Batcher’s...
TAOCP 5.3.4 Exercise 44
Section 5.3.4: Networks for Sorting Exercise 44. [ 50 ] Find the exact value of $\hat{S}(n)$ for some $n > 8$. Verified: no Solve time: 1m07s Setup Let (\hat{S}(n)) denote the minimum number of comparator modules required in a sorting network for (n) elements. A sorting network is an oblivious comparison-exchange network that correctly sorts every input sequence. The problem asks for the exact value of (\hat{S}(n)) for some (n...
TAOCP 5.3.4 Exercise 41
Section 5.3.4: Networks for Sorting Exercise 41. [ M47 ] Comparators $[i_1:j_1][i_2:j_2]\ldots[i_r:j_r]$ are chosen at random, with each irredundant choice $1 \le i_k < j_k \le n$ equally likely; the process stops when a sorting network has been obtained. Estimate the expected value of $r$; is it $O(n^{1+\epsilon})$ for all $\epsilon > 0$? Verified: no Solve time: 29m54s Setup We consider the following random process on (n) lines. Initially the...
TAOCP 5.3.4 Exercise 39
Section 5.3.4: Networks for Sorting Exercise 39. [ 25 ] Suppose that a primitive comparator network on $n$ lines is known to sort the single input $1 0 1 0 \ldots 1 0$ correctly. (See exercise 36; assume that $n$ is even.) Show that its "middle third," consisting of all comparators that involve only lines $\lceil n/3 \rceil$ through $\lceil 2n/3 \rceil$ inclusive, will sort all inputs. Verified: no Solve...
TAOCP 5.3.4 Exercise 40
Section 5.3.4: Networks for Sorting Exercise 40. [ HM44 ] Comparators $[i_1:i_1+1][i_2:i_2+1]\ldots[i_r:i_r+1]$ are chosen at random, with each value of $i_k \in {1, 2, \ldots, n-1}$ equally likely; the process stops when the network contains a bubble sort configuration like that of Fig. 47 as a subnetwork. Prove that $r \le 4n^2 + O(n^{3/2} \log n)$, except with probability $O(n^{-1000})$. Verified: no Solve time: 32m43s Setup The bubble sort configuration...
TAOCP 5.3.4 Exercise 37
Section 5.3.4: Networks for Sorting Exercise 37. [ M22 ] The odd-even transposition sort for $n$ numbers, $n \ge 3$, is a network $n$ levels deep with $\frac{1}{2}n(n-1)$ comparators, arranged in a brick-like pattern as shown in Fig. 58. (When $n$ is even, there are two possibilities.) Such a sort is especially easy to implement in hardware, since only two kinds of actions are performed alternatively. Prove that such a...
TAOCP 5.3.4 Exercise 38
Section 5.3.4: Networks for Sorting Exercise 38. ▶ [ 43 ] Let $N = \binom{n}{2}$. Find a one-to-one correspondence between Young tableaux of shape $(n-1, n-2, \ldots, 1)$ and primitive sorting networks $[i_1:i_1+1] \ldots [i_N:i_N+1]$. [Consequently by Theorem 5.1.4H there are exactly $$\frac{N!}{1^{n-1} 3^{n-2} 5^{n-3} \ldots (2n-3)^1}$$ such sorting networks.] [ Hint: Exercise 36(c) shows that primitive networks without redundant comparators correspond to paths from $1 2 \ldots n$ to...
TAOCP 5.3.4 Exercise 32
Section 5.3.4: Networks for Sorting Exercise 32. [ M28 ] (M. W. Green.) Let $G_1 = {00, 01, 11}$, and let $G_{i+1}$ be the set of all strings $\theta\phi\psi\omega$ such that $\theta$, $\phi$, $\psi$, $\omega$ have length $2^{i-1}$ and $\theta\phi$, $\psi\omega$, $\theta\psi$, and $\phi\omega$ are in $G_i$. Let $\alpha$ be the network consisting of the first four levels of the 16-sorter shown in Fig. 49. Show that $D_{16}\alpha = G_4$,...
TAOCP 5.3.4 Exercise 36
Section 5.3.4: Networks for Sorting Exercise 36. ▶ [ 22 ] The network of Fig. 47 involves only adjacent comparisons $[i:i+1]$; let us call such a network primitive . a) Prove that a primitive sorting network for $n$ elements must have at least $\binom{n}{2}$ comparators. [ Hint: Consider the inversions of a permutation.] b) (R. W. Floyd, 1964.) Let $\alpha$ be a primitive network for $n$ elements, and let $x$...
TAOCP 5.3.4 Exercise 34
Section 5.3.4: Networks for Sorting Exercise 34. [ 23 ] Is the following a sorting network? Verified: no Solve time: 8m34s Solution The network shown in the figure is the standard 4‑element sorting network obtained by Batcher’s odd‑even merge construction. It consists of five comparators applied in the following order: [ (1,2),;(3,4),;(1,3),;(2,4),;(2,3). ] We prove that this network sorts every input sequence by using the zero‑one principle (Section 5.3.4). It...
TAOCP 5.3.4 Exercise 35
Section 5.3.4: Networks for Sorting Exercise 35. [ 20 ] Prove that any standard sorting network must contain each of the adjacent comparators $[i:i+1]$, for $1 \le i < n$, at least once. Verified: no Solve time: 3m09s Solution We prove the statement using the zero‑one principle (Section 5.3.4): a comparator network is a sorting network if and only if it correctly sorts every sequence of 0s and 1s. Assume,...
TAOCP 5.3.4 Exercise 26
Section 5.3.4: Networks for Sorting Exercise 26. [ M24 ] (R. W. Floyd.) Let $\alpha$ be an $n$-network. Prove that $\alpha$ can determine the set $D_n\alpha = {x\alpha \mid x \in D_n}$ from the set $P_n\alpha = {p\alpha \mid p \in P_n}$; conversely, $P_n\alpha$ can be determined from $D_n\alpha$. Verified: no Solve time: 18m25s Solution Let (D_n = {0,1}^n) be the set of all (0)-(1) vectors of length (n), and...
TAOCP 5.3.4 Exercise 24
Section 5.3.4: Networks for Sorting Exercise 24. ▶ [ M21 ] (V. E. Alekseev.) Let $\alpha$ be an $n$-network, and for $1 \le k \le n$ let $$l_k = \min{(p\alpha)_k \mid p \in P_n}, \qquad u_k = \max{(p\alpha)_k \mid p \in P_n}$$ denote the lower and upper bounds on the range of values that may appear in line $k$ of the output. Let $l'_k$ and $u'_k$ be defined similarly for...
TAOCP 5.3.4 Exercise 29
Section 5.3.4: Networks for Sorting Exercise 29. [ M20 ] Given that $x_1 \le x_2 \le x_3$ and $y_1 \le y_2 \le y_3 \le y_4 \le y_5$, and that $z_1 \le z_2 \le \cdots \le z_n$ is the result of merging the $x$'s with the $y$'s, find formulas for each of the $z$'s in terms of the $x$'s and the $y$'s, using the operators $\wedge$ and $\vee$. Verified: no Solve...
TAOCP 5.3.4 Exercise 31
Section 5.3.4: Networks for Sorting Exercise 31. [ M24 ] (R. Dedekind, 1897.) Let $\delta_n$ be the number of distinct canonical forms on $x_1, \ldots, x_n$ in the sense of exercise 30. Thus $\delta_1 = 1$, $\delta_2 = 4$, and $\delta_3 = 18$. What is $\delta_4$? Verified: no Solve time: 1m15s Solution A canonical form as described in exercise 30 is a disjunction [ \tau_1 \lor \tau_2 \lor \cdots \lor...
TAOCP 5.3.4 Exercise 30
Section 5.3.4: Networks for Sorting Exercise 30. [ HM22 ] Prove that any formula involving $\wedge$ and $\vee$ and the independent variables ${x_1, \ldots, x_n}$ can be reduced using the identities in exercise 28 to a "canonical" form $\tau_1 \vee \tau_2 \vee \cdots \vee \tau_n$, where $k \ge 1$, each $\tau_i$ has the form $\bigwedge {x_j \mid j \in S_i}$ where $S_i$ is a subset of ${1, 2, \ldots, n}$,...
TAOCP 5.3.4 Exercise 28
Section 5.3.4: Networks for Sorting Exercise 28. ▶ [ M20 ] The following diagram illustrates the fact that we can systematically write down formulas for the contents of all lines in a sorting network in terms of the inputs: a ──── a ∧ b ─────────────┬── (a ∧ b) ∧ (c ∧ d) ─────────── (a ∧ b) ∧ (c ∧ d) │ b ──── a ∨ b ─────┬───────┼── (a ∨ b)...
TAOCP 5.3.4 Exercise 27
Section 5.3.4: Networks for Sorting Exercise 27. ▶ [ M20 ] Let $x$ and $y$ be vectors, and let $x\alpha$ and $y\alpha$ be sorted. Prove that $(x\alpha)_i \le (y\alpha)_i$ if and only if, for every choice of $j$ elements from $y$, we can choose $i$ elements from $x$ such that every chosen $x$ element is $\le$ some chosen $y$ element. Use this principle to prove that if we sort the...
TAOCP 5.3.4 Exercise 25
Section 5.3.4: Networks for Sorting Exercise 25. [ M30 ] Let $l_k$ and $u_k$ be as defined in exercise 24. Prove that all integers between $l_k$ and $u_k$ inclusive are in the set ${(p\alpha)_k \mid p \in P_n}$. Verified: no Solve time: 12m03s Setup Let $\alpha$ be an $n$-network. For each line $k;(1\le k\le n)$ define [ l_k = \min{(p\alpha)_k \mid p\in P_n},\qquad u_k = \max{(p\alpha)_k \mid p\in P_n}. ]...
TAOCP 5.3.4 Exercise 23
Section 5.3.4: Networks for Sorting Exercise 23. [ M18 ] Let $\alpha$ be an $n$-network. Prove that there is a permutation $p \in P_n$ such that $(p\alpha)_i = j$ if and only if there are vectors $x$ and $y$ in $D_n$ such that $x$ covers $y$, $(x\alpha)_i = 1$, $(y\alpha)_i = 0$, and $\zeta(y) = j$. Verified: no Solve time: 20m03s Solution Definitions. Let (D_n = {0,1}^n) be the set...
TAOCP 5.3.4 Exercise 19
Section 5.3.4: Networks for Sorting Exercise 19. [ M22 ] Prove that $\bar{U}_2(n) = 2n - 4$ and $\bar{V}_2(n) = 2n - 3$, for all $n \ge 2$. Verified: no Solve time: 25m38s Solution 1. $\bar{U}_2(n) = 2n-4$ Construction (upper bound) For $n \ge 2$ consider the following sequence of comparators: [ [1:n],; [2:n],; \dots,; [n-2:n],\qquad [1:n-1],; [2:n-1],; \dots,; [n-2:n-1]. ] There are $(n-2)+(n-2)=2n-4$ comparators. We prove that this network...
TAOCP 5.3.4 Exercise 20
Section 5.3.4: Networks for Sorting Exercise 20. [ 28 ] Prove that (a) $\bar{V}_3(5) = 7$; (b) $\bar{U}_4(n) \le 3n - 10$ for $n \ge 6$. Verified: no Solve time: 15m38s We are given Exercise 20 from Section 5.3.4 of TAOCP Volume 3. The exercise: Prove that (a) $\bar{V}_3(5) = 7$; (b) $\bar{U}_4(n) \le 3n - 10$ for $n \ge 6$. First, we need to understand the notation. The preceding...
TAOCP 5.3.4 Exercise 21
Section 5.3.4: Networks for Sorting Exercise 21. [ 21 ] True or false: Inserting a new standard comparator into any standard sorting network yields another standard sorting network. Verified: no Solve time: 8m23s Solution False. Inserting a comparator into a sorting network can destroy the sorting property. A counterexample with (n=4) is given below. Base sorting network Consider the following 6‑comparator network (N) for four inputs: [ (1,3),\quad (1,2),\quad (3,4),\quad...
TAOCP 5.3.4 Exercise 22
Section 5.3.4: Networks for Sorting Exercise 22. [ M17 ] Let $\alpha$ be any $n$-network, and let $x$ and $y$ be $n$-vectors. a) Prove that $x \subseteq y$ implies that $x\alpha \subseteq y\alpha$. b) Prove that $x \cdot y \le (x\alpha) \cdot (y\alpha)$, where $x \cdot y$ denotes the dot product $x_1y_1 + \cdots + x_ny_n$. Verified: no Solve time: 1m06s Solution Let an $n$-network $\alpha$ be a finite sequence...
TAOCP 5.3.4 Exercise 16
Section 5.3.4: Networks for Sorting Exercise 16. [ M22 ] Prove that the following algorithm transforms any sorting network $[i_1:j_1]\ldots[i_r:j_r]$ into a standard sorting network of the same length: T1. Let $q$ be the smallest index such that $i_q > j_q$. If no such index exists, stop. T2. Change all occurrences of $i_q$ to $j_q$, and all occurrences of $j_q$ to $i_q$, in all comparators $[i_s:j_s]$ for $q \le s...
TAOCP 5.3.4 Exercise 18
Section 5.3.4: Networks for Sorting Exercise 18. ▶ [ M20 ] Prove that a network that finds the median of $2t - 1$ elements requires at least $(t-1)\bigl(\lceil\lg(t+1)\rceil + \lceil\lg t\rceil\bigr)$ comparator modules. [ Hint : See the proof of Theorem A.] Verified: no Solve time: 10m24s Solution We prove the lower bound by applying the zero‑one principle and an adversary argument that extends the proof of Theorem A in...
TAOCP 5.3.4 Exercise 14
Section 5.3.4: Networks for Sorting Exercise 14. ▶ [ M27 ] (V. E. Alekseev.) Let $\alpha = [i_1: j_1] \ldots [i_r: j_r]$ be an $n$-network; for $1 \le s \le r$ we define $\alpha^s = [i' 1: j' 1] \ldots [i' {s-1}: j' {s-1}][i_s: j_s] \ldots [i_r: j_r]$, where the $i'_k$ and $j'_k$ are obtained from $i_k$ and $j_k$ by changing $i_s$ to $j_s$ and changing $j_s$ to $i_s$, wherever...
TAOCP 5.3.4 Exercise 15
Section 5.3.4: Networks for Sorting Exercise 15. [ 20 ] Find a nonstandard sorting network for four elements that has only five comparator modules. Verified: no Solve time: 12m15s Solution A nonstandard sorting network for four elements using only five comparator modules is [ \boxed{[1:3],;[1:4],;[2:3],;[2:4],;[1:2]}. ] Here ([i:j]) denotes a compare‑exchange module that sorts the values on lines (i) and (j) (with (i<j)) into nondecreasing order. **Verification by the zero‑one...
TAOCP 5.3.4 Exercise 17
Section 5.3.4: Networks for Sorting Exercise 17. [ M25 ] Let $D_{tn}$ be the set of all $\binom{n}{2}$ sequences $\langle x_1,\ldots,x_n\rangle$ of 0s and 1s having exactly $t$ 1s. Show that $\bar{U} t(n)$ is the minimum number of comparators needed in a network that sorts all the elements of $D {tn}$; $\bar{V} t(n)$ is the minimum number needed to sort $D {tn} \cup D_{(t-1)n}$; and $\bar{W} t(n)$ is the minimum...
TAOCP 5.3.4 Exercise 13
Section 5.3.4: Networks for Sorting Exercise 13. ▶ [ 24 ] (H. S. Stone.) Show that a sorting network for $2^t$ elements can be constructed by following the pattern illustrated for $t = 4$ in Fig. 57. Each of the $t^2$ steps in this scheme consists of a "perfect shuffle" of the first $2^{t-1}$ elements with the last $2^{t-1}$, followed by simultaneous operations performed on $2^{t-1}$ pairs of adjacent elements....
TAOCP 5.3.4 Exercise 10
Section 5.3.4: Networks for Sorting Exercise 10. [ M22 ] Prove that Batcher's bitonic sorter, as defined in the remarks preceding (15), is valid. [ Hint : It is only necessary to prove that all sequences consisting of $k$ 1s followed by $l$ 0s followed by $n - k - l$ 1s will be sorted.] Verified: no Solve time: 15m Solution We first recall the definitions of Batcher's bitonic sorter...
TAOCP 5.3.4 Exercise 8
Section 5.3.4: Networks for Sorting Exercise 8. [ M20 ] Prove that $\hat{M}(m_1+n_2, n_1+n_2) \ge \hat{M}(m_1, n_1) + \hat{M}(m_2, n_2) + \min(m_1, n_2)$, for $m_1, m_2, n_1, n_2 \ge 0$. Verified: no Solve time: 16m13s Solution We prove the inequality [ \hat{M}(m_1+m_2,, n_1+n_2) ;\ge; \hat{M}(m_1,n_1) + \hat{M}(m_2,n_2) + \min(m_1,n_2) \qquad (m_1,m_2,n_1,n_2 \ge 0), ] which is the intended form of the exercise (the original statement appears to contain a typographical...
TAOCP 5.3.4 Exercise 11
Section 5.3.4: Networks for Sorting Exercise 11. [ M23 ] Prove that Batcher's bitonic sorter of order $2^t$ will not only sort sequences $\langle z_0, z_1, \ldots, z_{2^t-1}\rangle$ for which $z_0 \ge \cdots \ge z_k \le \cdots \le z_{2^t-1}$, it also will sort any sequence for which $z_0 \le \cdots \le z_k \ge \cdots \ge z_{2^t-1}$. [As a consequence, the network in Fig. 56 will sort 16 elements, since each...
TAOCP 5.3.4 Exercise 12
Section 5.3.4: Networks for Sorting Exercise 12. [ M20 ] Prove or disprove: If $x$ and $y$ are bitonic sequences of the same length, so are $x \vee y$ and $x \wedge y$. Verified: no Solve time: 1m45s Solution We disprove the statement by providing a counterexample. Let (x = (0, 3, 2, 1)) and (y = (2, 1, 0, 3)). Both sequences have length (4). Bitonic definition. A sequence...
TAOCP 5.3.4 Exercise 9
Section 5.3.4: Networks for Sorting Exercise 9. [ M25 ] (R. W. Floyd.) Prove that $\hat{M}(3,3) = 6$, $\hat{M}(4,4) = 9$, $\hat{M}(5,5) = 13$. Verified: no Solve time: 10m50s Solution Zero-one principle A comparator network merges two sorted sequences of lengths (m) and (n) correctly for all inputs if and only if it does so for all (0)-(1) inputs where the first sequence consists of (k) zeros followed by (m-k)...
TAOCP 5.3.4 Exercise 7
Section 5.3.4: Networks for Sorting Exercise 7. [ 25 ] Show that if the final three comparators of the network for $n = 10$ in Fig. 49 are replaced by the "weaker" sequence [5:6][4:5][6:7], the network will still sort. Verified: no Solve time: 8m55s Solution The network for (n = 10) shown in Fig. 49 consists of the following 29 comparators arranged in 9 stages (delay 9): [ \begin{aligned} \text{Stage...
TAOCP 5.3.3 Exercise 27
Section 5.3.3: Minimum-Comparison Selection Exercise 27. ▶ [ M34 ] A randomized adversary is an adversary algorithm that is allowed to flip coins as it makes decisions. a) Let $A$ be a randomized adversary and let $\Pr(l)$ be the probability that $A$ reaches leaf $l$ of a given comparison tree. Show that if $\Pr(l) \le p$ for all $l$, the height of the comparison tree is $\ge \lg(1/p)$. b) Consider...
TAOCP 5.3.3 Exercise 24
Section 5.3.3: Minimum-Comparison Selection Exercise 24. [ HM40 ] Prove that $\overline{V}_t(n) \le n + t + O(\sqrt{n \log n})$ for $t \le \lceil n/2 \rceil$. Hint: Show that with this many comparisons we can in fact find both the $\lfloor t - \sqrt{t \ln n} \rfloor$th and $\lceil t + \sqrt{t \ln n} \rceil$th elements, after which the $t$th is easily located. Verified: no Solve time: 20m25s We need...
TAOCP 5.3.3 Exercise 26
Section 5.3.3: Minimum-Comparison Selection Exercise 26. [ M32 ] (A. Schönhage, 1974.) (a) In the notation of exercise 14, prove that $U_t(n) \ge \min(2 + U_t(n-1), 2 + U_{t-1}(n-1))$ for $n \ge 3$. [ Hint: Construct an adversary by reducing from $n$ to $n - 1$ as soon as the current partial ordering is not composed entirely of components having the form $\circ$ or $\leftarrow\bullet\rightarrow$.] (b) Similarly, prove that $$U_t(n)...
TAOCP 5.3.3 Exercise 25
Section 5.3.3: Minimum-Comparison Selection Exercise 25. ▶ [ M35 ] (W. Cunto and J. I. Munro.) Prove that $\overline{V}_t(n) \ge n + t - 2$ when $t \le \lceil n/2 \rceil$. Verified: no Solve time: 16m09s We need to prove that the minimum number of comparisons needed to find the t-th largest element (selection) satisfies V_t(n) >= n + t - 2 for t <= ceil(n/2). The problem is from...
TAOCP 5.3.3 Exercise 22
Section 5.3.3: Minimum-Comparison Selection Exercise 22. [ 24 ] (David G. Kirkpatrick.) Show that when $4 \cdot 2^k < n - 1 \le 5 \cdot 2^k$, the upper bound (11) for $V_3(n)$ can be reduced by 1 as follows: (i) Form four knockout trees of size $2^k$. (ii) Find the minimum of the four maxima, and discard all $2^k$ elements of its tree. (iii) Using the known information, build a...
TAOCP 5.3.3 Exercise 21
Section 5.3.3: Minimum-Comparison Selection Exercise 21. [ 32 ] (P. V. Ramanan and L. Hyafil.) Prove that $W_t(2^k + 2^{k+1-t}) \le 2^k + 2^{k+1-t} + (t-1)(k-1)$, when $k \ge t \ge 2$; also show that equality holds for infinitely many $k$ and $t$, because of exercise 4. [ Hint: Maintain two knockout trees and merge their results cleverly.] Verified: no Solve time: 17m31s Setup We are given integers (k \ge...
TAOCP 5.3.3 Exercise 20
Section 5.3.3: Minimum-Comparison Selection Exercise 20. [ M42 ] What is the asymptotic value of $\overline{V}_2(n) - n$, as $n \to \infty$? Verified: no Solve time: 20m17s Setup We consider the problem of finding the second largest element among (n) distinct elements using comparisons. The optimal worst-case algorithm is the tournament method (tree selection), which first finds the largest element in (n-1) comparisons, then finds the second largest among the...
TAOCP 5.3.3 Exercise 23
Section 5.3.3: Minimum-Comparison Selection Exercise 23. [ M42 ] What is the asymptotic value of $V_{\lceil n/2 \rceil}(n)$, as $n \to \infty$? Verified: no Solve time: 12m31s Setup We are asked for the asymptotic value of (V_{\lceil n/2 \rceil}(n)) as (n\to\infty), where (V_t(n)) is the minimum number of comparisons required in the worst case to determine the (t)‑th largest element of a set of (n) elements. The median is the...
TAOCP 5.3.3 Exercise 19
Section 5.3.3: Minimum-Comparison Selection Exercise 19. [ M42 ] Extend Table 2 to $n = 9$. Verified: no Solve time: 4m38s Setup Let (V_t(n)) denote the minimum number of comparisons required to select the (t)‑th largest element from a set of (n) elements, as defined in Section 5.3.3. Table 2 of the text lists the exact values of (V_t(n)) for (1 \le n \le 8). The exercise asks to extend...
TAOCP 5.3.3 Exercise 17
Section 5.3.3: Minimum-Comparison Selection Exercise 17. [ 20 ] (R. W. Floyd.) Show that it is possible to select, in order, both the $k$ largest and the $l$ smallest elements of a set of $n$ elements, using at most $\lceil \frac{3}{2}n \rceil - k - l + \sum_{n+1-k \le j \le n} \lceil \lg j \rceil + \sum_{n+1-l \le j \le n} \lceil \lg j \rceil$ comparisons. Verified: no Solve...
TAOCP 5.3.3 Exercise 18
Section 5.3.3: Minimum-Comparison Selection Exercise 18. [ M20 ] If groups of size 5, not 7, had been used in the proof of Theorem L, what theorem would have been obtained? Verified: no Solve time: 6m20s Solution The median-of-medians algorithm (Blum, Floyd, Pratt, Rivest, Tarjan) finds the (t)th largest element by recursively using a pivot obtained as the median of medians of small groups. The proof of Theorem L in...
TAOCP 5.3.1 Exercise 34
Section 5.3.1: Minimum-Comparison Sorting Exercise 34. [ M50 ] Determine the exact value of $S(n)$ for infinitely many $n$. Verified: no Solve time: 20m40s We need to solve Exercise 34 from TAOCP Volume 3, Section 5.3.1: "Determine the exact value of S(n) for infinitely many n." S(n) is the minimum number of comparisons required to sort n elements in the worst case. The exercise is marked M50 (research level). The...
TAOCP 5.3.1 Exercise 35
Section 5.3.1: Minimum-Comparison Sorting Exercise 35. [ 29 ] Determine the exact value of $S(16)$. Verified: no Solve time: 15m31s Setup We need to determine (S(16)), the minimum number of comparisons required to sort 16 distinct elements in the worst case. The information‑theoretic lower bound gives [ S(16) \ge \lceil \lg 16! \rceil. ] Since (16! = 20,922,789,888,000) and (2^{44} = 17,592,186,044,416 < 16! < 35,184,372,088,832 = 2^{45}), we have...
TAOCP 5.3.2 Exercise 13
Section 5.3.2: Minimum-Comparison Merging Exercise 13. [ M42 ] (R. L. Graham.) Show that the solution to the recurrence in exercise 12 may be expressed as follows. Define the function $G(x)$, for $0 < x < \infty$, by the rules $$G(x) = \begin{cases} 1, & \text{if } 0 < x \le \frac{5}{7}; \ \frac{1}{2} + \frac{7}{8} G(8x - 5), & \text{if } \frac{5}{7} < x \le \frac{3}{4}; \ \frac{7}{2} G(2x...
TAOCP 5.3.1 Exercise 33
Section 5.3.1: Minimum-Comparison Sorting Exercise 33. [ M30 ] (T. N. Hibbard.) A real-valued search tree of order $x$ and resolution $\delta$ is an extended binary tree in which all nodes contain a nonnegative real value such that (i) the value in each external node is $\le \delta$, (ii) the value in each internal node is at most the sum of the values in its two children, and (iii) the...
TAOCP 5.3.1 Exercise 36
Section 5.3.1: Minimum-Comparison Sorting Exercise 36. [ M50 ] (S. S. Kislitsyn, 1968.) Prove or disprove: Any directed acyclic graph $G$ with $T(G) > 1$ has two vertices $u$ and $v$ such that the digraphs $G_1$ and $G_2$ obtained from $G$ by adding the arcs $u \leftarrow v$ and $u \to v$ are acyclic and satisfy $1 \le T(G_1)/T(G_2) \le 2$. (Thus $T(G_1)/T(G)$ always lies between $\frac{1}{3}$ and $\frac{2}{3}$, for...
TAOCP 5.3.1 Exercise 31
Section 5.3.1: Minimum-Comparison Sorting Exercise 31. [ M38 ] Continuing exercise 30, prove that $S_e(5) = 8$. Verified: no Solve time: 11m50s We need to solve exercise 31 from Volume 3, Section 5.3.1: "Continuing exercise 30, prove that S_e(5) = 8." First, understand the context. Exercise 30 defines S_e(n) as the minimum number of comparison-exchanges needed in the worst case to sort n elements by means of a comparison-exchange tree....
TAOCP 5.3.1 Exercise 32
Section 5.3.1: Minimum-Comparison Sorting Exercise 32. [ M42 ] Continuing exercise 31, investigate $S_e(n)$ for small values of $n > 5$. Verified: no Solve time: 4m51s Setup Let (S_e(n)) denote the minimum worst-case number of comparison-exchanges required to sort (n) distinct elements, as defined in Exercise 30. We already know from Exercises 30 and 31 that [ S_e(n) \le S(n) + n - 1, \qquad S_e(1)=0,; S_e(2)=1,; S_e(3)=3,; S_e(4)=5,; S_e(5)=8....
TAOCP 5.3.1 Exercise 30
Section 5.3.1: Minimum-Comparison Sorting Exercise 30. [ M29 ] ( Optimum exchange sorting. ) Every exchange sorting algorithm as defined in Section 5.2.2 can be represented as a comparison-exchange tree , namely a binary tree structure whose internal nodes have the form $i:j$ for $i < j$, interpreted as the following operation: "If $K_i \le K_j$, continue by taking the left branch of the tree; if $K_i > K_j$, continue...
TAOCP 5.3.1 Exercise 29
Section 5.3.1: Minimum-Comparison Sorting Exercise 29. [ M25 ] (S. M. Chase.) Let $a_1 a_2 \ldots a_n$ be a permutation of ${1, 2, \ldots, n}$. Prove that any algorithm that decides whether this permutation is even or odd (that is, whether it has an even or odd number of inversions), based solely on comparisons between the $a$'s, must make at least $n \lg n$ comparisons, even though the algorithm has...
TAOCP 5.3.1 Exercise 26
Section 5.3.1: Minimum-Comparison Sorting Exercise 26. [ M42 ] Find a sorting procedure for seven elements that minimizes the average number of comparisons performed. Verified: no Solve time: 16m45s Setup We consider the problem of sorting 7 distinct elements using only binary comparisons. A sorting procedure corresponds to an extended binary decision tree whose internal nodes are comparisons between two elements and whose 5040 external nodes (leaves) are the permutations...
TAOCP 5.3.1 Exercise 24
Section 5.3.1: Minimum-Comparison Sorting Exercise 24. [ 27 ] (C. Picard.) Find a sorting tree for six elements such that all external nodes appear on levels 10 and 11. Verified: no Solve time: 18m21s Setup We are asked to find a comparison tree (sorting tree) for six distinct elements such that all 720 external nodes (leaves) appear on levels 10 and 11. The text defines the root at level 0...
TAOCP 5.3.1 Exercise 27
Section 5.3.1: Minimum-Comparison Sorting Exercise 27. ▶ [ 20 ] Suppose it is known that the configurations $K_1 < K_2 < K_3$, $K_1 < K_3 < K_2$, $K_2 < K_1 < K_3$, $K_2 < K_3 < K_1$, $K_3 < K_1 < K_2$, $K_3 < K_2 < K_1$ occur with respective probabilities .01, .25, .01, .24, .25, .24. Find a comparison tree that sorts these three elements with the smallest average...
TAOCP 5.3.1 Exercise 22
Section 5.3.1: Minimum-Comparison Sorting Exercise 22. [ M24 ] Continuing exercise 21, prove that a binary tree has minimum external path length among all binary trees with the same number of nodes if and only if $$|t(x) - 2t(l(x))| \le 2^{\lceil \lg t(x) \rceil} - t(x) \quad \text{and} \quad |t(x) - 2t(l(x))| \le t(x) - 2^{\lfloor \lg t(x) \rfloor}$$ for all internal nodes $x$. [Thus, for example, if $t(x) =...
TAOCP 5.3.1 Exercise 14
Section 5.3.1: Minimum-Comparison Sorting Exercise 14. [ M24 ] Find a closed form for the sum (19). Verified: no Solve time: 44m16s Solution The sum (19) in the text is the total number of comparisons required by merge insertion to sort (n) elements, which is [ S(n) = \sum_{k=1}^n \left\lceil \log_2 \frac{3k}{4} \right\rceil. ] We derive a closed form for this sum. For an integer (m \ge 0), the value...
TAOCP 5.3.1 Exercise 25
Section 5.3.1: Minimum-Comparison Sorting Exercise 25. [ 11 ] If there were a sorting procedure for seven elements that achieves the minimum average number of comparisons predicted by the use of Eq. (34), how many external nodes would there be on level 13? Verified: no Solve time: 1m50s Solution The minimum average number of comparisons for sorting (n) distinct elements is achieved by a comparison tree (a full binary tree)...
TAOCP 5.3.1 Exercise 23
Section 5.3.1: Minimum-Comparison Sorting Exercise 23. [ 10 ] The text proves that the average number of comparisons made by any sorting method for $n$ elements must be at least $\lceil \lg n! \rceil \approx n \lg n$. But multiple list insertion (Program 5.2.1M) takes only $O(n)$ units of time on the average. How can this be? Verified: no Solve time: 52s The information-theoretic lower bound (\lceil \lg n! \rceil)...
TAOCP 5.3.1 Exercise 21
Section 5.3.1: Minimum-Comparison Sorting Exercise 21. [ M21 ] The height of an extended binary tree is the maximum level number of its external nodes. If $x$ is an internal node of an extended binary tree, let $t(x)$ be the number of external nodes below $x$, and let $l(x)$ denote the root of $x$'s left subtree. If $x$ is an external node, let $t(x) = 1$. Prove that an extended...
TAOCP 5.3.1 Exercise 20
Section 5.3.1: Minimum-Comparison Sorting Exercise 20. ▶ [ M26 ] Prove that an extended binary tree has minimum external path length if and only if there is a number $l$ such that all external nodes appear on levels $l$ and $l+1$ (or perhaps all on a single level $l$). Verified: no Solve time: 7m08s Setup An extended binary tree is a finite rooted tree in which every internal node has...
TAOCP 5.3.1 Exercise 16
Section 5.3.1: Minimum-Comparison Sorting Exercise 16. [ HM26 ] (F. Hwang and S. Lin.) Prove that $F(n) > \lceil \lg n! \rceil$ for $n \ge 22$. Verified: no Solve time: 22m58s Setup Let (F(n)) denote the number of comparisons performed by the merge‑insertion (Ford-Johnson) algorithm when sorting (n) distinct elements. From the description in the text (Section 5.3.1) one can derive the explicit formula [ F(n)=\sum_{k=1}^{n}\Bigl\lceil \lg\frac{3k}{4}\Bigr\rceil \qquad (n\ge 1),...
TAOCP 5.3.1 Exercise 19
Section 5.3.1: Minimum-Comparison Sorting Exercise 19. [ 40 ] Experiment with the following heuristic rule for deciding which pair of elements to compare next while designing a comparison tree: At each stage of sorting ${K_1, \ldots, K_n}$, let $u_i$ be the number of keys known to be $\le K_i$ as a result of the comparisons made so far, and let $v_i$ be the number of keys known to be $\ge...
TAOCP 5.3.1 Exercise 18
Section 5.3.1: Minimum-Comparison Sorting Exercise 18. [ 20 ] If the procedure whose first steps are shown in Fig. 36 had produced the linear graph •, •, •, •, •, •, •, •, •, •, •, • with efficiency $12!/2^{29}$, would this have proved that $S(12) = 29$? Verified: no Solve time: 4m51s Solution The efficiency of a comparison tree that sorts (n) elements (with no redundant comparisons) is defined...
TAOCP 5.3.1 Exercise 11
Section 5.3.1: Minimum-Comparison Sorting Exercise 11. [ HM22 ] When sorting $n$ elements as in exercise 5, and knowing that all keys are members of the set ${1, 2, \ldots, m}$, let $S_m(n)$ be the minimum number of comparisons needed in the worst case. [Thus by exercise 6, $S_n(n) = S(n)$.] Prove that, for fixed $m$, $S_m(n)$ is asymptotically $n \lg m + O(1)$ as $n \to \infty$. Verified: no...
TAOCP 5.3.1 Exercise 15
Section 5.3.1: Minimum-Comparison Sorting Exercise 15. [ M21 ] Determine the asymptotic behavior of $B(n)$ and $F(n)$ up to $O(\log n)$. [ Hint: Show that in both cases the coefficient of $n$ involves the function shown in Fig. 37.] Verified: no Solve time: 13m12s Solution 1. Binary insertion (B(n)) The maximum number of comparisons for binary insertion is given in the text (Eq. (3)) as [ B(n) = \sum_{k=1}^{n}\lceil\lg k\rceil...
TAOCP 5.3.1 Exercise 13
Section 5.3.1: Minimum-Comparison Sorting Exercise 13. [ M28 ] Prove (17). Verified: no Solve time: 15m49s Setup We consider the merge insertion (Ford-Johnson) algorithm as described in the text. For (n) elements the algorithm proceeds as follows: If (n \le 1), no comparisons are needed. Let (m = \lfloor n/2\rfloor). Form (m) disjoint pairs and compare each pair. This uses (m) comparisons. The larger element of each pair is called...
TAOCP 5.2.5 Exercise 14
Section 5.2.5: Sorting by Distribution Exercise 14. [ 22 ] The sequence of playing cards can be sorted into increasing order A 2 ... J Q K from top to bottom in two passes, using just two piles for intermediate storage: Deal the cards face down into two piles containing respectively A 2 9 3 10 and 4 J 5 6 Q K 7 8 (from bottom to top); then...
TAOCP 5.3.1 Exercise 12
Section 5.3.1: Minimum-Comparison Sorting Exercise 12. ▶ [ M25 ] (W. G. Bouricius, circa 1954.) Suppose that equal keys may occur, but we merely want to sort the elements ${K_1, K_2, \ldots, K_n}$ so that a permutation $a_1 a_2 \ldots a_n$ is determined with $K_{a_1} \le K_{a_2} \le \cdots \le K_{a_n}$; we do not need to know whether or not equality occurs between $K_{a_i}$ and $K_{a_{i+1}}$. Let us say that...
TAOCP 5.2.5 Exercise 15
Section 5.2.5: Sorting by Distribution Exercise 15. [ 22 ] Consider the problem of exercise 14 when all cards must be dealt face up instead of face down. Thus, one pass can be used to convert increasing order into decreasing order. How many passes are required? Verified: no Solve time: 46m52s We need to solve Exercise 15 from TAOCP Volume 3, Section 5.2.5. The exercise refers to Exercise 14. Let's...
TAOCP 5.3.1 Exercise 10
Section 5.3.1: Minimum-Comparison Sorting Exercise 10. ▶ [ M25 ] When sorting $n$ elements as in exercise 7, knowing that all keys are 0 or 1, what is the minimum average number of comparisons as a function of $n$? Verified: no Solve time: 19m50s Solution We consider the problem of sorting (n) elements whose keys are known to be either 0 or 1. A comparison between two elements (K_i) and...
TAOCP 5.3.1 Exercise 9
Section 5.3.1: Minimum-Comparison Sorting Exercise 9. [ M20 ] When sorting $n$ elements as in exercise 7, knowing that all keys are 0 or 1, what is the minimum number of comparisons in the worst case? Verified: no Solve time: 27m14s Solution We consider the problem of sorting (n) elements when it is known that each key is either (0) or (1). A comparison between two keys has three possible...
TAOCP 5.2.5 Exercise 16
Section 5.2.5: Sorting by Distribution Exercise 16. ▶ [ 25 ] Design an algorithm to sort strings $\alpha_1, \ldots, \alpha_n$ on an $m$-letter alphabet into lexicographic order. The total running time of your algorithm should be $O(m + n + N)$, where $N = |\alpha_1| + \cdots + |\alpha_n|$ is the total length of all the strings. Verified: no Solve time: 22m31s Solution Algorithm S (Radix list sort for variable‑length...
TAOCP 5.2.5 Exercise 18
Section 5.2.5: Sorting by Distribution Exercise 18. [ HM26 ] Prove Theorem T. Hint: Show first that MacLaren's distribution-plus-insertion algorithm does $O(BN)$ operations, on the average, when it is applied to independent random keys whose probability density function satisfies $f(x) \le B$ for $0 \le x \le 1$. For sorting the roots and words we had the use of 1100 lozenge boxes, and used trays for the forms. , GEORGE...
TAOCP 5.2.5 Exercise 17
Section 5.2.5: Sorting by Distribution Exercise 17. [ 15 ] In the two-level distribution sort proposed by Tamminen (see Theorem T), why is a MacLaren-like method used for the second level of distribution but not the first level? Verified: no Solve time: 1m41s Solution In Tamminen's two-level distribution sort (Theorem T), the first level partitions the $N$ records into $M$ buckets according to their most significant digit. This is done...
TAOCP 5.2.5 Exercise 13
Section 5.2.5: Sorting by Distribution Exercise 13. [ 40 ] Implement the internal sorting method suggested in the text at the close of this section, producing a subroutine that sorts random data in $O(N)$ units of time with only $O(\sqrt{N})$ additional memory locations. Verified: no Solve time: 8m40s Setup We consider the problem of sorting (N) records with keys that are two-digit numbers in base (M = \lceil \sqrt{N} \rceil)....
TAOCP 5.2.5 Exercise 10
Section 5.2.5: Sorting by Distribution Exercise 10. [ 30 ] Design an efficient most-significant-digit-first radix-sorting algorithm that uses linked memory. (As the size of the subfiles decreases, it is wise to decrease $M$, and to use a nonradix method on the really short subfiles.) Verified: no Solve time: 13m58s Setup We consider the same record structure as in Algorithm R (Section 5.2.5). There are (N) records (R_1,\dots,R_N), each containing a...
TAOCP 5.2.4 Exercise 19
Section 5.2.4: Sorting by Merging Exercise 19. [ 26 ] Consider a railway switching network with $n$ "stacks," as shown in Fig. 31 when $n = 5$; we considered one-stack networks in exercises 2.2.1–2 through 2.2.1–5. If $N$ railroad cars enter at the right, we observed that only comparatively few of the $N!$ permutations of those cars could appear at the left, in the one-stack case. In the $n$-stack network,...
TAOCP 5.2.5 Exercise 12
Section 5.2.5: Sorting by Distribution Exercise 12. [ 24 ] (M. D. MacLaren.) Suppose that Algorithm R has been applied only to the $p$ leading digits of the actual keys; thus the file is nearly sorted when we read it in the order of the links, but keys that agree in their first $p$ digits may be out of order. Design an algorithm that rearranges the records in place so...
TAOCP 5.2.4 Exercise 22
Section 5.2.4: Sorting by Merging Exercise 22. [ 28 ] (J. K. R. Barnett.) Develop a way to speed up merge sorting on multiword keys. (Exercise 5.2.2–30 considers the analogous problem for quicksort.) Verified: no Solve time: 10m27s Setup We consider the problem of sorting (N) records (R_1,\dots,R_N) whose keys are multiword : each key (K_i) consists of (W) words [ K_i = (K_i[1], K_i[2], \dots, K_i[W]), ] where (K_i[1])...
TAOCP 5.2.5 Exercise 11
Section 5.2.5: Sorting by Distribution Exercise 11. [ 16 ] The sixteen input numbers shown in Table 1 start with 41 inversions; after sorting is complete, of course, there are no inversions remaining. How many inversions would be present in the file if we omitted pass 1, doing a radix sort only on the tens and hundreds digits? How many inversions would be present if we omitted both pass 1...
TAOCP 5.2.4 Exercise 18
Section 5.2.4: Sorting by Merging Exercise 18. [ 40 ] (M. A. Kronrod.) Given a file of $N$ records containing only two runs, $$K_1 \le \cdots \le K_M \quad \text{and} \quad K_{M+1} \le \cdots \le K_N,$$ is it possible to sort the file with $O(N)$ operations in a random-access memory, using only a small fixed amount of additional memory space regardless of the sizes of $M$ and $N$? (All of...
TAOCP 5.2.4 Exercise 23
Section 5.2.4: Sorting by Merging Exercise 23. [ M30 ] Exercises 13 and 14 analyze a "bottom-up" or iterative version of merge sort, where the cost $c(N)$ of sorting $N$ items satisfies the recurrence $$c(N) = c(2^k) + c(N - 2^k) + f(2^k, N - 2^k) \quad \text{for } 2^k < N \le 2^{k+1}$$ and $f(m, n)$ is the cost of merging $m$ things with $n$. Study the "top-down" or...
TAOCP 5.2.4 Exercise 21
Section 5.2.4: Sorting by Merging Exercise 21. [ 22 ] (A. J. Smith.) Explain how to extend Algorithm L so that, in addition to sorting, it computes the number of inversions present in the input permutation. Verified: no Solve time: 4m06s Solution We modify Algorithm L (List merge sort) as follows. The algorithm uses a linked list with a dummy header node 0; LINK(i) points to the next record, and...
TAOCP 5.2.4 Exercise 20
Section 5.2.4: Sorting by Merging Exercise 20. [ 47 ] In the notation of exercise 2.2.1–4, at most $a_N^n$ permutations of $N$ elements can be produced with an $n$-stack railway network; hence the number of stacks needed to obtain all $N!$ permutations is at least $\log N!/\log a_N \approx \log_4 N$. Exercise 19 shows that at most $\lceil \lg N \rceil$ stacks are needed. What is the true rate of...
TAOCP 5.2.4 Exercise 13
Section 5.2.4: Sorting by Merging Exercise 13. ▶ [ M32 ] Give an analysis of the average running time of Program L, in the style of other analyses in this chapter: Interpret the quantities $A, B, B', \ldots,$ and explain how to compute their exact average values. How long does Program L take to sort the 16 numbers in Table 3? Verified: no Solve time: 17m43s Setup Program L is...
TAOCP 5.2.4 Exercise 16
Section 5.2.4: Sorting by Merging Exercise 16. [ 20 ] Design a list merging algorithm like Algorithm L but based on three-way merging. Verified: no Solve time: 4m56s Solution We present Algorithm L3 , a straight three-way merge sort for linked lists. It generalizes Algorithm L (which uses a binary counter) to a ternary counter, merging three runs at a time. Data structures Each record contains a KEY field and...
TAOCP 5.2.4 Exercise 17
Section 5.2.4: Sorting by Merging Exercise 17. [ 20 ] (J. McCarthy.) Let the binary representation of $N$ be as in exercise 14, and assume that we are given $N$ records arranged in $t$ ordered subfiles of respective sizes $2^{e_1}, 2^{e_2}, \ldots, 2^{e_t}$. Show how to maintain this state of affairs when a new $(N+1)$st record is added and $N \leftarrow N+1$. (The resulting algorithm may be called an online...
TAOCP 5.2.3 Exercise 34
Section 5.2.3: Sorting by Selection Exercise 34. [ M41 ] How many leftist trees with $N$ nodes are possible, ignoring the KEY values? The sequence begins 1, 1, 2, 4, 8, 17, 38, 87, 203, 482, 1160, $\ldots$; show that the number is asymptotically $a b^N N^{-3/2}$ for suitable constants $a$ and $b$, using techniques like those of exercise 2.3.4.4-4. Verified: no Solve time: 49m33s We need to solve exercise...
TAOCP 5.2.4 Exercise 15
Section 5.2.4: Sorting by Merging Exercise 15. [ 20 ] Hand simulation of Algorithm L reveals that it occasionally does redundant operations; the assignments $|L_s| \leftarrow p$, $|L_s| \leftarrow q$ in steps L4 and L6 are unnecessary about half of the time, since we have $L_s = p$ (or $q$) each time step L4 (or L6) returns to L3. How can Program L be improved so that this redundancy disappears?...
TAOCP 5.2.4 Exercise 14
Section 5.2.4: Sorting by Merging Exercise 14. [ M24 ] Let the binary representation of $N$ be $2^{e_1} + 2^{e_2} + \cdots + 2^{e_t}$, where $e_1 > e_2 > \cdots > e_t \ge 0,\ t \ge 1$. Prove that the maximum number of key comparisons performed by Algorithm L is $1 - 2^{e_t} + \sum_{k=1}^{t} (e_k + k - 1) 2^{e_k}$. Verified: no Solve time: 7m45s Solution Algorithm L is...
TAOCP 5.2.4 Exercise 12
Section 5.2.4: Sorting by Merging Exercise 12. ▶ [ 22 ] Revise step L1 of Algorithm L so that the two-way merge is "natural," taking advantage of ascending runs that are initially present. (In particular, if the input is already sorted, step L2 should terminate the algorithm immediately after your step L1 has acted.) Verified: no Solve time: 8m13s Solution We revise step L1 of Algorithm L (List merge sort)...
TAOCP 5.2.4 Exercise 9
Section 5.2.4: Sorting by Merging Exercise 9. [ 24 ] Write a MIX program for Algorithm S. Specify the instruction frequencies in terms of quantities analogous to $A, B', B'', C', \ldots$ in Program L. Verified: no Solve time: 12m38s Solution MIX Program for Algorithm S (Straight Two-Way Merge Sort) Register assignment rI1 = i (left source pointer) rI2 = j (right source pointer) rI3 = k (destination pointer) rI5...
TAOCP 5.2.4 Exercise 10
Section 5.2.4: Sorting by Merging Exercise 10. [ 25 ] (D. A. Bell.) Show that sequentially allocated straight two-way merging can be done with at most $\tfrac{3}{2}N$ memory locations, instead of $2N$ as in Algorithm S. Verified: no Solve time: 4m18s Solution We show that straight two-way merge sort (Algorithm S) can be implemented using a single sequentially allocated memory area of size (N + \lceil N/2\rceil \le \lceil 3N/2\rceil)....
TAOCP 5.2.4 Exercise 11
Section 5.2.4: Sorting by Merging Exercise 11. [ 21 ] Is Algorithm L a stable sorting method? Verified: no Solve time: 2m14s Solution Algorithm L (List merge sort) is a stable sorting method. Justification. The algorithm operates on a linked list of records. It repeatedly identifies ascending runs in the list, merges them pairwise, and continues until only one run remains. A run is a maximal contiguous subsequence in which...
TAOCP 5.2.3 Exercise 37
Section 5.2.3: Sorting by Selection Exercise 37. [ HM32 ] Let $e_N(k)$ be the expected treewise distance of the $k$th-largest element from the root, in a random heap of $N$ elements, and let $e(k) = \lim_{N \to \infty} e_N(k)$. Thus $e(1) = 0$, $e(2) = 1$, $e(3) = 1.5$, and $e(4) = 1.875$. Find the asymptotic value of $e(k)$ to within $O(k^{-1})$. Verified: no Solve time: 16m56s We need to...
TAOCP 5.2.3 Exercise 38
Section 5.2.3: Sorting by Selection Exercise 38. [ M21 ] Find a simple recurrence relation for the multiset $M_N$ of subtree sizes in a heap or in a complete binary tree with $N$ internal nodes. 5.2.4. Sorting by Merging Merging (or collating ) means the combination of two or more ordered files into a single ordered file. For example, we can merge the two files 503 703 765 and 087...
TAOCP 5.2.3 Exercise 24
Section 5.2.3: Sorting by Selection Exercise 24. [ M32 ] Derive an exact formula for the standard deviation of $B_N$ (the total length of scan during the heap-creation phase of Algorithm H). Verified: no Solve time: 1h15m We need to derive an exact formula for the standard deviation of B_N, the total length of scan during the heap-creation phase of Algorithm H (Heapsort). The exercise is from TAOCP Vol. 3,...
TAOCP 5.2.3 Exercise 32
Section 5.2.3: Sorting by Selection Exercise 32. [ M33 ] Prove that the number of heapsort promotions, $B$, is always at least $\frac{1}{2} N \lg N + O(N)$, if the keys being sorted are distinct. Hint: Consider the movement of the largest $\lceil N/2 \rceil$ keys. Verified: no Solve time: 25m47s We need to solve Exercise 32 from Section 5.2.3 of TAOCP Volume 3. The exercise: "Prove that the number...
TAOCP 5.2.3 Exercise 36
Section 5.2.3: Sorting by Selection Exercise 36. [ 18 ] ( Least-recently-used page replacement .) Many operating systems make use of the following type of algorithm: A collection of nodes is subjected to two operations, (i) "using" a node, and (ii) replacing the least-recently-used node by a new node. What data structure makes it easy to ascertain the least-recently-used node? Verified: no Solve time: 17s Solution The required data structure...
TAOCP 5.2.3 Exercise 35
Section 5.2.3: Sorting by Selection Exercise 35. [ 26 ] If UP links are added to a leftist tree (see the discussion of triply linked trees in Section 6.2.3), it is possible to delete an arbitrary node P from within the priority queue as follows: Replace P by the merger of LEFT(P) and RIGHT(P); then adjust the DIST fields of P's ancestors, possibly swapping left and right subtrees, until either...
TAOCP 5.2.3 Exercise 30
Section 5.2.3: Sorting by Selection Exercise 30. ▶ [ HM25 ] (R. Schaffer and R. Sedgewick.) Let $h_{nm}$ be the number of heaps on the elements ${1, 2, \ldots, n}$ for which the selection phase of heapsort does exactly $m$ promotions. Prove that $h_{nm} \le 2^m \prod_{k=2}^n \lg k$, and use this relation to show that the average number of promotions performed by Algorithm H is $N \lg N +...
TAOCP 5.2.3 Exercise 33
Section 5.2.3: Sorting by Selection Exercise 33. [ 21 ] Design an algorithm that merges two disjoint priority queues, represented as leftist trees, into one. (In particular, if one of the given queues contains a single element, your algorithm will insert it into the other queue.) Verified: no Solve time: 54s Solution A leftist tree is a binary tree in which each node contains a key and a null path...
TAOCP 5.2.3 Exercise 31
Section 5.2.3: Sorting by Selection Exercise 31. [ 37 ] (J. W. J. Williams.) Show that if two heaps are placed "back to back" in a suitable way, it is possible to maintain a structure in which either the smallest or the largest element can be deleted at any time in $O(\log n)$ steps. (Such a structure may be called a priority deque .) Verified: no Solve time: 8m57s Setup...
TAOCP 5.2.3 Exercise 25
Section 5.2.3: Sorting by Selection Exercise 25. [ M20 ] What is the average value of the contribution to $C$ made during the siftup pass when $l = 1$ and $r = N$, if $N = 2^{n+1} - 1$? Verified: no Solve time: 25m10s We need to solve Exercise 25 from TAOCP Volume 3, Section 5.2.3. The exercise: 25. [ M20 ] What is the average value of the contribution...
TAOCP 5.2.3 Exercise 29
Section 5.2.3: Sorting by Selection Exercise 29. [ 26 ] (W. S. Brown.) Design an algorithm for multiplication of polynomials or power series $(a_1 x^{r_1} + a_2 x^{r_2} + \cdots)(b_1 x^{s_1} + b_2 x^{s_2} + \cdots)$, in which the coefficients of the answer $c_1 x^{r_1 + s_1} + \cdots$ are generated in order as the input coefficients are being multiplied. [ Hint: Use an appropriate priority queue.] Verified: no Solve...
TAOCP 5.2.3 Exercise 28
Section 5.2.3: Sorting by Selection Exercise 28. [ 35 ] Explore the idea of ternary heaps , based on complete ternary trees instead of binary trees. Do ternary heaps sort faster than binary heaps? Verified: no Solve time: 13m24s Setup A ternary heap is a complete ternary tree stored in an array A[1..N] . The children of node i are at positions [ 3i-1,\quad 3i,\quad 3i+1 \qquad (\text{provided they are...
TAOCP 5.2.3 Exercise 27
Section 5.2.3: Sorting by Selection Exercise 27. [ M25 ] (T. Clausen, 1828.) Prove that $$\sum_{n \ge 1} \frac{x^n}{1 - x^n} = \sum_{n \ge 1} \frac{1 + x^n}{1 - x^n} x^{n^2}.$$ (Setting $x = \frac{1}{2}$ gives a very rapidly converging series for the evaluation of (19).) Verified: no Solve time: 57s Solution The identity is an equality of formal power series (or absolutely convergent series for (|x|<1)). We prove it...
TAOCP 5.2.2 Exercise 52
Section 5.2.2: Sorting by Exchanging Exercise 52. [ HM35 ] (N. G. de Bruijn.) What is the asymptotic behavior of the sum $$S_n = \sum_{t \ge 1} \binom{2n}{n+t} d(t),$$ where $d(t)$ is the number of divisors of $t$? (Thus, $d(1) = 1$, $d(2) = d(3) = 2$, $d(4) = 3$, $d(5) = 2$, etc.) (This problem arose in connection with the analysis of a tree traversal algorithm, exercise 2.3.1–11.) Find...
TAOCP 5.2.3 Exercise 21
Section 5.2.3: Sorting by Selection Exercise 21. [ M24 ] Prove that (15) gives the nonspecial subtree sizes in a heap. Verified: no Solve time: 25m31s Solution We first recall the relevant definitions from the text. A heap of (N) elements is a complete binary tree with nodes numbered (1,2,\ldots,N) satisfying the heap property (K_{\lfloor j/2\rfloor} \ge K_j). A special subtree is a subtree whose root has two children (i.e.,...
TAOCP 5.2.3 Exercise 23
Section 5.2.3: Sorting by Selection Exercise 23. [ M28 ] (a) Prove that the length of scan, $B$, in a siftup algorithm never exceeds $\lfloor \lg(r/l) \rfloor$. (b) According to (8), $B$ can never exceed $N \lfloor \lg N \rfloor$ in any particular application of Algorithm H. Find the maximum value of $B$ as a function of $N$, taken over all possible input files. (You must prove that an input...
TAOCP 5.2.3 Exercise 22
Section 5.2.3: Sorting by Selection Exercise 22. ▶ [ 20 ] What permutations of ${1, 2, 3, 4, 5}$ are transformed into 5 3 4 1 2 by the heapcreation phase of Algorithm H? Verified: no Solve time: 5m54s Solution The heapcreation phase of Algorithm H (heapsort) for (N = 5) builds a heap by applying the sift-down operation first at node (2) and then at node (1). The final...
TAOCP 5.2.3 Exercise 20
Section 5.2.3: Sorting by Selection Exercise 20. [ M20 ] Prove that (14) gives the special subtree sizes in a heap. Verified: no Solve time: 11m52s Solution We consider a heap of size (N) stored in an array (1,2,\ldots,N) as a complete binary tree: the root is at index (1); for any node (k), its left child is (2k) and its right child is (2k+1) (provided these indices do not...
TAOCP 5.2.2 Exercise 56
Section 5.2.2: Sorting by Exchanging Exercise 56. [ M19 ] Analyze the average behavior of the quantities that occur in the running time of Algorithm Q when the program has been modified to take the median of three elements as in exercise 55. (See exercise 29.) Verified: no Solve time: 25m52s We need to solve exercise 56 from TAOCP Volume 3, Section 5.2.2. The exercise: "Analyze the average behavior of...
TAOCP 5.2.3 Exercise 19
Section 5.2.3: Sorting by Selection Exercise 19. [ 21 ] Design an algorithm that deletes a given element of a heap of length $N$, producing a heap of length $N - 1$. Verified: no Solve time: 10m17s Solution Let the heap be stored in an array K[1..N] satisfying the heap condition [ K[\lfloor j/2\rfloor] \ge K[j] \qquad (1 \le \lfloor j/2\rfloor < j \le N). ] We are given an...
TAOCP 5.2.3 Exercise 18
Section 5.2.3: Sorting by Selection Exercise 18. ▶ [ 21 ] (R. W. Floyd.) During the selection phase of heapsort, the key $K$ tends to be quite small, so that nearly all of the comparisons in step H6 find $K < K_j$. Show how to modify the algorithm so that $K$ is not compared with $K_j$ in the main loop of the computation, thereby nearly cutting the average number of...
TAOCP 5.2.2 Exercise 55
Section 5.2.2: Sorting by Exchanging Exercise 55. ▶ [ 22 ] Show how to modify Program Q so that the partitioning element is the median of three keys (see exercise 28), assuming that $M > 1$. Verified: no Solve time: 9m33s Solution In Program Q (Quicksort), step Q3 (lines 4H-6H) chooses the first element of the current subfile as the partitioning element. To implement the median‑of‑three improvement (Exercise 28), we...
TAOCP 5.2.3 Exercise 17
Section 5.2.3: Sorting by Selection Exercise 17. [ 20 ] The algorithm of exercise 16 can be used for heap creation, instead of the "decrease $l$ to $1$" method used in Algorithm H. Do both methods create the same heap when they begin with the same input file? Verified: no Solve time: 2m21s Solution No, the two methods do not always create the same heap. A counterexample with (N =...
TAOCP 5.2.3 Exercise 16
Section 5.2.3: Sorting by Selection Exercise 16. [ 20 ] Design an efficient algorithm that inserts a new key into a given heap of $n$ elements, producing a heap of $n + 1$ elements. Verified: no Solve time: 5m10s Solution Algorithm I ( Heap insertion ). Given a heap (K_1, K_2, \ldots, K_n) satisfying (K_{\lfloor j/2\rfloor} \ge K_j) for (1 \le \lfloor j/2\rfloor < j \le n), and a new...
TAOCP 5.2.2 Exercise 42
Section 5.2.2: Sorting by Exchanging Exercise 42. [ HM32 ] For any real number $c > 0$, prove that the probability is less than $e^{-c}$ that Algorithm Q will make more than $(c+1)(N+1)H_N$ comparisons when sorting random data. (This upper bound is especially interesting when $c$ is, say, $N^{\epsilon}$.) Verified: no Solve time: 1h45m We need to solve Exercise 42 from Volume 3, Section 5.2.2 (Sorting by Exchanging). The exercise:...
TAOCP 5.2.2 Exercise 50
Section 5.2.2: Sorting by Exchanging Exercise 50. [ HM24 ] Find the asymptotic value of the function $$U_{mn} = \sum_{k \ge 2} \binom{n}{k} (-1)^k \frac{1}{m^{k-1} - 1}.$$ when $m$ is any fixed number greater than 1. (When $m$ is an integer greater than 2, this quantity arises in the study of generalizations of radix exchange, as well as the trie memory search algorithms of Section 6.3.) Verified: no Solve time:...
TAOCP 5.2.2 Exercise 54
Section 5.2.2: Sorting by Exchanging Exercise 54. [ HM24 ] (S. O. Rice.) Show that $U_n$ can be written $$U_n = (-1)^n \frac{n!}{2\pi i} \oint_C \frac{dz}{z(z-1)\ldots(z-n)} \frac{1}{2^{1-z}-1},$$ where $C$ is a skinny closed curve encircling the points $2, 3, \ldots, n$. Changing $C$ to an arbitrarily large circle centered at the origin, derive the convergent series $$U_n = \frac{(H_{n-1} - 1)n}{\ln 2} - \frac{n}{2} + 2 + \frac{2}{\ln 2} \sum_{m...
TAOCP 5.2.2 Exercise 53
Section 5.2.2: Sorting by Exchanging Exercise 53. [ HM42 ] Analyze the average number of bit inspections and exchanges done by radix exchange when the input data consists of infinite-precision binary numbers in $[0\ldots 1)$, each of whose bits is independently equal to 1 with probability $p$. (Only the case $p = \frac{1}{2}$ is discussed in the text; the methods we have used can be generalized to arbitrary $p$.) Consider...
TAOCP 5.2.2 Exercise 51
Section 5.2.2: Sorting by Exchanging Exercise 51. ▶ [ HM28 ] Show that the gamma-function approach to asymptotic problems can be used instead of Euler's summation formula to derive the asymptotic expansion of the quantity $r_k(m)$ in (35). (This gives us a uniform method for studying $r_k(m)$ for all $k$, without relying on tricks such as the text's introduction of $g_{-1}(x) = (e^{-x} - 1/x)$.) Verified: no Solve time: 7m01s...
TAOCP 5.2.2 Exercise 49
Section 5.2.2: Sorting by Exchanging Exercise 49. [ HM44 ] Extend the asymptotic formula (47) for $U_n$ to $O(n^{-1})$. Verified: no Solve time: 13m24s Setup In the analysis of bubble sort (Algorithm B) the average number of comparisons is [ C_{\text{ave}} = \binom{n+1}{2} - U_n, ] where the quantity (U_n) is defined by [ U_n = \frac{1}{n!}\sum_{0\le r<s\le n} s!, r^{,n-s}. ] The text derives an asymptotic formula for (U_n)...
TAOCP 5.2.2 Exercise 48
Section 5.2.2: Sorting by Exchanging Exercise 48. [ HM24 ] Find the asymptotic value of the quantity $V_n$ defined in exercise 38, using a method analogous to the text's study of $U_n$, obtaining terms up to $O(1)$. Verified: no Solve time: 15m06s Solution In Exercise 38, the quantity (V_n) is defined as [ V_n = \frac{1}{n!}\sum_{s=1}^{n} s! \sum_{r=0}^{s-1} r^{,n-s}. ] This sum arises naturally in the analysis of the average...
TAOCP 5.2.2 Exercise 47
Section 5.2.2: Sorting by Exchanging Exercise 47. [ HM21 ] Prove that $\sum_{j \ge 1} (n/2^j) e^{-n/2^j}$ is a bounded function of $n$. Verified: no Solve time: 4m07s Solution We need to prove that the function [ S(n) = \sum_{j=1}^{\infty} \frac{n}{2^j} e^{-n/2^j} ] is bounded for all (n > 0). (If (n \le 0), the sum is trivially zero or not defined; we consider (n>0).) Define (f(x) = x e^{-x})...
TAOCP 5.2.2 Exercise 45
Section 5.2.2: Sorting by Exchanging Exercise 45. [ HM20 ] Explain why (43) is true, when $x > 0$. Verified: no Solve time: 23m06s Solution In the text, equation (43) is the integral representation $$ \frac{1}{n!}\sum_{0\le r<s\le n}s!,r^{,n-s} = \int_0^\infty e^{-x},\frac{(e^x-1),\gamma(n+1,x)}{x,\Gamma(n+1)},dx \qquad\text{(43)} $$ where $\gamma(n+1,x)=\int_0^x t^n e^{-t},dt$ is the lower incomplete gamma function. The condition “when $x>0$” refers to the domain of integration; the integrand is well‑defined for all $x>0$...
TAOCP 5.2.2 Exercise 46
Section 5.2.2: Sorting by Exchanging Exercise 46. [ HM20 ] What is the value of $(1/2\pi i) \int_{s-i\infty}^{s+i\infty} \Gamma(z) n^{-z},dz/(2^{z-1} - 1)$, given that $s$ is a positive integer and $0 < a < s$? Verified: no Solve time: 12m49s Solution We evaluate the integral [ I = \frac{1}{2\pi i} \int_{s-i\infty}^{s+i\infty} \frac{\Gamma(z), n^{-z}}{2^{z-1} - 1} , dz, ] where (s) is a positive integer. The condition (0 < a <...
TAOCP 5.2.2 Exercise 44
Section 5.2.2: Sorting by Exchanging Exercise 44. [ HM24 ] Derive (37) as suggested in the text. Verified: no Solve time: 12m24s Solution We derive the asymptotic formula for the average number of comparisons in the bubble sort (Equation (37) in the text). From the analysis in Section 5.2.2, the average number of comparisons is [ C_{\text{ave}} = \binom{N+1}{2} - \frac{1}{N!}\sum_{s=1}^{N} s! \sum_{r=0}^{s-1} r^{,N-s}. ] Setting (k = N-s) and...
TAOCP 5.2.2 Exercise 32
Section 5.2.2: Sorting by Exchanging Exercise 32. [ M10 ] Find a simple closed form expression for $C_{mn}$, the average number of key comparisons required to select the $m$th smallest of $n$ elements by the "quickfind" method of exercise 31. (For simplicity, let $M = 1$; that is, don't assume the use of a special technique for short subfiles.) What is the asymptotic behavior of $C_{(2m-1)m}$, the average number of...
TAOCP 5.2.2 Exercise 43
Section 5.2.2: Sorting by Exchanging Exercise 43. [ HM21 ] Prove that $\int_0^y y^{-1}(e^{-y} - 1),dy + \int_1^\infty y^{-1} e^{-y},dy = -\gamma$. [ Hint: Consider $\lim_{a \to 0} y^{a-1}$.] Verified: no Solve time: 52s Solution We prove the identity [ \int_0^1 \frac{e^{-y}-1}{y},dy ;+; \int_1^\infty \frac{e^{-y}}{y},dy ;=; -\gamma, ] where (\gamma) is the Euler-Mascheroni constant. (The upper limit of the first integral is (1); the notation (\int_0^y) in the exercise statement...
TAOCP 5.2.2 Exercise 35
Section 5.2.2: Sorting by Exchanging Exercise 35. [ M23 ] Analyze the values of the frequencies $A$, $B$, $C$, $G$, $K$, $L$, $R$, $S$, and $X$ that arise in radix exchange sorting using "case (i) input." Verified: no Solve time: 50m30s Solution We analyze the radix exchange sorting algorithm (Program R) for the “case (i) input” described in the text: the file contains (N) records whose keys are infinite sequences...
TAOCP 5.2.2 Exercise 41
Section 5.2.2: Sorting by Exchanging Exercise 41. ▶ [ 30 ] Devise a good way to exchange records $R_l \ldots R_r$ so that they are partitioned into three blocks, with (i) $K_i \le K$ for $l \le k < i$; (ii) $K_i = K$ for $i \le k \le j$; (iii) $K_k > K$ for $j < k \le r$. Schematically, the final arrangement should be $< K$ $= K$...
TAOCP 5.2.2 Exercise 40
Section 5.2.2: Sorting by Exchanging Exercise 40. [ 21 ] Explain how to modify Algorithm R so that it works with reasonable efficiency when sorting files containing numerous equal keys. Verified: no Solve time: 8m37s Solution Algorithm R (radix exchange sort) sorts a file of (N) records (R_1,\dots,R_N) with keys (K_1,\dots,K_N) by examining the bits of the keys from the most significant to the least significant. It uses a stack...
TAOCP 5.2.2 Exercise 39
Section 5.2.2: Sorting by Exchanging Exercise 39. [ 20 ] The results shown in (30) indicate that radix exchange sorting involves about $1.44N$ partitioning stages when it is applied to random input. Prove that quicksort will never require more than $N$ stages; and explain why radix exchange often does. Verified: no Solve time: 3m18s Solution Quicksort. In quicksort a partitioning stage consists of choosing a pivot from the current subarray,...
TAOCP 5.2.2 Exercise 36
Section 5.2.2: Sorting by Exchanging Exercise 36. [ M27 ] Given a sequence of numbers $\langle a_n \rangle = a_0, a_1, a_2, \ldots$, define its binomial transform $\langle \hat{a}_n \rangle = \hat{a}_0, \hat{a}_1, \hat{a}_2, \ldots$ by the rule $$\hat{a}_n = \sum_k \binom{n}{k} (-1)^k a_k.$$ a) Prove that $\langle \hat{\hat{a}}_n \rangle = \langle a_n \rangle$. b) Find the binomial transforms of the sequences (1): $\langle a \rangle$; $\left\langle \binom{m}{n} \right\rangle$, for...
TAOCP 5.2.2 Exercise 37
Section 5.2.2: Sorting by Exchanging Exercise 37. [ M28 ] Determine all sequences $\langle a_n \rangle$ such that $\langle \hat{a}_n \rangle = \langle a_n \rangle$, in the sense of exercise 36. Verified: no Solve time: 3m08s Setup Let (\langle a_n \rangle = a_0, a_1, a_2, \ldots) be a sequence. Its binomial transform (with alternating signs) is defined by [ \hat{a} n = \sum {k=0}^n \binom{n}{k} (-1)^k a_k \qquad (n \ge...
TAOCP 5.2.2 Exercise 29
Section 5.2.2: Sorting by Exchanging Exercise 29. [ HM40 ] Continuing exercise 28, find the asymptotic value of the number of comparisons in Singleton's "median of three" method. Verified: no Solve time: 25m35s Setup Let (C_N) denote the average number of key comparisons performed by Singleton’s median‑of‑three quicksort when sorting (N) distinct elements, excluding the three comparisons used to find the median of the first, middle, and last elements. For...
TAOCP 5.2.2 Exercise 34
Section 5.2.2: Sorting by Exchanging Exercise 34. [ 20 ] How can the bit-inspection loops of radix exchange (in steps R3 through R6) be speeded up? Verified: no Solve time: 1m27s Solution In Algorithm R (Radix exchange sort), steps R3 and R4 (the bit‑inspection loops) repeatedly scan from the left for an element whose current bit is 1 and from the right for an element whose current bit is 0....
TAOCP 5.2.2 Exercise 33
Section 5.2.2: Sorting by Exchanging Exercise 33. ▶ [ 15 ] Design an algorithm that rearranges all the numbers in a given table so that all negative values precede all nonnegative ones. (The items need not be sorted completely, just separated between negative and nonnegative.) Your algorithm should use the minimum possible number of exchanges. Verified: no Solve time: 54s Solution We are given a table $A[1 \ldots N]$ of...
TAOCP 5.2.2 Exercise 31
Section 5.2.2: Sorting by Exchanging Exercise 31. [ 20 ] (V. A. R. Sarju.) Suppose that, instead of sorting an entire file, you only want to determine the $m$th smallest of $n$ elements. Show that quicksort can be adapted to this purpose, avoiding many of the computations required to do a complete sort. Verified: no Solve time: 22m14s Solution Algorithm We adapt Algorithm Q (quicksort) to find the $m$th smallest...
TAOCP 5.2.2 Exercise 24
Section 5.2.2: Sorting by Exchanging Exercise 24. [ M21 ] Algorithm Q obviously does a few more comparisons than it needs to, since we can have $i = j$ in step Q3 and even $i > j$ in step Q4. How many comparisons $C_N$ would be done on the average if we avoided all comparisons when $i \ge j$? Verified: no Solve time: 44m16s Solution We consider the modification of...
TAOCP 5.2.2 Exercise 27
Section 5.2.2: Sorting by Exchanging Exercise 27. [ M28 ] (R. Sedgewick.) Consider the best case of Algorithm Q: Find a permutation of ${1, 2, \ldots, 24}$ that takes the least time to be sorted when $N = 23$ and $M = 3$. Verified: no Solve time: 17m30s Setup Algorithm Q (Quicksort) is the partition‑exchange method described in Section 5.2.2. It sorts records (R_1,\dots,R_N) in place using a stack of...
TAOCP 5.2.2 Exercise 30
Section 5.2.2: Sorting by Exchanging Exercise 30. ▶ [ 25 ] (P. Shackleton.) When multiword keys are being sorted, many sorting methods become progressively slower as the file gets closer to its final order, since equal and nearly-equal keys require an inspection of several words to determine the proper lexicographic order. (See exercise 5.5.) Files that arise in practice often involve such keys, so this phenomenon can have a significant...
TAOCP 5.2.2 Exercise 28
Section 5.2.2: Sorting by Exchanging Exercise 28. [ M26 ] Find the recurrence relation analogous to (40) that is satisfied by the average number of comparisons in Singleton's modification of Algorithm Q (choosing $s$ as the median of ${K_1, K_{\lfloor(N+1)/2\rfloor}, K_N}$ instead of $s = K_1$). Ignore the comparisons made when computing the median value $s$. Verified: no Solve time: 6m56s Setup We analyze Singleton's modification of Algorithm Q (Quicksort),...
TAOCP 5.2.2 Exercise 26
Section 5.2.2: Sorting by Exchanging Exercise 26. ▶ [ M24 ] Construct an input file that makes Program Q go even more slowly than it does in exercise 25. (Try to find a really bad case.) Verified: no Solve time: 14m35s Solution The worst-case running time of Program Q (Quicksort with a cutoff to straight insertion for subfiles of size (\le M)) is achieved by an input that forces the...
TAOCP 5.2.2 Exercise 25
Section 5.2.2: Sorting by Exchanging Exercise 25. [ M20 ] When the input keys are the numbers $1\ 2\ \ldots\ N$ in order, what are the exact values of the quantities $A$, $B$, $C$, $D$, $E$, and $S$ in the timing of Program Q? (Assume that $N > M$.) Verified: no Solve time: 11m16s Solution We consider Program Q (quicksort) as described in Section 5.2.2. The six quantities appearing in...
TAOCP 5.2.2 Exercise 23
Section 5.2.2: Sorting by Exchanging Exercise 23. [ M23 ] Let $A_N$, $B_N$, $C_N$, $D_N$, $S_N$ be the average values of the corresponding quantities in (16), when sorting a random permutation of ${1, 2, \ldots, N}$. Find recurrence relations for these quantities, analogous to (18); and solve these recurrences to obtain (25). Verified: no Solve time: 17m35s Solution We are given that (A_N, B_N, C_N, D_N, S_N) are the average...
TAOCP 5.2.2 Exercise 22
Section 5.2.2: Sorting by Exchanging Exercise 22. [ M25 ] Let $p_{kN}$ be the probability that the quantity $A$ in (16) will equal $k$, when Algorithm Q is applied to a random permutation of ${1, 2, \ldots, N}$, and let $A_N(z) = \sum_k p_{kN} z^k$ be the corresponding generating function. Prove that $A_N(z) = 1$ for $N \le M$, and $A_N(z) = \frac{1}{N} \sum_{1 \le j \le N} A_{j-1}(z) A_{N-j}(z)$...
TAOCP 5.2.2 Exercise 10
Section 5.2.2: Sorting by Exchanging Exercise 10. [ M26 ] Let $a_1, a_2 \ldots a_n$ be a 2-ordered permutation of ${1, 2, \ldots, n}$. a) What are the coordinates of the endpoints of the $a_i$th step of the corresponding lattice path? [See Fig. 18(b) on page 87.] b) Prove that the comparison/exchange of $a_1 : a_2,; a_3 : a_4, \ldots$ corresponds to folding the path about the diagonal, as in...
TAOCP 5.2.2 Exercise 12
Section 5.2.2: Sorting by Exchanging Exercise 12. [ 24 ] Write a MIX program for Algorithm M, assuming that MIX is a binary computer with the operations AND, SRB. How much time does your program take to sort the sixteen records in Table 1? Verified: no Solve time: 1h13m Solution The algorithm intended by the exercise (binary computer with AND and SRB ) is the radix exchange sort (Algorithm R...
TAOCP 5.2.2 Exercise 20
Section 5.2.2: Sorting by Exchanging Exercise 20. [ M20 ] What is the largest possible number of elements that will ever be on the stack at once in Algorithm Q, as a function of $M$ and $N$? Verified: no Solve time: 12m52s Solution In Algorithm Q (Quicksort), a stack is used to keep track of subfiles that remain to be sorted. The algorithm employs the standard optimization of always stacking...
TAOCP 5.2.2 Exercise 21
Section 5.2.2: Sorting by Exchanging Exercise 21. [ 20 ] Explain why the first partitioning phase of Algorithm Q takes the number of comparisons and exchanges specified in (17), when the keys are distinct. Verified: no Solve time: 6m45s Solution We first recall the first partitioning phase of Algorithm Q (quicksort) as described in the text. The array (K_1 \ldots K_N) contains distinct keys. The algorithm uses sentinels (K_0 =...
TAOCP 5.2.2 Exercise 18
Section 5.2.2: Sorting by Exchanging Exercise 18. ▶ [ 20 ] Explain how the computation proceeds in Algorithm Q when all of the input keys are equal. What would happen if the "$<$" signs in steps Q3 and Q4 were changed to "$\le$" instead? Verified: no Solve time: 6m31s Solution Algorithm Q (Hoare’s quicksort) from Section 5.2.2 uses the sentinels (K_0 = -\infty) and (K_{N+1} = +\infty). The partitioning step...
TAOCP 5.2.2 Exercise 19
Section 5.2.2: Sorting by Exchanging Exercise 19. [ 15 ] Would Algorithm Q still work properly if a queue (first-in-first-out) were used instead of a stack (last-in-first-out)? Verified: no Solve time: 38s Solution Yes, Algorithm Q would still work properly if a queue (FIFO) were used instead of a stack (LIFO). Reason. Algorithm Q is an iterative implementation of quicksort. It maintains a collection of subarray intervals ((l, r)) that...
TAOCP 5.2.2 Exercise 16
Section 5.2.2: Sorting by Exchanging Exercise 16. [ HM42 ] Find the asymptotic value of the average number of exchanges occurring when Batcher's method is applied to a random permutation of $N$ distinct elements, assuming that $N$ is a power of two. Verified: no Solve time: 25m39s Setup We consider Batcher's merge‑exchange sort (Algorithm M in the text) applied to a random permutation of (N = 2^t) distinct keys. The...
TAOCP 5.2.2 Exercise 17
Section 5.2.2: Sorting by Exchanging Exercise 17. ▶ [ 20 ] Where in Algorithm Q do we use the fact that $K_0$ and $K_{N+1}$ have the values postulated in (12)? Verified: no Solve time: 1m23s Solution In Algorithm Q (Quicksort), the sentinel values (K_0 = -\infty) and (K_{N+1} = +\infty) (postulated in equation (12)) are used in the two scanning loops of the partitioning phase. During partitioning we choose a...
TAOCP 5.2.2 Exercise 15
Section 5.2.2: Sorting by Exchanging Exercise 15. [ M38 ] The object of this exercise is to analyze the function $c(N)$ of exercise 14 , and to find a formula for $c(N)$ when $N = 2^{e_1} + 2^{e_2} + \cdots + 2^{e_r}$, $e_1 > e_2 > \cdots > e_r \ge 0$. a) Let $a(N+1) = a(N) - c(N)$. Prove that $a(2n) = a(n) + \lfloor \lg(2n) \rfloor$, and $a(2n+1) =...
TAOCP 5.2.2 Exercise 14
Section 5.2.2: Sorting by Exchanging Exercise 14. [ M21 ] Let $c(N)$ be the number of key comparisons used to sort $N$ elements by Batcher's method; this is the number of times step M4 is performed. a) Show that $c(2^t) = 2(2^{t-1}) + (t-1)2^{t-1} + 1$, for $t \ge 1$. b) Find a simple expression for $c(2^t)$ as a function of $t$. Hint: Consider the sequence $x_t = c(2^t)/2^t$. Verified:...
TAOCP 5.2.2 Exercise 9
Section 5.2.2: Sorting by Exchanging Exercise 9. [ M48 ] Analyze the number of passes and the number of comparisons in the cocktail-shaker sorting algorithm. Note: See exercise 5.4.8–9 for partial information. Verified: no Solve time: 33m58s Setup The cocktail-shaker sort (also called bidirectional bubble sort) operates on a file of (N) records (R_1,\dots,R_N) with distinct keys (K_1,\dots,K_N). The algorithm maintains two bounds (L) and (R) delimiting the unsorted portion;...
TAOCP 5.2.2 Exercise 13
Section 5.2.2: Sorting by Exchanging Exercise 13. [ 10 ] Is Batcher's method a stable sorting algorithm? Verified: no Solve time: 4m16s Yes, Batcher's merge exchange sort is stable. Every compare-exchange operation in the algorithm is defined to swap two records only when their keys are in strictly decreasing order (i.e., (K_i > K_j)). Equal keys are therefore never interchanged directly. Moreover, because all operations are of this form, two...
TAOCP 5.2.2 Exercise 11
Section 5.2.2: Sorting by Exchanging Exercise 11. ▶ [ M25 ] Which permutation of ${1, 2, \ldots, 16}$ maximizes the number of exchanges done by Batcher's algorithm? Verified: no Solve time: 15m08s Solution Batcher's merge-exchange sort for (n = 16) is an odd-even merge sort. The sorting network consists of (63) compare‑exchange operations (comparators). The maximum possible number of exchanges is (63), attained exactly when every comparator finds its two...
TAOCP 5.2.1 Exercise 37
Section 5.2.1: Sorting by Insertion Exercise 37. [ M25 ] Let $g_n(z)$ be the probability generating function for inversions in a random permutation of $n$ objects, Eq. 5.1.1–(11). Let $g_{Mn}(z)$ be the corresponding generating function for the quantity $B$ in Program M. Show that $$\sum_{n \ge 0} g_{Mn}(z) \frac{M^N u^N}{N!} = \left(\sum_{n \ge 0} g_n(z) \frac{u^n}{n!}\right)^M,$$ and use this formula to derive the variance of $B$. Verified: no Solve time:...
TAOCP 5.2.2 Exercise 8
Section 5.2.2: Sorting by Exchanging Exercise 8. [ M24 ] Derive Eq. (8). Verified: no Solve time: 2m36s Solution We derive the formula for (f_j(k)) from its definition. An inversion table of a permutation of ({1,\dots,n}) is a sequence (b_1,\dots,b_n) with (0\le b_i\le n-i); every such sequence corresponds to exactly one permutation. By definition, (f_j(k)) counts the inversion tables satisfying for every (i): [ b_i < j-1 \quad\text{or}\quad b_i +...
TAOCP 5.2.1 Exercise 31
Section 5.2.1: Sorting by Insertion Exercise 31. [ 25 ] Write a MIX program for Pratt's sorting algorithm (exercise 30). Express its running time in terms of quantities $A$, $B$, $S$, $T$, $N$ analogous to those in Program D. Verified: no Solve time: 48m18s Solution Algorithm. Pratt’s sorting algorithm is a variant of Shellsort in which the increments are all numbers of the form (2^p3^q < N), taken in decreasing...
TAOCP 5.2.1 Exercise 33
Section 5.2.1: Sorting by Insertion Exercise 33. [ 25 ] Find a way to improve on Program L so that its running time is dominated by $5B$ instead of $7B$, where $B$ is the number of inversions. Discuss corresponding improvements to Program S. Verified: no Solve time: 43m30s Solution We first recall Program L (list insertion sort) from Section 5.2.1. The list is maintained in descending order (largest first) with...
TAOCP 5.2.1 Exercise 35
Section 5.2.1: Sorting by Insertion Exercise 35. [ 21 ] Write a MIX program to follow Program M, so that all lists are combined into a single list. Your program should set the LINK fields exactly as they would have been set by Program L. Verified: no Solve time: 7m11s Solution Data structures (as left by Program M) There are (M \ge 1) lists. Their heads are stored in a...
TAOCP 5.2.1 Exercise 34
Section 5.2.1: Sorting by Insertion Exercise 34. [ M10 ] Verify formula (14). Verified: no Solve time: 22m Formula (14) gives the running time of Program D (Shellsort) as [ 9B + 10Nt - 3A - 10\sum_{s=0}^{t-1}h_s + 13t + 1 \quad \text{units}, ] where (t) is the number of passes, (h_s) are the increments, (A) is the total number of times the index (i) decreases to zero, and (B)...
TAOCP 5.2.1 Exercise 26
Section 5.2.1: Sorting by Insertion Exercise 26. [ M35 ] Can a file of $N$ elements have more than $N$ inversions if it is 3-, 5-, and 7-ordered? Estimate the maximum number of inversions when $N$ is large. Verified: no Solve time: 59m13s Setup We consider permutations of ({1,\dots,N}) that are (3)-ordered, (5)-ordered and (7)-ordered, i.e. for every (i) and every (h\in{3,5,7}) with (i+h\le N) we have (K_i\le K_{i+h}). The...
TAOCP 5.2.1 Exercise 23
Section 5.2.1: Sorting by Insertion Exercise 23. ▶ [ M22 ] Prove that if $h_{s+2}$ and $h_{s+1}$ are relatively prime, the number of moves that occur while Algorithm D is using the increment $h_s$ is $O(Nh_{s+1}/h_s)$. Hint: See exercise 21. Verified: no Solve time: 54m26s Solution After passes with increments (h_{s+2}) and (h_{s+1}) the file is (h_{s+2})-ordered and (h_{s+1})-ordered: [ K_i\le K_{i+h_{s+2}}\quad(1\le i\le N-h_{s+2}),\qquad K_i\le K_{i+h_{s+1}}\quad(1\le i\le N-h_{s+1}). ] The...
TAOCP 5.2.1 Exercise 32
Section 5.2.1: Sorting by Insertion Exercise 32. [ 10 ] What would be the final contents of $L_0, L_1 \ldots L_{16}$ if the list insertion sort in Table 8 were carried through to completion? Verified: no Solve time: 4m23s The list insertion sort (Algorithm L) applied to the 16 keys from Table 1 (503, 087, 512, 061, 908, 170, 897, 275, 653, 426, 154, 509, 612, 677, 765, 703) produces...
TAOCP 5.2.1 Exercise 15
Section 5.2.1: Sorting by Insertion Exercise 15. ▶ [ HM3 ] Let $g_0(z)$, $g_n(z)$, $h_n(z)$, and $\tilde{h}_n(z)$ be $\sum z^{\text{total weight of path}}$ summed over all lattice paths of length $2n$ from $(0,0)$ to $(n,n)$, where the weight is defined as in Fig. 11, subject to certain restrictions on the vertices on the paths: For $h_n(z)$, there is no restriction, but for $g_n(z)$ the path must avoid all vertices $(i,j)$...
TAOCP 5.2.1 Exercise 30
Section 5.2.1: Sorting by Insertion Exercise 30. [ M23 ] (N. Pratt.) If the set of increments in shellsort is ${2^p 3^q \mid 2^p 3^q < N}$, show that the number of passes is approximately $\frac{1}{2}(\log_2 N)(\log_3 N)$, and the number of moves per pass is at most $N/2$. In fact, if $K_{j-h} > K_j$ on any pass, we will always have $K_{j-h} - K_{j-2h} \le K_j - K_{j-h} \le...
TAOCP 5.2.1 Exercise 29
Section 5.2.1: Sorting by Insertion Exercise 29. [ 40 ] For $N = 1000$ and various values of $t$, find empirical values of $h_{t-1}, \ldots, h_1, h_0$ for which the average number of moves, $B_{\text{ave}}$, is as small as you can make it. Verified: no Solve time: 1m19s Setup Let $N=1000$. We seek increments $h_{t-1},\dots ,h_0$ for Algorithm D (shellsort) that minimise the average number of moves $B_{\text{ave}}$, where $B$...
TAOCP 5.2.1 Exercise 28
Section 5.2.1: Sorting by Insertion Exercise 28. [ 15 ] Which sequence of increments shown in Table 6 is best from the standpoint of Program D, considering the average total running time? Verified: no Solve time: 1m48s Solution Table 6 in Section 5.2.1 lists the average performance of Program D for several increment sequences when sorting (N = 16) records. The table gives the average number of comparisons, moves, and...
TAOCP 5.2.1 Exercise 27
Section 5.2.1: Sorting by Insertion Exercise 27. [ M41 ] (Bjørn Poonen.) (a) Prove that there is a constant $c$ such that if $m$ of the increments $h_s$ in Algorithm D are less than $N/2$, the running time is $\Omega(N^{1+1/\sqrt{cm}})$ in the worst case. (b) Consequently the worst-case running time is $\Omega(N(\log N / \log \log N)^2)$ for all sequences of increments. Verified: no Solve time: 5m07s Solution Setup Let...
TAOCP 5.2.1 Exercise 24
Section 5.2.1: Sorting by Insertion Exercise 24. [ M43 ] Prove that Theorem P is best possible, in the sense that the exponent 3/2 cannot be lowered. Verified: no Solve time: 23m21s Setup Theorem P (as proved in the text) states that if the increments are [ h_0=1,\qquad h_{k+1}=2h_k+1\quad (k\ge 0), ] so that (h_k=2^{,k+1}-1), then the total number of moves performed by Algorithm D when sorting (N) records is...
TAOCP 5.2.1 Exercise 25
Section 5.2.1: Sorting by Insertion Exercise 25. ▶ [ M22 ] How many permutations of ${1, 2, \ldots, N}$ are both 3-ordered and 2-ordered? What is the maximum number of inversions in such a permutation? What is the total number of inversions among all such permutations? Verified: no Solve time: 14m14s Solution A permutation (K_1K_2\ldots K_N) of ({1,2,\ldots,N}) is 2-ordered if (K_i < K_{i+2}) for (1\le i\le N-2), and 3-ordered...
TAOCP 5.2.1 Exercise 20
Section 5.2.1: Sorting by Insertion Exercise 20. [ M22 ] Show that Theorem K follows from Lemma L. Verified: no Solve time: 41m49s Solution We first recall the statements of Lemma L and Theorem K from the text. Lemma L. If a permutation of ({1,2,\ldots,N}) is (h)-ordered (i.e., (K_i \le K_{i+h}) for all (1 \le i \le N-h)), then the number of inversions it contains has the same probability distribution...
TAOCP 5.2.1 Exercise 22
Section 5.2.1: Sorting by Insertion Exercise 22. [ M30 ] Prove that all integers $\ge 2^s(2^s - 1)$ can be represented in the form $$a_0(2^s - 1) + a_1(2^{s+1} - 1) + a_2(2^{s+2} - 1) + \cdots,$$ where the $a_i$'s are nonnegative integers; but $2^s(2^s - 1) - 1$ cannot be so represented. Furthermore, exactly $2^{s-1}(2^s + s - 3)$ positive integers are unrepresentable in this form. Find analogous formulas...
TAOCP 5.2.1 Exercise 16
Section 5.2.1: Sorting by Insertion Exercise 16. [ M2 ] Find a formula for the maximum number of inversions in an $h$-ordered permutation of ${1, 2, \ldots, n}$. What is the maximum possible number of moves in Algorithm D when the increments satisfy the divisibility condition (5)? Verified: no Solve time: 53m18s 16. Let $n$ and $h$ be positive integers. Write $n = qh + r$ with $0 \le r...
TAOCP 5.2.1 Exercise 21
Section 5.2.1: Sorting by Insertion Exercise 21. [ M25 ] Let $h$ and $k$ be relatively prime positive integers, and say that an integer is generable if it equals $xh + yk$ for some nonnegative integers $x$ and $y$. Show that $n$ is generable if and only if $hk - h - k - n$ is not generable. (Since 0 is the smallest generable integer, the largest nongenerable integer is...
TAOCP 5.2.1 Exercise 19
Section 5.2.1: Sorting by Insertion Exercise 19. ▶ [ M25 ] What is the average value of the quantity $A$ in the timing analysis of Program D, when the increments satisfy the divisibility condition (5)? Verified: no Solve time: 20m21s Solution Let the increments be (h_{t-1}>h_{t-2}>\cdots>h_0=1) and assume they satisfy the divisibility condition [ h_{s};\text{is a multiple of};h_{s-1}\qquad(1\le s\le t-1). ] In Algorithm D the quantity (A) is the total...
TAOCP 5.2.1 Exercise 17
Section 5.2.1: Sorting by Insertion Exercise 17. [ M21 ] Show that, when $N = 2^t$ and $h_s = 2^s$ for $t > s \ge 0$, there is a unique permutation of ${1, 2, \ldots, N}$ that maximizes the number of move operations performed by Algorithm D. Find a simple way to describe this permutation. Verified: no Solve time: 9m01s Solution We consider Shellsort (Algorithm D) with $N = 2^t$...
TAOCP 5.2.1 Exercise 18
Section 5.2.1: Sorting by Insertion Exercise 18. [ HM2 ] For large $N$ the sum (6) can be estimated as $$\frac{1}{4} \frac{N^2}{h_{t-1}} - \frac{\sqrt{\pi}}{8} \left( \frac{N^{3/2} h_{t-1}^{1/2}}{h_{t-2}} + \cdots + \frac{N^{3/2} h_1^{1/2}}{h_0} \right).$$ What real values of $h_{t-1}, \ldots, h_0$ minimize this expression when $N$ and $t$ are fixed and $h_0 = 1$? Verified: no Solve time: 7m44s We minimize the asymptotic estimate for the sum (6): [ E =...
TAOCP 5.1.4 Exercise 43
Section 5.1.4: Tableaux and Involutions Exercise 43. [ 35 ] Continuing the previous exercise, show that at most $n + 1$ flips are needed to sort any rearrangement of $g_1 g_2 \ldots g_n$. Construct examples that require $n + 1$ flips, for all $n > 3$. Verified: no Solve time: 41m33s We are given Exercise 43 from Volume 3, Section 5.1.4 (Tableaux and Involutions). The exercise continues from Exercise 42...
TAOCP 5.1.4 Exercise 44
Section 5.1.4: Tableaux and Involutions Exercise 44. [ M37 ] Show that the average number of flips required to sort a random arrangement of $n$ genes is greater than $n - H_n$, if all $2^n , n!$ genome rearrangements are equally likely. Verified: no Solve time: 27m06s We need to solve Exercise 44 from TAOCP Volume 3, Section 5.1.4. The exercise: 44. [M37] Show that the average number of flips...
TAOCP 5.1.4 Exercise 39
Section 5.1.4: Tableaux and Involutions Exercise 39. [ M38 ] (I. M. Pak and A. V. Stoyanovskii, 1992.) Let $P$ be an array of shape $(n_1, \ldots, n_m)$ that has been filled with any permutation of the integers ${1, \ldots, n}$, where $n = n_1 + \cdots + n_m$. The following procedure, which is analogous to the "siftup" algorithm in Section 5.2.3, can be used to convert $P$ to a...
TAOCP 5.1.4 Exercise 27
Section 5.1.4: Tableaux and Involutions Exercise 27. [ M24 ] Let $Q$ be a Young tableau on ${1, 2, \ldots, n}$; let the element $i$ be in row $r_i$ and column $c_i$. We say that $i$ is "above" $j$ when $r_i < r_j$. a) Prove that, for $1 \le i < n$, $i$ is above $i + 1$ if and only if $c_i \ge c_{i+1}$. b) Given that $Q$ is...
TAOCP 5.1.4 Exercise 24
Section 5.1.4: Tableaux and Involutions Exercise 24. [ M28 ] Prove that $$\sum_{\substack{q_1 + \cdots + q_m = n \ 0 \le q_1, \ldots, q_m \le n}} \binom{m}{q_1} \cdots \binom{m}{q_m} \Delta(q_1, \ldots, q_m)^2$$ $$= n! \binom{m - (n^2 - n)}{t - \frac{1}{2}(n^2 - n)} \binom{m}{n-1} \binom{m}{n-2} \cdots \binom{m}{0} \Delta(n-1, \ldots, 0)^2.$$ [ Hints: Prove that $\Delta(k_1 + n - 1, \ldots, k_s) = \Delta(m - k_s + n - 1,...
TAOCP 5.1.4 Exercise 28
Section 5.1.4: Tableaux and Involutions Exercise 28. [ M43 ] Prove that the average length of the longest increasing subsequence of a random permutation of ${1, 2, \ldots, n}$ is asymptotically $2\sqrt{n}$. (This is the average length of row 1 in the correspondence of Theorem A.) Verified: no Solve time: 9m32s Setup Let (S_n) be the symmetric group on ({1,2,\ldots,n}). For a permutation (\pi\in S_n), let (L(\pi)) denote the length...
TAOCP 5.1.4 Exercise 14
Section 5.1.4: Tableaux and Involutions Exercise 14. [ M43 ] Find a more direct proof of Theorem D, part (c). Verified: no Solve time: 20m52s Setup We state Theorem D(c) in the notation of Section 5.1.4. Theorem D(c). Let (\pi) be a permutation of ({1,2,\ldots,n}) and let ((P,Q)) be the corresponding tableaux under the Robinson-Schensted correspondence of Theorem A. If the shape of (P) is ((n_1,n_2,\ldots,n_m)), then for every (k)...
TAOCP 5.1.4 Exercise 23
Section 5.1.4: Tableaux and Involutions Exercise 23. ▶ [ HM30 ] (D. André.) In how many ways, $E_m$, can the numbers ${1, 2, \ldots, n}$ be placed into the array of $n$ cells $$\begin{array}{cccc} & & \cdots \ \square & \square & \cdots \end{array}$$ in such a way that the rows and columns are in increasing order? Find the generating function $g(z) = \sum E_m z^m / m!$. Verified: no...
TAOCP 5.1.4 Exercise 13
Section 5.1.4: Tableaux and Involutions Exercise 13. [ M28 ] Prove Theorem C. Verified: no Solve time: 12m07s Setup We work within the framework of Section 5.1.4 of The Art of Computer Programming , Volume 3. The Robinson-Schensted correspondence (Theorem A) constructs from any two‑line array [ \begin{pmatrix} q_1 & q_2 & \cdots & q_n \ p_1 & p_2 & \cdots & p_n \end{pmatrix},\qquad q_1 < q_2 < \cdots <...
TAOCP 5.1.2 Exercise 22
Section 5.1.2: Permutations of a Multiset Exercise 22. [ M30 ] Let $P(x_1^{n_1} \ldots x_m^{n_m})$ denote the set of all possible permutations of the multiset ${n_1 \cdot x_1, \ldots, n_m \cdot x_m}$, and let $P_0(x_0^{n_0} x_1^{n_1} \ldots x_m^{n_m})$ be the subset of $P(x_0^{n_0} x_1^{n_1} \ldots x_m^{n_m})$ in which the first $n_0$ elements are $\ne x_0$. a) Given a number $t$ with $1 \le l < m$, find a one-to-one correspondence...
TAOCP 5.1.2 Exercise 15
Section 5.1.2: Permutations of a Multiset Exercise 15. ▶ [ M25 ] Prove that the permutation $a_1 \ldots a_n$ of the multiset $${n_1 \cdot x_1,, n_2 \cdot x_2, \ldots, n_m \cdot x_m},$$ where $x_1 < x_2 < \cdots < x_n$ and $n_1 + n_2 + \cdots + n_m = n$, is a cycle if and only if the directed graph with vertices ${x_1, x_2, \ldots, x_m}$ and arcs from $x_i$...
TAOCP 5.1.2 Exercise 18
Section 5.1.2: Permutations of a Multiset Exercise 18. [ M30 ] (P. A. MacMahon.) The index of a permutation $a_1, a_2 \ldots a_n$ was defined in the previous section; and we proved that the number of permutations of a given set that have a given index $k$ is the same as the number of permutations that have $k$ inversions. Does the same result hold for permutations of a given multiset?...
TAOCP 1.2.11.3 Exercise 11
Section 1.2.11.3: Some Asymptotic Calculations Exercise 11. ▶ [ HM35 ] Let us generalize the functions $Q(n)$ and $R(n)$ by introducing a parameter $x$: $$ Q_x(n)=1+\frac{n-1}{n}x+\frac{n-1}{n}\frac{n-2}{n}x^2+\cdots, $$ $$ R_x(n)=1+\frac{n}{n+1}x+\frac{n}{n+1}\frac{n}{n+2}x^2+\cdots. $$ Explore this situation and find asymptotic formulas when $x\ne 1$. Verified: no Solve time: 19m20s Setup The generalized sums are defined for integer (n\ge 1) and real (x) by [ Q_x(n) = \sum_{k=0}^{n-1} \frac{(n-1) k}{n^k},x^k, \qquad R_x(n) = \sum {k=0}^{\infty}...
TAOCP 5.1.2 Exercise 14
Section 5.1.2: Permutations of a Multiset Exercise 14. [ M30 ] One way to define the inverse $\pi^-$ of a general permutation $\pi$, suggested by other definitions in this section, is to interchange the lines of the two-line representation of $\pi$ and then to do a stable sort of the columns in order to bring the top row into nondecreasing order. For example, if $a < b < c <...
TAOCP 5 Exercise 17
Section 5: Introduction to Sorting Exercise 17. ▶ [ 33 ] (Library card sorting.) Before the days of computerized databases, every library maintained a catalog of cards so that users could find the books they wanted. But the task of putting catalog cards into an order convenient for human use turned out to be quite complicated as library collections grew. The following "alphabetical" listing indicates many of the procedures recommended...
TAOCP 5 Exercise 16
Section 5: Introduction to Sorting Exercise 16. [ 20 ] In order to make it easier to make changes to large FORTRAN programs, you want to design a "cross-reference" routine; such a routine takes FORTRAN programs as input and prints them together with an index that shows each use of each identifier (that is, each name) in the program. How should such a routine be designed? Verified: yes Solve time:...
TAOCP 5.1.4 Exercise 40
Section 5.1.4: Tableaux and Involutions Exercise 40. [ HM43 ] Suppose a random Young tableau has been constructed by successively placing the numbers $1, 2, \ldots, n$ in such a way that each possibility is equally likely when a new number is placed. For example, the tableau (1) would be obtained with probability $\frac{1}{2} \cdot \frac{1}{4} \cdot \frac{1}{4} \cdot \frac{1}{4} \cdots$ using this procedure. The resulting shape $(n_1, n_2, \ldots,...
TAOCP 5.1.4 Exercise 41
Section 5.1.4: Tableaux and Involutions Exercise 41. [ 25 ] (Disorder in a library.) Casual users of a library often put books back on the shelves in the wrong place. One way to measure the amount of disorder present in a library is to consider the minimum number of times we would have to take a book out of one place and insert it in another, before all books are...
TAOCP 5.1.4 Exercise 38
Section 5.1.4: Tableaux and Involutions Exercise 38. ▶ [ M30 ] (Greene, Nijenhuis, and Wilf, 1979.) We can construct a directed acyclic graph on the cells $T$ of any given tableau shape by letting arcs run from each cell to the other cells in its hook; the out-degree of cell $(i, j)$ will then be $d_{ij} = h_{ij} - 1$, where $h_{ij}$ is the hook length. Suppose we generate a...
TAOCP 5.1.4 Exercise 37
Section 5.1.4: Tableaux and Involutions Exercise 37. [ M20 ] (P. A. MacMahon, 1912.) What is the generating function for all plane partitions? (The coefficient of $z^m$ should be the total number of plane partitions of $m$ when the tableau shape is unbounded.) Verified: yes Solve time: 43m02s Solution A plane partition is an infinite array of nonnegative integers (p_{ij}) ((i,j\ge 1)) satisfying [ p_{ij} \ge p_{i+1,j},\qquad p_{ij} \ge p_{i,j+1}...
TAOCP 5.1.4 Exercise 36
Section 5.1.4: Tableaux and Involutions Exercise 36. [ HM27 ] (R. P. Stanley, 1971.) (a) Prove that the number of reverse plane partitions of $m$ in a given shape is $\lfloor s^m \rfloor / \prod (1 - z^{h_{ij}})$, where the numbers $h_{ij}$ are the hook lengths of the shape. (b) Derive Theorem H from this result. [ Hint: What is the asymptotic number of partitions as $m \to \infty$?] Verified:...
TAOCP 5.1.4 Exercise 35
Section 5.1.4: Tableaux and Involutions Exercise 35. ▶ [ 30 ] (A. P. Hillman and R. M. Grassl, 1976.) An arrangement of nonnegative integers $p_{ij}$ in a tableau shape is called a plane partition of $m$ if $\sum p_{ij} = m$ and $$p_{i1} \ge \cdots \ge p_{im_i}, \qquad p_{1j} \ge \cdots \ge p_{n'_j j}, \qquad \text{for } 1 \le i \le n_1',\ 1 \le j \le n_1,$$ when there are...
TAOCP 5.1.4 Exercise 34
Section 5.1.4: Tableaux and Involutions Exercise 34. [ 25 ] (T. Nakayama, 1940.) Prove that if a tableau shape contains a hook of length $4b$, it contains a hook of length $b$. Verified: no Solve time: 4h28m A tableau shape (or Young diagram) is a finite set of cells $\lambda \subset \mathbb{N}^2$ such that $(i,j) \in \lambda$ implies $(i',j') \in \lambda$ for all $1 \le i' \le i$, $1 \le...
TAOCP 5.1.4 Exercise 31
Section 5.1.4: Tableaux and Involutions Exercise 31. [ HM30 ] Let $x_n$ be the number of ways to place $n$ mutually nonattacking rooks on an $n \times n$ chessboard, where each arrangement is unchanged by reflection about both diagonals. Thus, $x_4 = 6$. (Involutions are required to be symmetrical about only one diagonal. Exercise 5.1.3–19 considers a related problem.) Find the asymptotic behavior of $x_n$. Verified: yes Solve time: 4h31m...
TAOCP 5.1.4 Exercise 33
Section 5.1.4: Tableaux and Involutions Exercise 33. [ M25 ] (O. H. Mitchell, 1881.) True or false: $\Delta(a_1, a_2, \ldots, a_m)/\Delta(1, 2, \ldots, m)$ is an integer when $a_1, a_2, \ldots, a_m$ are integers. Verified: yes Solve time: 19m22s Solution The statement is true . For any integers (a_1, a_2, \dots, a_m), the ratio [ \frac{\Delta(a_1, a_2, \dots, a_m)}{\Delta(1, 2, \dots, m)} ] is an integer. Proof. Recall the Vandermonde...
TAOCP 5.1.4 Exercise 32
Section 5.1.4: Tableaux and Involutions Exercise 32. [ HM21 ] Prove that the involution number $t_n$ is the expected value of $X^n$, when $X$ is a normal deviate with mean 1 and variance 1. Verified: yes Solve time: 13m11s Solution Let (X) be a normal random variable with mean (1) and variance (1). Its moment generating function is [ M(t) = \mathbb{E}[e^{tX}] = \exp!\left(t + \frac{t^2}{2}\right). ] Expanding as a...
TAOCP 5.1.4 Exercise 30
Section 5.1.4: Tableaux and Involutions Exercise 30. [ M41 ] (M. P. Schützenberger.) Show that the operation of going from $P$ to $P^5$ is a special case of an operation applicable in connection with any finite partially ordered set, not merely a tableau: Label the elements of a partially ordered set with the integers ${1, 2, \ldots, n}$ in such a way that the partial order is consistent with the...
TAOCP 5.1.4 Exercise 29
Section 5.1.4: Tableaux and Involutions Exercise 29. [ HM25 ] Prove that a random permutation of $n$ elements has an increasing subsequence of length $\ge t$ with probability $\le \binom{n}{t}/t!$. This probability is $O(1/\sqrt{n})$ when $l = c\sqrt{n} + O(1)$, and $O(\exp(-c\sqrt{n}))$ when $l = 3\sqrt{n}$, $c = 6\ln 3 - 6$. Verified: yes Solve time: 1h15m Solution 1. Upper bound for the probability Let (\pi) be a uniformly random...
TAOCP 5.1.4 Exercise 26
Section 5.1.4: Tableaux and Involutions Exercise 26. [ M21 ] Evaluate $\int_{-\infty}^{\infty} x^t \exp(-2x^2) \sqrt{n} , dx$ when $t$ is a nonnegative integer. Verified: yes Solve time: 14m10s Solution We evaluate the integral [ I_t = \int_{-\infty}^{\infty} x^t \exp(-2x^2) \sqrt{n} , dx, ] where (t) is a nonnegative integer and (n > 0) is a constant. The factor (\sqrt{n}) is independent of (x), so [ I_t = \sqrt{n} \int_{-\infty}^{\infty} x^t...
TAOCP 5.1.4 Exercise 25
Section 5.1.4: Tableaux and Involutions Exercise 25. [ M30 ] Why is (42) the generating function for involutions? Verified: yes Solve time: 52m41s Setup By Theorem A in this section, there is a bijection between permutations of ({1,2,\ldots,n}) and ordered pairs ((P,Q)) of standard Young tableaux of the same shape. Under this correspondence, the inverse of a permutation corresponds to swapping (P) and (Q). Hence a permutation is an involution...
TAOCP 5.1.4 Exercise 21
Section 5.1.4: Tableaux and Involutions Exercise 21. [ HM91 ] (R. M. Thrall.) Let $n_1 > n_2 > \cdots > n_m$ specify the shape of a "shifted tableau" where row $i+1$ starts one position to the right of row $i$; for example, a shifted tableau of shape $(7, 5, 4, 1)$ has the form of the diagram $$ \begin{array}{|c|c|c|c|c|c|c|} \hline \cdot & 9 & 6 & 5 & 3 &...
TAOCP 5.1.4 Exercise 22
Section 5.1.4: Tableaux and Involutions Exercise 22. [ M39 ] In how many ways can an array of shape $(n_1, n_2, \ldots, n_m)$ be filled with elements from the set ${1, 2, \ldots, N}$ with repetitions allowed , so that the rows are nondecreasing and the columns are strictly increasing? For example, the simple $m$-rowed shape $(1, 1, \ldots, 1)$ can be filled in $\binom{n}{m}$ ways; the 1-rowed shape $(n)$...
TAOCP 5.1.4 Exercise 19
Section 5.1.4: Tableaux and Involutions Exercise 19. [ M40 ] Find a formula for the number of ways to fill an array that is like a tableau but with two boxes removed at the left of row 1; for example, $$ \begin{array}{l} n_1 - 2 \text{ boxes} \ n_2 \text{ boxes} \ n_3 \text{ boxes} \ \vdots \end{array} $$ is such a shape. (The rows and columns are to be...
TAOCP 5.1.4 Exercise 20
Section 5.1.4: Tableaux and Involutions Exercise 20. ▶ [ M25 ] Prove that the number of ways to label the nodes of a given tree with the elements ${1, 2, \ldots, n}$, such that the label of each node is less than that of its descendants, is $n!$ divided by the product of the subtree sizes (the number of nodes in each subtree). For example, the number of ways to...
TAOCP 5.1.4 Exercise 17
Section 5.1.4: Tableaux and Involutions Exercise 17. [ HM25 ] Let $$g(x_1, x_2, \ldots, x_n;, y) = x_1, \Delta(y, x_2, \ldots, x_n) + x_2, \Delta(x_1, x_2, \ldots, x_n)$$ $$+ \cdots + x_n, \Delta(x_1, x_2, \ldots, x_{n-1}, y).$$ Prove that $$g(x_1, x_2, \ldots, x_n;, y) = (x_1 + x_2 + \cdots + x_n + \tbinom{n}{2}, y), \Delta(x_1, x_2, \ldots, x_n).$$ [ Hint: The function is homogeneous (all terms have the same...
TAOCP 5.1.4 Exercise 18
Section 5.1.4: Tableaux and Involutions Exercise 18. [ HM30 ] Generalizing exercise 17, evaluate the sum $$x_1^m, \Delta(y, x_2, \ldots, x_n) + x_2^m, \Delta(x_1, x_2, \ldots, x_n) + \cdots + x_n^m, \Delta(x_1, x_2, \ldots, x_{n-1}, y),$$ when $m \ge 0$. Verified: yes Solve time: 1h24m Setup Let $\Delta(x_1,\dots,x_n)$ denote the Vandermonde determinant $$\Delta(x_1,\dots,x_n) = \prod_{1\le i<j\le n} (x_j - x_i).$$ We are to evaluate, for $m\ge 0$, the sum $$S_m...
TAOCP 5.1.4 Exercise 16
Section 5.1.4: Tableaux and Involutions Exercise 16. [ M08 ] In how many ways can the partial ordering represented by (39) be sorted topologically? Verified: yes Solve time: 36m57s The partial ordering (39) is defined on the pairs ((q_i, p_i)) of the two-line array [ \begin{pmatrix} q_1 & q_2 & \cdots & q_n \ p_1 & p_2 & \cdots & p_n \end{pmatrix} \begin{pmatrix} 1 & 3 & 5 & 6...
TAOCP 5.1.4 Exercise 15
Section 5.1.4: Tableaux and Involutions Exercise 15. [ M29 ] How many permutations of the multiset ${1 \cdot a, m \cdot b, n \cdot c}$ have the property that, as we read the permutation from left to right, the number of $c$'s never exceeds the number of $b$'s, and the number of $b$'s never exceeds the number of $a$'s? (For example, $a, a, b, c, b, b, c, a, c,...
TAOCP 5.1.2 Exercise 24
Section 5.1.2: Permutations of a Multiset Exercise 24. [ 27 ] Consider any relation $R$ that might hold between two unordered pairs of letters: if ${w, x} R {y, z}$ we say ${w, x}$ preserves ${y, z}$, otherwise ${w, x}$ moves ${y, z}$. The operation of transposing $\begin{smallmatrix}w\ x\end{smallmatrix}$ with respect to $R$ replaces $\begin{smallmatrix}w\ x\end{smallmatrix}$ by $\begin{smallmatrix}y\ x\end{smallmatrix}$ or $\begin{smallmatrix}w\ y\end{smallmatrix}$, and is applicable as the pair ${w, x}$...
TAOCP 5.1.2 Exercise 23
Section 5.1.2: Permutations of a Multiset Exercise 23. [ M23 ] A strand of DNA may be thought of as a word on a four-letter alphabet. Suppose we copy a strand of DNA and break it completely into one-letter bases, then recombine those bases at random. If the resulting strand is placed next to the original, prove that the number of places in which they differ is more likely to...
TAOCP 5.1.2 Exercise 21
Section 5.1.2: Permutations of a Multiset Exercise 21. [ M21 ] Given $n_1, \ldots, n_m$, and $d \ge 0$, how many permutations $a_1 a_2 \ldots a_n$ of the multiset ${n_1 \cdot 1, \ldots, n_m \cdot m}$ satisfy $a_{j+1} \ge a_j - d$ for $1 \le j < n = n_1 + \cdots + n_m$? Verified: yes Solve time: 2h25m Solution Let $f(n_1,\dots,n_m)$ be the number of permutations $a_1a_2\ldots a_n$ of...
TAOCP 5.1.2 Exercise 20
Section 5.1.2: Permutations of a Multiset Exercise 20. ▶ [ HM33 ] (D. Foata.) Let $(a_{ij})$ be any matrix of real numbers. In the notation of exercise 19(b), define $\nu(\pi) = a_{i_1 j_1} \ldots a_{i_n j_n}$, where the two-line notation for $\pi$ is $$\begin{pmatrix} x_{j_1} & x_{j_2} & \cdots & x_{j_n} \ x_{i_1} & x_{i_2} & \cdots & x_{i_n} \end{pmatrix}.$$ This function is useful in the computation of generating functions...
TAOCP 5.1.2 Exercise 19
Section 5.1.2: Permutations of a Multiset Exercise 19. [ HM28 ] Define the Möbius function $\mu(\pi)$ of a permutation $\pi$ to be 0 if $\pi$ contains repeated elements, otherwise $(-1)^k$ if $\pi$ is the product of $k$ primes. (Compare with the definition of the ordinary Möbius function, exercise 4.5.2–10.) a) Prove that if $\pi \ne \epsilon$, we have $$\sum \mu(\lambda) = 0,$$ summed over all permutations $\lambda$ that are left...
TAOCP 5.1.2 Exercise 17
Section 5.1.2: Permutations of a Multiset Exercise 17. [ M24 ] Find the average and standard deviation of the number of inversions in a random permutation of a given multiset, using the generating function found in exercise 16. Verified: yes Solve time: 38m35s Solution The generating function for the number of inversions in a random permutation of the multiset ({n_1\cdot x_1, n_2\cdot x_2, \ldots, n_m\cdot x_m}) (with (x_1 < x_2...
TAOCP 5.1.2 Exercise 16
Section 5.1.2: Permutations of a Multiset Exercise 16. [ M35 ] We found the generating function for inversions of permutations in the previous section, Eq. 5.1.1–(8), in the special case that a set was being permuted. Show that, in general, if a multiset is permuted, the generating function for inversions of ${n_1 \cdot x_1, n_2 \cdot x_2, \ldots}$ is the "$z$-multinomial coefficient" $$\binom{n}{n_1, n_2, n_3, \ldots} z = \frac{m_n}{n_1!, n_2!,...
TAOCP 5.1.2 Exercise 13
Section 5.1.2: Permutations of a Multiset Exercise 13. [ M21 ] Prove that the number of permutations of the multiset $${A \cdot a,, B \cdot b,, C \cdot c,, D \cdot d,, E \cdot e,, F \cdot f}$$ containing no adjacent pairs of letters on and $db$ is $$\sum_t \binom{D}{A-t} \binom{A+B+E+F}{t} \binom{A+B+C+E+F-t}{t} \binom{C+D+E+F}{C,D,E,F}.$$ Verified: no Solve time: 2h58m Exercise 13 (M21). Prove that the number of permutations of the multiset...
TAOCP 5.1.2 Exercise 12
Section 5.1.2: Permutations of a Multiset Exercise 12. [ M16 ] Show that [29] is a consequence of the assumptions of (28). Verified: yes Solve time: 59m39s Solution We are given a permutation of the multiset ${A\cdot a,;B\cdot b,;C\cdot c,;D\cdot d}$ with $A+C = B+D$. Its two‑line array contains no columns of the form $x_x$ and the frequencies of the eight column types are given in (28): $$ \begin{array}{c|cccccccc} \text{Frequency}...
TAOCP 5 Exercise 24
Section 5: Introduction to Sorting Exercise 24. ▶ [ 30 ] Three million men with distinct names were laid end-to-end, reaching from New York to California. Each participant was given a slip of paper on which he wrote down his own name and the name of the person immediately west of him in the line. The man at the extreme western end didn't understand what to do, so he threw...
TAOCP 5 Exercise 25
Section 5: Introduction to Sorting Exercise 25. [ M21 ] ( Discrete logarithms. ) You know that $p$ is a (rather large) prime number, and that $a$ is a primitive root modulo $p$. Therefore, for all $b$ in the range $1 \le b < p$, there is a unique $n$ such that $a^n \bmod p = b$, $1 \le n < p$. (This $n$ is called the index of $b$...
TAOCP 5 Exercise 23
Section 5: Introduction to Sorting Exercise 23. [ 30 ] In a certain group of 4096 people, everyone has about 100 acquaintances. (A file has been prepared listing all pairs of people who are acquaintances. (The relation is symmetric: If $x$ is acquainted with $y$, then $y$ is acquainted with $x$. Therefore the file contains roughly 200,000 entries.) How would you design an algorithm to list all the $k$-person cliques...
TAOCP 5 Exercise 20
Section 5: Introduction to Sorting Exercise 20. ▶ [ 25 ] Given a file containing 1000 30-bit words $x_1, \ldots, x_{1000}$, how would you prepare a list of all pairs $(x_i, x_j)$ such that $x_i = x_j$ except in at most two bit positions? Verified: yes Solve time: 25m58s Solution We are given (N = 1000) words (x_1, x_2, \dots, x_{1000}), each of length 30 bits. The task is to...
TAOCP 5 Exercise 22
Section 5: Introduction to Sorting Exercise 22. [ M28 ] Given the specifications of a fairly large number of directed graphs, what approach will be useful for grouping the isomorphic ones together? (Directed graphs are isomorphic if there is a one-to-one correspondence between their vertices and a one-to-one correspondence between their arcs, where the correspondences preserve incidence between vertices and arcs.) Verified: yes Solve time: 12m07s Setup We are given...
TAOCP 5 Exercise 21
Section 5: Introduction to Sorting Exercise 21. [ 22 ] How would you go about looking for five-letter anagrams such as CARET, CARTE, CATER, CRATE, REACT, RECTA, TRACE; CRUEL, LUCRE, ULCER; DOWRY, ROWDY, WORDY? (One might wish to know whether there are any sets of ten or more five-letter English anagrams besides the remarkable set APERS, ASPER, PARES, PARSE, PEARS, PRASE, PRESA; RAPES, REAPS, SPAER, SPARE, SPEAR, to which we...
TAOCP 5 Exercise 19
Section 5: Introduction to Sorting Exercise 19. ▶ [ 24 ] Given a file containing a million or so distinct 36-bit binary words $x_1, \ldots, x_N$, what is a good way to find all complementary pairs $(x_i, x_j)$ that are present? (Two words are complementary when one has 0 wherever the other has 1, and conversely; thus they are complementary if and only if their sum is $(11 \ldots 1)_2$,...
TAOCP 5 Exercise 18
Section 5: Introduction to Sorting Exercise 18. [ M25 ] (E. T. Parker.) Leonhard Euler once conjectured [ Nova Acta Acad. Sci. Petropolitanae 13 (1795), 45–63, §3; written in 1778] that there are no solutions to the equation $$u^5 + v^5 + w^5 + x^5 + y^5 = z^5$$ in positive integers $u$, $v$, $w$, $x$, $y$, $z$. At the same time he conjectured that $$x_1^n + \cdots + x_{n-1}^n...
TAOCP 5 Exercise 15
Section 5: Introduction to Sorting Exercise 15. [ 18 ] You are given a list of the names of a fairly large number of people born in the U.S.A., together with the name of the state where they were born. How do you count the number of people born in each state? (Assume that nobody appears in the list more than once.) Verified: yes Solve time: 7m26s Solution We are...
TAOCP 5 Exercise 13
Section 5: Introduction to Sorting Exercise 13. [ M26 ] How could you "shuffle" a large file of $N$ words into a random rearrangement? Verified: yes Solve time: 8m32s Setup We are given a file of (N) words (records) (R_1, R_2, \ldots, R_N) stored on external storage (e.g., magnetic tape). Each record contains a key field and satellite data; the goal is to rearrange the records into a uniformly random...
TAOCP 5 Exercise 14
Section 5: Introduction to Sorting Exercise 14. [ 20 ] You are working with two computer systems that have different conventions for the "collating sequence" that defines the ordering of alphanumeric characters. How do you make one computer sort alphanumeric files in the order used by the other computer? Verified: yes Solve time: 6m35s Solution Let the two computers be (A) and (B). Let (\Sigma) be the set of alphanumeric...
TAOCP 5 Exercise 12
Section 5: Introduction to Sorting Exercise 12. [ M25 ] (Transposing a matrix.) You are given a magnetic tape containing one million words, representing the elements of a $1000 \times 1000$ matrix stored in order by rows: $a_{1,1}, a_{1,2}, \ldots, a_{1,1000}, a_{2,1}, \ldots, a_{2,1000}, \ldots, a_{1000,1000}$. How do you create a tape in which the elements are stored by columns $a_{1,1} a_{2,1} \ldots a_{100,1} a_{1,2} \ldots a_{100,2} \ldots a_{100,100}$ instead?...
TAOCP 5 Exercise 8
Section 5: Introduction to Sorting Exercise 8. ▶ [ 30 ] Locations A and B contain two numbers $a$ and $b$, respectively. Show that it is possible to write a MIX program that computes and stores $\min(a, b)$ in location C, without using any jump operators . (Caution: Since you will not be able to test whether or not arithmetic overflow has occurred, it is wise to guarantee that overflow...
TAOCP 5 Exercise 11
Section 5: Introduction to Sorting Exercise 11. [ 18 ] You are the U. S. Internal Revenue Service; you receive millions of "information" forms from organizations telling how much income they have paid to people, and millions of "tax" forms from people telling how much income they have been paid. How do you catch people who don't report all of their income? Verified: yes Solve time: 14m32s Solution We are...
TAOCP 5 Exercise 10
Section 5: Introduction to Sorting Exercise 10. [ 15 ] You are given a tape containing one million words of data. How do you determine how many distinct words are present on the tape? Verified: yes Solve time: 10m07s Solution We are given a tape containing (N = 10^6) words and have at most a few thousand words of internal memory (say (M) words, where (M \ll N)) and about...
TAOCP 5 Exercise 9
Section 5: Introduction to Sorting Exercise 9. [ M27 ] After $N$ independent, uniformly distributed random variables between 0 and 1 have been sorted into nondecreasing order, what is the probability that the $r$th smallest of these numbers is $\le x$? Each of the following exercises states a problem that a computer programmer might have had to solve in the old days when computers didn't have much random-access memory. Suggest...
TAOCP 5 Exercise 7
Section 5: Introduction to Sorting Exercise 7. [ 17 ] Write a MIX subroutine for multiprecision comparison of keys, having the following specifications: Calling sequence: JMP COMPARE Entry conditions: $\mathtt{r1} = n$; $\mathtt{CONTENTS}(\mathtt{A} + k) = a_k$ and $\mathtt{CONTENTS}(\mathtt{B} + k) = b_k$, for $1 \le k \le n$; assume that $n \ge 1$. Exit conditions: $\mathtt{CI} = \mathtt{GREATER}$, if $(a_n, \ldots, a_1) > (b_n, \ldots, b_1)$; $\mathtt{CI} = \mathtt{EQUAL}$,...
TAOCP 4.5.4 Exercise 13
Section 4.5.4: Factoring into Primes Exercise 13. [ HM25 ] (J. D. Dixon.) Prove that whenever the algorithm of exercise 12 is pre- sented with a solution $(x,e_0,\ldots,e_m)$ whose exponents are linearly dependent modulo 2 on the exponents of previous solutions, the probability is $2^{1-d}$ that a factorization will not be found, when $N$ has $d$ distinct prime factors and $x$ is chosen at random. Verified: no Solve time: 53m27s...
TAOCP 5 Exercise 6
Section 5: Introduction to Sorting Exercise 6. [ 15 ] Mr. B. C. Dull (a MIX programmer) wanted to know if the number stored in location A is greater than, less than, or equal to the number stored in location B. So he wrote LDA A; SUB B and tested whether register A was positive, negative, or zero. What serious mistake did he make, and what should he have done...
TAOCP 4.3.2 Exercise 13
Section 4.3.2: Modular Arithmetic Exercise 13. ▶ [ M25 ] (Automorphic numbers.) An $n$-digit decimal number $x > 1$ is called an “automorph” by recreational mathematicians if the last $n$ digits of $x^2$ are equal to $x$. For example, 9376 is a 4-digit automorph, since $9376^2 = 87909376$. [See Scientific American 218, 1 (January 1968), 125.] a) Prove that an $n$-digit number $x > 1$ is an automorph if and...
TAOCP 3.2.2 Exercise 9
Section 3.2.2: Other Methods Exercise 9. [ M24 ] (R. R. Coveyou.) Use the result of exercise 8 to prove that the modified middle-square method (4) has a period of length $2^{e-2}$. Verified: yes Solve time: 31m29s Solution The modified middle-square method (4) is defined by the recurrence [ X_{n+1} = (X_n^2 + X_n) \bmod 2^e, ] where (X_n) is an integer with (0 \le X_n < 2^e). (This is...
TAOCP 1.2.11.3 Exercise 14
Section 1.2.11.3: Some Asymptotic Calculations Exercise 14. ▶ [ HM39 ] (N. G. de Bruijn.) The purpose of this exercise is to find the asymptotic expansion of $\sum_{k=0}^n k^{n+\alpha}e^{-k}$ for fixed $\alpha$, as $n\to\infty$. a) Replacing $k$ by $n-k$, show that the given sum equals $n^{n+\alpha}e^{-n}\sum_{k=0}^n e^{-k^2/2n}f(k,n)$, where $$ f(k,n)=\left(1-\frac{k}{n}\right)^\alpha \exp!\left(-\frac{k^3}{3n^2}-\frac{k^4}{4n^3}-\cdots\right). $$ b) Show that for all $m\ge 0$ and $\epsilon>0$, the quantity $f(k,n)$ can be written in the form...
TAOCP 1.2.11.3 Exercise 13
Section 1.2.11.3: Some Asymptotic Calculations Exercise 13. [ HM42 ] (S. Ramanujan.) Prove that $R(n)-Q(n)=\dfrac{2}{3}+ \dfrac{8}{135(n+\theta(n))}$, where $\dfrac{2}{21}\le \theta(n)\le \dfrac{8}{45}$. (This implies the much weaker result $R(n+1)-Q(n+1)<R(n)-Q(n)$.) Verified: no Solve time: 1h53m Solution We work within the notation of Section 1.2.11.3. The three sums are [ Q(n)=\sum_{k=1}^{n}\frac{n!}{(n-k)!,n^{k}},\qquad R(n)=\sum_{k\ge 0}\frac{n!,n^{k}}{(n+k)!},\qquad Q(n)+R(n)=\frac{n!,e^{n}}{n^{n}}. \tag{4} ] The incomplete gamma function (\gamma(a,x)=\int_{0}^{x}e^{-t}t^{a-1}dt) satisfies (Eq. (9)) [ R(n)=\frac{n!,e^{n}}{n^{n}},\frac{\gamma(n,n)}{(n-1)!}, ] hence [ R(n)-Q(n)=\frac{n!,e^{n}}{n^{n}}\left(2\frac{\gamma(n,n)}{(n-1)!}-1\right). \tag{1} ] 1. An...
TAOCP 1.2.11.3 Exercise 12
Section 1.2.11.3: Some Asymptotic Calculations Exercise 12. [ HM20 ] The function $\int_0^x e^{-t^2/2},dt$ that appeared in connection with the normal distribution (see Section 1.2.10) can be expressed as a special case of the incomplete gamma function. Find values of $a$, $b$, and $y$ such that $b,\gamma(a,y)$ equals $\int_0^x e^{-t^2/2},dt$. Verified: yes Solve time: 5m01s Solution We want to express the integral [ \int_0^x e^{-t^2/2},dt ] in terms of the...
TAOCP 1.2.11.3 Exercise 9
Section 1.2.11.3: Some Asymptotic Calculations Exercise 9. ▶ [ HM36 ] What is the behavior of $\gamma(x+1,px)/\Gamma(x+1)$ for large $x$? (Here $p$ is a real constant; and if $p<0$, we assume that $x$ is an integer, so that $t^x$ is well defined for negative $t$.) Obtain at least two terms of the asymptotic expansion, before resorting to $O$-terms. Verified: yes Solve time: 57m10s Setup Let [ G_x(p)=\frac{\gamma(x+1,px)}{\Gamma(x+1)}. ] The answer...
TAOCP 1.2.11.3 Exercise 10
Section 1.2.11.3: Some Asymptotic Calculations Exercise 10. [ HM34 ] Under the assumptions of the preceding problem, with $p\ne 1$, obtain the asymptotic expansion of $\gamma(x+1,px+py/(p-1))-\gamma(x+1,px)$, for fixed $y$, to terms of the same order as obtained in the previous exercise. Verified: yes Solve time: 44m31s Setup We consider the difference [ \Delta = \gamma(x+1,, px + \tfrac{p y}{p-1}) - \gamma(x+1,, px), ] where (p \neq 1) is a real...
TAOCP 1.2.5 Exercise 24
Section 1.2.5: Permutations and Factorials Exercise 24. ▶ [ HM21 ] Prove the handy inequalities $$ \frac{n^n}{e^{,n-1}} \le n! \le \frac{n^{n+1}}{e^{,n-1}}, \qquad \text{integer } n \ge 1. $$ [Hint: $1+x \le e^x$ for all real $x$; hence $(k+1)/k \le e^{1/k} \le k/(k-1)$.] Verified: yes Solve time: 9m39s Solution From (1+x\le e^x), taking (x=1/k) gives, for (k\ge1), [ \frac{k+1}{k}\le e^{1/k}. ] Taking (x=-1/k), where (k\ge2), gives [ 1-\frac1k\le e^{-1/k}. ] Both...
TAOCP 1.2.5 Exercise 22
Section 1.2.5: Permutations and Factorials Exercise 22. ▶ [ HM20 ] Try to put yourself in Euler's place, looking for a way to generalize $n!$ to noninteger values of $n$. Since $(n+\tfrac12)!/n!$ times $((n+\tfrac12)+\tfrac12)!/(n+\tfrac12)!$ equals $(n+1)!/n! = n+1$, it seems natural that $(n+\tfrac12)!/n!$ should be approximately $\sqrt{n}$. Similarly, $(n+\tfrac13)!/n!$ should be approximately $n^{1/3}$. Invent a hypothesis about the ratio $(n+x)!/n!$ as $n$ approaches infinity. Is your hypothesis correct when $x$...
TAOCP 1.2.5 Exercise 14
Section 1.2.5: Permutations and Factorials Exercise 14. ▶ [ M28 ] (L. Stickelberger, 1890.) In the notation of exercise 12, we can determine $n! \bmod p$ in terms of the $p$-ary representation, for any positive integer $n$, thus generalizing Wilson's theorem. In fact, prove that $$ \frac{n!}{p^\mu} \equiv (-1)^\mu a_0!a_1!\cdots a_k! \pmod p. $$ Verified: yes Solve time: 13m59s Setup Let [ n=a_kp^k+a_{k-1}p^{k-1}+\cdots+a_1p+a_0, \qquad 0\le a_j<p,\quad a_k>0. ] For every...
TAOCP 1.2.5 Exercise 10
Section 1.2.5: Permutations and Factorials Exercise 10. ▶ [ HM20 ] Does the identity $\Gamma(x+1)=x\Gamma(x)$ hold for all real numbers $x$? (See exercise 7.) Verified: yes Solve time: 8m06s Solution Let [ D=\mathbb{R}\setminus{0,-1,-2,\ldots}, ] the set of real numbers for which both (\Gamma(x)) and (\Gamma(x+1)) are defined by Eq. (15). For (x\in D), Eq. (15) gives [ x\Gamma(x) =\lim_{m\to\infty} \frac{x,m^x m!}{x(x+1)\cdots(x+m)} =\lim_{m\to\infty} \frac{m^x m!}{(x+1)(x+2)\cdots(x+m)}. ] On the other hand, [...
TAOCP 1.2.5 Exercise 12
Section 1.2.5: Permutations and Factorials Exercise 12. ▶ [ M22 ] (A. Legendre, 1808.) Generalizing the result of the previous exercise, let $p$ be a prime number, and let the representation of $n$ in the $p$-ary number system be $$ n = a_k p^k + a_{k-1}p^{k-1} + \cdots + a_1p + a_0. $$ Express the number $\mu$ of Eq. (8) in a simple formula involving $n$, $p$, and the $a$'s....
TAOCP 1.2.5 Exercise 4
Section 1.2.5: Permutations and Factorials Exercise 4. ▶ [ 13 ] Given the fact that $\log_{10} 1000! = 2567.60464\ldots$, determine exactly how many decimal digits are present in the number $1000!$. What is the most significant digit? What is the least significant digit? Verified: yes Solve time: 7m12s Solution Let [ L=\log_{10}(1000!)=2567.60464\ldots. ] For every positive integer (N), the number of decimal digits of (N) is [ \lfloor \log_{10}N\rfloor+1, ]...
TAOCP 1.2.5 Exercise 6
Section 1.2.5: Permutations and Factorials Exercise 6. ▶ [ 17 ] Using Eq. (8), write $20!$ as a product of prime factors. Verified: yes Solve time: 4m25s Solution By Eq. (8), the exponent of a prime (p) in (20!) is [ \mu=\sum_{k>0}\left\lfloor\frac{20}{p^k}\right\rfloor. ] The relevant values are [ \begin{array}{c|c|c} p & \text{nonzero terms in }\mu & \mu \ \hline 2 & 10+5+2+1 & 18\ 3 & 6+2 & 8\ 5...
TAOCP 7.2.2.2 Exercise 99
Section 7.2.2.2: Satisfiability Exercise 99. [ 25 ] Th. Dekker devised the first correct mutual-exclusion protocol in 1965: 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 A3, else to A6. B2. If $a$ go to B3, else to B6. A3. If $f$ go to A3, else to...
TAOCP 7.2.2.2 Exercise 98
Section 7.2.2.2: Satisfiability Exercise 98. ▶ [ M23 ] This exercise is about proving the nonexistence of starvation cycles (47). a) A cycle of states is called "pure" if one of the players is never bumped, and "simple" if no state is repeated. Prove that every starvation cycle, if any, is either simple or consists of two simple pure cycles that share a common state. b) If Alice is starved...
TAOCP 7.2.2.2 Exercise 97
Section 7.2.2.2: Satisfiability Exercise 97. [ 20 ] Can states A6 and B6 occur simultaneously in Peterson's protocol (49)? Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to...
TAOCP 7.2.2.2 Exercise 96
Section 7.2.2.2: Satisfiability Exercise 96. [ 22 ] Find all solutions to (52) when $r = 2$. Also illustrate the fact that invariants are extremely helpful, by finding a solution with distinct states $X_0, X_1, \ldots, X_r$ and with $r$ substantially greater than 2, if the clauses involving $\Phi$ are removed. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating...
TAOCP 7.2.2.2 Exercise 95
Section 7.2.2.2: Satisfiability Exercise 95. [ 20 ] Using invariants like (50), prove that (45) and (46) provide mutual exclusion. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$...
TAOCP 7.2.2.2 Exercise 94
Section 7.2.2.2: Satisfiability Exercise 94. ▶ [ 21 ] Suppose we know that $(X_0 \to X_1 \to \cdots \to X_r) \land \neg\Phi(X_r)$ is unsatisfiable for $0 \le r \le k$. What clauses will guarantee that $\Phi$ is invariant? (The case $k = 1$ is (51).) Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff...
TAOCP 7.2.2.2 Exercise 93
Section 7.2.2.2: Satisfiability Exercise 93. [ 20 ] What clauses correspond to the term $\neg\Phi(X^r)$ in (51)? Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly...
TAOCP 7.2.2.2 Exercise 92
Section 7.2.2.2: Satisfiability Exercise 92. [ 20 ] Suggest $O(r^2)$ clauses with which we can determine whether or not a mutual exclusion protocol permits a path $X_0 \to X_1 \to \cdots \to X_r$ of distinct states. Verified: no Solve time: 3m41s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$...
TAOCP 7.2.2.2 Exercise 91
Section 7.2.2.2: Satisfiability Exercise 91. [ M21 ] Formally speaking, Alice is said to "starve" if there is (i) an infinite sequence of transitions $X_0 \to X_1 \to \cdots$ starting from the state $X_0$, and (ii) an infinite sequence $\theta_0, \theta_1, \ldots$ of Boolean "bumps" that changes infinitely often, such that (iii) Alice is in a "maybe" or "critical" state only a finite number of times. Prove that this can...
TAOCP 7.2.2.2 Exercise 90
Section 7.2.2.2: Satisfiability Exercise 90. [ 20 ] Show that (43), (45), and (46) permit starvation, by satisfying (47) and (48). Verified: no Solve time: 3m51s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 89
Section 7.2.2.2: Satisfiability Exercise 89. [ 21 ] Here's a mutual-exclusion protocol once recommended in 1966. Does it work? 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 $f$ go to A3, else to A5. B2. If $f$ go to B5, else to B3. A3. If $b$ go to B3, else...
TAOCP 7.2.2.2 Exercise 88
Section 7.2.2.2: Satisfiability Exercise 88. [ 15 ] Satisfy (41) and (42) for $0 \le t < 6$, and the $20 \times 6$ additional binary clauses that exclude multiple states, along with the "embarrassing" unit clauses $(A3_6) \land (B3_6)$. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and...
TAOCP 7.2.2.2 Exercise 87
Section 7.2.2.2: Satisfiability Exercise 87. [ 21 ] Explain why the clauses (42) represent Alice and Bob's programs (40), and give a general recipe for converting such programs into equivalent sets of clauses. Verified: no Solve time: 3m50s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 86
Section 7.2.2.2: Satisfiability Exercise 86. [ M29 ] How many Life predecessors does a random $10 \times 10$ bitmap have, on average? Verified: no Solve time: 3m49s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 85
Section 7.2.2.2: Satisfiability Exercise 85. ▶ [ 39 ] A Garden of Eden is a state of Life that has no predecessor. a) If an array of 92 cells illustrated here occurs anywhere within a bitmap $X$, verify that $X$ is a Garden of Eden. (The gray cells can be either dead or alive.) b) The orphan pattern found, with a SAT solver's help, is the smallest that is currently...
TAOCP 7.2.2.2 Exercise 84
Section 7.2.2.2: Satisfiability Exercise 84. [ 33 ] Prove that $f^*(i,j) = f(i,j)$ in the following cases when $j > 0$: (a) $i = j$, $i = j + 1$, (b) (i) $i = 0$ and $i = -1$. (c) $i = 1 - j$. (d) $i = -2$. Verified: no Solve time: 3m40s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 83
Section 7.2.2.2: Satisfiability Exercise 83. [ 21 ] According to the previous exercise, the earliest possible time that cell $(i, j)$ can become alive, if all initial life is confined to the lower left quadrant of the plane, is at least $$f(i, j) = i[i \ge 0] + j[j \ge 0] + |i \ge 0| + |i + j \ge 0| \cdot |i + j \ge 0|$$ For example, when...
TAOCP 7.2.2.2 Exercise 82
Section 7.2.2.2: Satisfiability Exercise 82. ▶ [ 22 ] (Light speed.) Imagine Life on an infinite plane, with all cells dead at time 0 except in the lower left quadrant. More precisely, suppose $X_t = (x_{tij})$ is defined for all $t \ge 0$ and all integers $-\infty < i, j < +\infty$, and that $x_{0ij} = 0$ whenever $i > 0$ or $j > 0$. a) Prove that $x_{tij} =...
TAOCP 7.2.2.2 Exercise 81
Section 7.2.2.2: Satisfiability Exercise 81. [ 21 ] Conway discovered a remarkable "spaceship," where $X_4$ is $X_0$ shifted up 2: $$X_0 = \raisebox{0pt}{\includegraphics[height=1em]{fig_spaceship_x0}} \to \cdots \to X_4 = \raisebox{0pt}{\includegraphics[height=1em]{fig_spaceship_x4}}$$ Is there a left-right symmetrical version? (Such spaceships would eat any such spaceships?) Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where...
TAOCP 7.2.2.2 Exercise 80
Section 7.2.2.2: Satisfiability Exercise 80. [ 21 ] To counteract the problem in the previous exercise, find an eater that is symmetrical when reflected about a diagonal, so that it eats both ▶ and ▼. (You'll have to go larger than $8 \times 8$, and you'll have to wait longer for digestion.) Verified: no Solve time: 3m41s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables...
TAOCP 7.2.2.2 Exercise 79
Section 7.2.2.2: Satisfiability Exercise 79. [ 29 ] What happens if the glider meets the eater of (39) in its opposite phase (namely, ▶ instead of ▼)? Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding...
TAOCP 7.2.2.2 Exercise 78
Section 7.2.2.2: Satisfiability Exercise 78. [ 21 ] Find a solution to the four-step eater problem in (38) that works on a $7 \times n$ grid, for some $n$, instead of $8 \times 8$. Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the...
TAOCP 7.2.2.2 Exercise 77
Section 7.2.2.2: Satisfiability Exercise 77. [ 20 ] "Step $X_{-1}$," which precedes $X_0$ in (38), has the glider configuration ▶ instead of ▼. What conditions on the still life $X_S$ will ensure that state $X_0$ is indeed reached? (We don't want digestion to begin prematurely.) Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff...
TAOCP 7.2.2.2 Exercise 76
Section 7.2.2.2: Satisfiability Exercise 76. [ 41 ] Construct a mobile Life oscillator of period 3. Verified: no Solve time: 3m40s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly one...
TAOCP 7.2.2.2 Exercise 75
Section 7.2.2.2: Satisfiability Exercise 75. [ M22 ] $[M22]$ (Stephen Silver, 2000.) Show that a finite, mobile oscillator of period $p \ge 3$ must have some cell that is alive more than once during the cycle. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$...
TAOCP 7.2.2.2 Exercise 74
Section 7.2.2.2: Satisfiability Exercise 74. [ M28 ] $[M28]$ Continuing the previous exercise, prove that no nonblank cell of a finite mobile flipflop has more than one neighbor of its own type. (This fact greatly speeds up the search for finite mobile flipflops.) Can two type A cells be diagonally adjacent? Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating...
TAOCP 7.2.2.2 Exercise 73
Section 7.2.2.2: Satisfiability Exercise 73. ▶ [ 21 ] $[21]$ (Mobile flipflops.) An oscillator of period 2 is called a flipflop , and the Life patterns of mobile flipflops are particularly appealing: Each cell is either blank (dead at every time $t$) or type A (alive when $t$ is even) or type B (alive when $t$ is odd). Every nonblank cell (i) has exactly three neighbors of the other type,...
TAOCP 7.2.2.2 Exercise 72
Section 7.2.2.2: Satisfiability Exercise 72. [ 28 ] $[28]$ Oscillators of period 3 are particularly intriguing, because Life seems so inherently binary. a) What are the smallest such oscillators (in terms of bounding box)? b) Find period-3 oscillators of sizes $9 \times n$ and $10 \times n$, with $n$ odd, that have "fourfold symmetry": The patterns are unchanged after left-right and/or up-down reflection. (Such patterns are not only pleasant to...
TAOCP 7.2.2.2 Exercise 71
Section 7.2.2.2: Satisfiability Exercise 71. ▶ [ 22 ] $[22]$ When looking for sequences of Life transition on a square grid, an asymmetrical solution will appear in eight different forms, because the grid has eight different symmetries. Furthermore, an asymmetrical periodic solution will appear in $8r$ different forms, if $r$ is the length of the period. Explain how to add further clauses so that essentially equivalent solutions will occur only...
TAOCP 7.2.2.2 Exercise 70
Section 7.2.2.2: Satisfiability Exercise 70. [ 21 ] $[21]$ The live cells of an oscillator are divided into a rotor (those that change) and a stator (those that stay alive). a) Show that the rotor cannot be just a single cell. b) Find the smallest example of an oscillator whose rotor is $\leftrightarrow \blacksquare$. c) Similarly, find the smallest oscillators of period 3 whose rotors have the following forms: $\to...
TAOCP 7.2.2.2 Exercise 69
Section 7.2.2.2: Satisfiability Exercise 69. [ 23 ] $[23]$ Find all (a) still lifes and (b) oscillators of period $> 1$ that live in a $4 \times 4$ board. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The...
TAOCP 7.2.2.2 Exercise 68
Section 7.2.2.2: Satisfiability Exercise 68. [ 39 ] $[39]$ Find a maximum-length mobile path in which 6 to 10 cells are always alive. Verified: no Solve time: 3m40s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses...
TAOCP 7.2.2.2 Exercise 67
Section 7.2.2.2: Satisfiability Exercise 67. [**] $[2\frac{1}{2}]$ Find a mobile chessboard path $X_0 \to X_1 \to \cdots \to X_{21}$ with no more than five cells alive in each $X_i$. (The glider in (37) leaves the board after $X_{20}$.) How about $X_{22}$? Verified: no Solve time: 3m41s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le...
TAOCP 7.2.2.2 Exercise 66
Section 7.2.2.2: Satisfiability Exercise 66. [ 24 ] $[24]$ Use a SAT solver to find short counterparts to Fig. 35 in which (a) $N_1 = \mathbf{LIFE}$; (b) $X_2 = \mathbf{LIFE}$. In each case $X_0$ should have the smallest possible number of live cells. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$...
TAOCP 7.2.2.2 Exercise 65
Section 7.2.2.2: Satisfiability Exercise 65. ▶ [ 28 ] $[28]$ Describe encodings of the Life transition function (35) into clauses. a) Use only the variables $x' {ij}$ and $x {ij}$. b) Use auxiliary variables with the Bailleux and Boufkhad encoding (20)–(21), sharing intermediate results between neighboring cells as discussed in the text. Verified: no Solve time: 2m21s Setup Let $x_{ij}$ denote the state of cell $(i,j)$ before a Life transition,...
TAOCP 7.2.2.2 Exercise 64
Section 7.2.2.2: Satisfiability Exercise 64. [ 26 ] $[26]$ The exact minimum time $\hat{T}(n)$ of a sorting network for $n$ elements is a famous unsolved problem, and the fact that $\hat{T}(9) = 7$ was first established in 1987 by running a highly optimized program for many hours on a Cray 2 supercomputer. Show that this result can now be proved with a SAT solver in less than a second(!). Verified:...
TAOCP 7.2.2.2 Exercise 63
Section 7.2.2.2: Satisfiability Exercise 63. ▶ [ 29 ] $[29]$ Given an $n$-network $\alpha = [i_1 : j_1][i_2 : j_2] \cdots [i_r : j_r]$, as defined in the exercises for Section 5.3.4, explain how to use a SAT solver to test whether or not $\alpha$ is a sorting network. Hint: Use Theorem 5.3.4Z. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean...
TAOCP 7.2.2.2 Exercise 62
Section 7.2.2.2: Satisfiability Exercise 62. [ 29 ] $[29]$ Try to learn a secret small-DNF function with $N$-bit training sets $x^{(0)}, x^{(1)}, x^{(2)}, \ldots$, where $x^{(0)}$ is random but each bit of $x^{(k)} \oplus x^{(k-1)}$ for $k > 0$ is 1 with probability $p$. (Thus, if $p$ is small, successive data points will tend to be near each other.) Do such sets turn out to be more efficient in practice...
TAOCP 7.2.2.2 Exercise 61
Section 7.2.2.2: Satisfiability Exercise 61. [ 30 ] $[30]$ Explain how to test when a set of clauses generated from a training set via (29)–(31) is satisfiable only by the function $f(x)$ in (27). Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the...
TAOCP 7.2.2.2 Exercise 60
Section 7.2.2.2: Satisfiability Exercise 60. [ 24 ] $[24]$ Experiment with the problem of learning $f(x)$ in (27) from training sets of sizes 32 and 64. Use a SAT solver to find a conjectured function, $\hat{f}(x)$; then use BDD methods to determine the probability that this $\hat{f}(x)$ differs from $f(x)$ for random $x$. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean...
TAOCP 7.2.2.2 Exercise 59
Section 7.2.2.2: Satisfiability Exercise 59. [ M20 ] $[M20]$ Compute the exact probability that $f(x)$ in (32) differs from $f(x)$ in (27). Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 58
Section 7.2.2.2: Satisfiability Exercise 58. ▶ [ 20 ] $[20]$ Discuss adding the clauses $\bar{p} {i,j} \vee \bar{q} {i,j}$ to (29), (30), and (31). Verified: no Solve time: 3m41s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the...
TAOCP 7.2.2.2 Exercise 57
Section 7.2.2.2: Satisfiability Exercise 57. [ 29 ] $[29]$ Combining the previous exercise with the methods of Section 7.1.2, exhibit a function $f$ for Table 2 that can be evaluated with only six Boolean operations(!). Verified: no Solve time: 6m33s The data supplied is insufficient to produce a correct solution to this exercise. Exercise 7.2.2.2.57 does not define the target function by itself. It refers to “Table 2”, which contains...
TAOCP 7.2.2.2 Exercise 56
Section 7.2.2.2: Satisfiability Exercise 56. ▶ [ 22 ] $[22]$ Equation (27) exhibits a function matching Table 2 that depends on only 8 of the 20 variables. Use a SAT solver to show that we can actually find a suitable $f$ that depends on only five of the $x_j$. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 55
Section 7.2.2.2: Satisfiability Exercise 55. [ 21 ] $[21]$ Find an equation analogous to (27) that is consistent with Table 2 and has every variable complemented. (Thus the resulting function is monotone decreasing.) Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 54
Section 7.2.2.2: Satisfiability Exercise 54. ▶ [ 29 ] $[29]$ Extend Table 2 using the rule in the previous exercise. How many rows are needed before $f(x)$ has no $M$-term representation in DNF, when $M = 3$, 4, and 5? Verified: no Solve time: 4m07s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$...
TAOCP 7.2.2.2 Exercise 53
Section 7.2.2.2: Satisfiability Exercise 53. ▶ [ M20 ] $[M20]$ The numbers in Table 2 are definitely nonrandom. Can you see why? Verified: no Solve time: 3m50s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 526
Section 7.2.2.2: Satisfiability Exercise 526. [ M25 ] (David S. Johnson, 1974.) If $F$ has $m$ clauses, all of size $\ge k$, prove that some assignment leaves at most $m/2^k$ clauses unsatisfied. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has...
TAOCP 7.2.2.2 Exercise 525
Section 7.2.2.2: Satisfiability Exercise 525. ▶ [ 40 ] Find the most difficult 3SAT problem you can that has at most 100 variables. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses...
TAOCP 7.2.2.2 Exercise 524
Section 7.2.2.2: Satisfiability Exercise 524. ▶ [ 22 ] Find all Hamiltonian paths of the cube $P_3 \mathbin{\square} P_3 \mathbin{\square} P_3$ that have loopless shadows. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains...
TAOCP 7.2.2.2 Exercise 523
Section 7.2.2.2: Satisfiability Exercise 523. [ 20 ] Prove that, for any $m$ or $n$, no cycle of the graph $P_m \mathbin{\square} P_n \mathbin{\square} P_2$ has loopless shadows. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct...
TAOCP 7.2.2.2 Exercise 522
Section 7.2.2.2: Satisfiability Exercise 522. ▶ [ 26 ] (Loopless shadows.) A cyclic path within the cube $P_3 \mathbin{\square} P_3 \mathbin{\square} P_3$ is shown here, together with the three "shadows" that appear when it is projected onto each coordinate plane. Notice that the shadow at the bottom contains a loop, but the other two shadows do not. Does this cube contain a cycle whose three shadows are entirely without loops?...
TAOCP 7.2.2.2 Exercise 521
Section 7.2.2.2: Satisfiability Exercise 521. [ 30 ] Experiment with the following idea, which is much simpler than the clause-purging method described in the text: "Forget a learned clause of length $k$ with probability $p_k$," where $p_1 \ge p_2 \ge p_3 \ge \cdots$ is a tunable sequence of probabilities. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 520
Section 7.2.2.2: Satisfiability Exercise 520. ▶ [ 24 ] Every instance of SAT corresponds in a natural way to an integer programming feasibility problem: To find, if possible, integers $x_1, \ldots, x_n$ that satisfy the linear inequalities $0 \le x_j \le 1$ for $1 \le j \le n$ and $$l_1 + l_2 + \cdots + l_k \ge 1 \qquad \text{for each clause } C = (l_1 \vee l_2 \vee \cdots...
TAOCP 7.2.2.2 Exercise 52
Section 7.2.2.2: Satisfiability Exercise 52. [ 15 ] $[15]$ What clauses correspond to (29) and (30) when the second case on the left of Table 2, $f(1, 0, 1, 0, \ldots, 1) = 1$, is taken into account? Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le...
TAOCP 7.2.2.2 Exercise 519
Section 7.2.2.2: Satisfiability Exercise 519. [ 20 ] Table 7 shows inconclusive results in a race for factoring between factor.fifo and factor.lifo . What is the comparable performance of factor.rand $(m, n, z, 314159)$? Verified: no Solve time: 2m37s Solution The statement of the exercise depends on numerical data from Table 7, but that table is not included in the supplied context. The names factor.fifo , factor.lifo , and factor.rand...
TAOCP 7.2.2.2 Exercise 518
Section 7.2.2.2: Satisfiability Exercise 518. [ M32 ] [M32] Given a 3SAT problem with $m$ clauses and $n$ variables, we shall construct a $(6m + n) \times (6m + n)$ matrix $M$ of integers such that the permanent , per $M$, is zero if and only if the clauses are unsatisfiable. For example, the solvable problem (7) corresponds to the $46 \times 46$ matrix indicated here; each shaded box stands...
TAOCP 7.2.2.2 Exercise 517
Section 7.2.2.2: Satisfiability Exercise 517. [ 25 ] [25] Given clauses $C_1, \ldots, C_m$, the one-per-clause satisfiability problem asks if there is a Boolean assignment $x_1, \ldots, x_n$ such that every clause is satisfied by a unique literal. In other words, we want to solve the simultaneous equations $\Sigma C_j = 1$ for $1 \le j \le m$, where $\Sigma C_j$ is the sum of the literals of clause $C_j$....
TAOCP 7.2.2.2 Exercise 516
Section 7.2.2.2: Satisfiability Exercise 516. [ M9 ] [M9] Prove or disprove the strong exponential time hypothesis : "If $\tau < 2$, there is an integer $k$ such that no randomized algorithm can solve every $k$SAT problem in fewer than $\tau^n$ steps, where $n$ is the number of variables." Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 515
Section 7.2.2.2: Satisfiability Exercise 515. ▶ [ 23 ] [23] ( Hard sudoku. ) Specify SAT clauses with which a designer of sudoku puzzles can meet the following specifications: (i) If cell $(i, j)$ of the puzzle is blank, so is cell $(10-i, 10-j)$, for $1 \le i, j \le 9$. (ii) Every row, every column, and every box contains at least one blank. ("Box" means one of sudoku's nine...
TAOCP 7.2.2.2 Exercise 514
Section 7.2.2.2: Satisfiability Exercise 514. [ 24 ] $[24]$ The timings quoted in the text for Algorithm W, for problems in Table 6, are based on the median of nine runs using the parameters $p = A$ and $N = 50n$, restarting from scratch if necessary until a solution is found. Those parameters worked fine in most cases, unless Algorithm W was unsuited to the task. But problem C9 was...
TAOCP 7.2.2.2 Exercise 513
Section 7.2.2.2: Satisfiability Exercise 513. [ 24 ] $[24]$ Find parameters for Algorithm L that tune it for $\mathit{rand}(3, m, n, \mathit{seed})$. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 512
Section 7.2.2.2: Satisfiability Exercise 512. [ 29 ] $[29]$ Find parameters for Algorithm C that will find an Erdős discrepancy pattern $x_1, \ldots, x_n$ rapidly. (This is problem E in Table 6.) Compare the running times of nine random runs with linear parameters (194) versus nine random runs with (194), when $n = 400, 500, 600, \ldots, 1100, 1160$, and 1161. Verified: no Solve time: 3m47s Solution In the direct...
TAOCP 7.2.2.2 Exercise 511
Section 7.2.2.2: Satisfiability Exercise 511. [ 22 ] $[22]$ Problem P4 in Table 6 is a strange set of clauses that caused Algorithm C (in Figs. 54 and 55; and it causes Algorithm L to "time out" in Fig. 53. a) The preprocessing algorithm of the text requires about 1.5 megamems to convert those 2509 clauses in 400 variables into just 2414 clauses in 339 variables. Show empirically that Algorithm...
TAOCP 7.2.2.2 Exercise 510
Section 7.2.2.2: Satisfiability Exercise 510. [ 18 ] $[18]$ When the data points A1, A2, …, X8 were plotted in Fig. 55, one by one, they sometimes covered parts of previously plotted points, because of overlaps. What test cases are partially hidden by (a) T2? (b) X6? (c) X7? Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 51
Section 7.2.2.2: Satisfiability Exercise 51. [ 40 ] $[40]$ Study the behavior of SAT solvers on the problem of finding a small number of test patterns for all of the detectable single-stuck-at faults of the circuit $\mathit{prod}(32, 32)$. Can a complete set of patterns for this large circuit be discovered "automatically" (without relying on number theory)? Verified: no Solve time: 2m45s Solution In the direct encoding, each variable $x_i$ is...
TAOCP 7.2.2.2 Exercise 509
Section 7.2.2.2: Satisfiability Exercise 509. [ 20 ] $[20]$ Several of the "training set" tasks used when tuning Algorithm C's parameters were taken from the 100 test cases of Table 6. Why didn't this lead to a problem of "overfitting" (namely, of choosing parameters that are too closely associated with the trainees)? Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables...
TAOCP 7.2.2.2 Exercise 508
Section 7.2.2.2: Satisfiability Exercise 508. [ M20 ] $[M20]$ According to Table 7, Algorithm C proved problem T3 to be unsatisfiable after learning about 324 thousand clauses. About how many times did it enter a purging phase in step C7? Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$...
TAOCP 7.2.2.2 Exercise 507
Section 7.2.2.2: Satisfiability Exercise 507. ▶ [ 21 ] $[21]$ (Marijn Heule.) Explain why "windfalls" (see (72)) help Algorithm L to deal with miter problems such as D5. Verified: no Solve time: 3m50s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct...
TAOCP 7.2.2.2 Exercise 506
Section 7.2.2.2: Satisfiability Exercise 506. [ 22 ] $[22]$ The weighted variable interaction graph of a family of clauses has one vertex for each variable, and the weight $\Sigma, 2/(\lfloor |c| \rfloor\choose 2)$ between vertices $u$ and $v$, where the sum is over all clauses $c$ that contain both $\pm u$ and $\pm v$. Figure 52 indicates these weights indirectly, by making the heavier edges darker. a) True or false:...
TAOCP 7.2.2.2 Exercise 505
Section 7.2.2.2: Satisfiability Exercise 505. [ 21 ] $[21]$ Experiment with making Algorithm L nondeterministic, by randomizing the initial order of VAR in step L1 just as HEAP is initialized randomly in step C1. How does the modified algorithm perform on, say, problems D3, K0, and W2 of Table 6? Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its...
TAOCP 7.2.2.2 Exercise 504
Section 7.2.2.2: Satisfiability Exercise 504. ▶ [ M21 ] The problem in exercise 502 can be proved NP-complete as follows: a) Let $w_j$ be the string of length $2n$ that is entirely 0 except for 1s in positions $2j-1$ and $2j$, and let $w_{n+j} = w_j$, for $1 \le j \le n$. Describe all binary strings of length $2n$ that differ from each of $w_1, \ldots, w_{2n}$ in at most...
TAOCP 7.2.2.2 Exercise 503
Section 7.2.2.2: Satisfiability Exercise 503. [ M20 ] (Covering strings.) Given $s_j$ and $r_j$ as in exercise 502, show that every string of length $n$ is within $r_j$ bits of some $s_j$ if and only if the closest string problem has no solution with parameters $r'_j = n - 1 - r_j$. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables...
TAOCP 7.2.2.2 Exercise 502
Section 7.2.2.2: Satisfiability Exercise 502. [ 16 ] (Closed strings.) Given binary strings $s_1, \ldots, s_m$ of length $n$, and threshold parameters $r_1, \ldots, r_m$, construct clauses that are satisfiable by $x = x_1 \ldots x_n$ if and only if $x$ differs from $s_i$ in at least $r_i$ bit positions, for $1 \le j \le m$. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is...
TAOCP 7.2.2.2 Exercise 501
Section 7.2.2.2: Satisfiability Exercise 501. [ 22 ] Martin Gardner introduced an interesting queen placement problem in Scientific American 235 , 4 (October 1976), 134–137: "Place $r$ queens on an $m \times n$ chessboard so that (i) no more than one queen per row; (ii) the fewest possible squares can be occupied without breaking rule (i); and (iii) $r$ is as small as possible." Construct clauses that are satisfiable if...
TAOCP 7.2.2.2 Exercise 500
Section 7.2.2.2: Satisfiability Exercise 500. [ 16 ] The precocious student J. H. Quick decided to extend the monkey wrench principle, arguing that if $F_0 \cup S \models f$ then the original clauses $F$ can be replaced by $F | l$. But he soon realized his mistake. What was it? Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its...
TAOCP 7.2.2.2 Exercise 50
Section 7.2.2.2: Satisfiability Exercise 50. [ 24 ] $[24]$ Demonstrate Larrabee's method of representing stuck-at faults by describing the clauses that characterize test patterns for the fault "$x_2^-$ stuck at 1" in Fig. 34. (This is the wire that splits off of $x_2$ and feeds into $x_2^3$ and $x_2^5$, then to $b_7$ and $b_5$; see Table 1.) Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$...
TAOCP 7.2.2.2 Exercise 499
Section 7.2.2.2: Satisfiability Exercise 499. [ 21 ] In the pigeonhole problem, is it legitimate to include the clauses (18$_3$) together with clauses that enforce lexicographic row and column order? Verified: no Solve time: 3m40s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$....
TAOCP 7.2.2.2 Exercise 498
Section 7.2.2.2: Satisfiability Exercise 498. [ 22 ] Justify adding the symmetry-breakers (18$_3$) to the pigeonhole clauses. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly...
TAOCP 7.2.2.2 Exercise 497
Section 7.2.2.2: Satisfiability Exercise 497. [ 22 ] Use BDD methods to determine the number of $8 \times 8$ binary matrices that have both row and column order increasing in lexicographic order. How many of them have exactly $r$ 1s, for $r = 24$, $r = 25$, $r = 64 - 25 = 39$, and $r = 64 - 24 = 40$? Verified: no Solve time: 3m45s Solution In the...
TAOCP 7.2.2.2 Exercise 496
Section 7.2.2.2: Satisfiability Exercise 496. [ M20 ] B. C. Dull reasoned as follows: "The pigeonhole clauses have row and column symmetry. Therefore we can assume that the rows are lexicographically increasing from top to bottom, and the columns are lexicographically increasing from right to left. Consequently the problem is easily seen to be unsatisfiable." Was he correct? Verified: no Solve time: 5m55s Solution In the direct encoding, each variable...
TAOCP 7.2.2.2 Exercise 495
Section 7.2.2.2: Satisfiability Exercise 495. [ M22 ] Spell out the details of how we can justify appending clauses to assert (18$ 5$) and (18$ 6$), using Corollary E, whenever we have an $m \times n$ problem whose variables $x {ij}$ have both row and column symmetry. [In other words, we assume that $x {ij} \mapsto x_{\sigma(i)\rho(j)}$ is an automorphism for all permutations $\sigma$ of ${1,\ldots,m}$ and $\rho$ of ${1,\ldots,n}$.]...
TAOCP 7.2.2.2 Exercise 494
Section 7.2.2.2: Satisfiability Exercise 494. [ 21 ] Show that if $(uw)(ûŵ)$ is a symmetry of some clauses $F$, we're allowed to break symmetries as if $(uw)(\hat{u}\hat{w})$, $(u\hat{w})(\hat{u}w)$, and $(w\hat{u})(\hat{w}u)$ were also symmetries. For example, if $i < j < k$ and if $(ijk)(\hat{i}\hat{j}\hat{k})$ is a symmetry, we can assert $(\bar{x}_i \vee x_j) \wedge (\bar{x}_j \vee x_k)$ with respect to the global ordering $p_1 \ldots p_n = 1 \ldots n$....
TAOCP 7.2.2.2 Exercise 493
Section 7.2.2.2: Satisfiability Exercise 493. [ 20 ] The problem $werden(3,3;9)$ has four symmetries, because we can reflect and/or complement all the variables. How can we speed up the proof of unsatisfiability by adding clauses to break those symmetries? Verified: no Solve time: 3m54s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and...
TAOCP 7.2.2.2 Exercise 492
Section 7.2.2.2: Satisfiability Exercise 492. [ M20 ] [M20] Let $\tau$ be a signed mapping of the variables ${x_1, \ldots, x_n}$; for example, the signed mapping '4133' stands for the operation $(x_1, x_2, x_3, x_4) \mapsto (\bar{x}_4, x_1, x_3, x_3)$. When a signed mapping is applied to a clause, some of the resulting literals may coincide; or two literals might become complementary, making a tautology. When $\tau = \overline{4}133$, for...
TAOCP 7.2.2.2 Exercise 491
Section 7.2.2.2: Satisfiability Exercise 491. [ 22 ] [22] The unsatisfiable clause $R$ in (6) have the signed permutation 2341 as an automorphism. How can this fact help us to verify their unsatisfiability? Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 490
Section 7.2.2.2: Satisfiability Exercise 490. [ 15 ] [15] Does Theorem E hold also when $p_1 p_2 \ldots p_n$ is any signed permutation? Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses...
TAOCP 7.2.2.2 Exercise 49
Section 7.2.2.2: Satisfiability Exercise 49. [ 21 ] $[21]$ Write a program that determines exactly which of the 100 single-stuck-at faults of the circuit in Fig. 34 are detected by each of the 32 possible input patterns. Also find all the minimum sets of test patterns that will discover every such fault (unless it's not detectable). Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is...
TAOCP 7.2.2.2 Exercise 489
Section 7.2.2.2: Satisfiability Exercise 489. [ M21 ] [M21] Find a recurrence for $T_n$, the number of signed involutions on $n$ elements. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 488
Section 7.2.2.2: Satisfiability Exercise 488. [ 24 ] [24] (Peaceable armies of queens.) Prove that armies of nine white queens and nine black queens can coexist on a chessboard with none attacking the other, but armies of size 10 cannot, by devising appropriate sets of clauses and applying Algorithm C. Also examine the effects of symmetry breaking. (This problem has sixteen symmetries, because we can swap colors and/or rotate and/or...
TAOCP 7.2.2.2 Exercise 487
Section 7.2.2.2: Satisfiability Exercise 487. ▶ [ 27 ] [27] There are $\binom{92}{2} = 4216,368$ ways to place eight queens on a chessboard. Long ago, W. H. Rouse asked which of these leaves the maximum number of vacant squares to remain unattacked. [See W. W. Rouse Ball, Mathematical Recreations and Problems , third edition (London: Macmillan, 1896), 109–110.] Every subset $S$ of the vertices of a graph has three boundary...
TAOCP 7.2.2.2 Exercise 486
Section 7.2.2.2: Satisfiability Exercise 486. [ 21 ] [21] (Late Binding solitaire.) Shuffle a deck and deal out 18 cards; then try to reduce these 18 piles to a single pile, using a sequence of "captures" in which one pile is placed on top of another pile. A pile can capture only the pile to its immediate left, or the pile found by skipping left over two other piles. Furthermore...
TAOCP 7.2.2.2 Exercise 485
Section 7.2.2.2: Satisfiability Exercise 485. ▶ [ 23 ] [23] Sometimes successive transitions in the previous exercise are commutative: For example, the effect of $q_{t,k}$ and $q_{t,k+1}$ is the same as $q_{t,k+2}$ and $q_{t+1,k}$. Explain how to break symmetry in such cases, by allowing only one of the two possibilities. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its...
TAOCP 7.2.2.2 Exercise 484
Section 7.2.2.2: Satisfiability Exercise 484. [ 22 ] [22] ( Graph quenching. ) A graph with vertices $(v_1, \ldots, v_n)$ is called "quenchable" if either (i) $n = 1$; or (ii) there's a $k$ such that $v_k - v_{k+1}$ and the graph on $(v_1, \ldots, v_{k-1}, v_{k+1}, \ldots, v_n)$ can be quenched; or (iii) there's an $l$ such that $v_l - v_{l+3}$ and the graph on $(v_1, \ldots, v_{l-1}, v_{l+2},...
TAOCP 7.2.2.2 Exercise 483
Section 7.2.2.2: Satisfiability Exercise 483. [ 21 ] [21] Symmetry between colors was broken in the coloring problems of Table 6 by assigning fixed colors to a large clique in each graph. But many graphs have no large clique, so a different strategy is necessary. Explain how to encode the "restricted growth string" principle (see Section 7.2.1.5) with appropriate clauses, given an ordering $v_1 v_2 \ldots v_n$ of the vertices:...
TAOCP 7.2.2.2 Exercise 482
Section 7.2.2.2: Satisfiability Exercise 482. ▶ [ 26 ] [26] ( Erdős discrepancy patterns. ) The binary sequence $y_1 \ldots y_t$ is called strongly balanced if we have $|\sum_{j=1}^{k}(2y_j - 1)| \le 2$ for $1 \le k \le t$. a) Show that this balance condition needs to be checked only for odd $k \ge 3$. b) Describe clauses that efficiently characterize a strongly balanced sequence. c) Construct clauses that are...
TAOCP 7.2.2.2 Exercise 481
Section 7.2.2.2: Satisfiability Exercise 481. ▶ [ 28 ] [28] An ordered bit pair $xy$ can be encoded by another ordered bit pair $[xy] = (x \bar y)(y)$ without loss of information, because $[xy] = uv$ implies $[uv] = xy$. a) Find an optimum circuit that computes $([z z']^\dagger)_2 = x_1 + x_2 + 1$. Find an optimum circuit that computes $((u \oplus v) + v)$, and note that $v[00]...
TAOCP 7.2.2.2 Exercise 480
Section 7.2.2.2: Satisfiability Exercise 480. [ 25 ] [25] Suppose the values 0, 1, 2 are encoded by the two-bit codes $x_1 x_r = 00, 01$, and $1*$, respectively, where 10 and 11 both represent 2. (See Eq. 7.1.3–(120).) a) Find an optimum circuit for mod 3 addition: $z_{1*} = (x_{1r} + y_{1r}) \bmod 3$. b) Find an optimum circuit that computes $x_{1r} + y_{1r} + z_{1r} \pmod 3$ mod...
TAOCP 7.2.2.2 Exercise 48
Section 7.2.2.2: Satisfiability Exercise 48. [ 20 ] $[20]$ The small circuit shown here has three inputs, three XOR gates, one fanout gate, eight wires, and one output. Which single-stuck-at faults are detected by each of the eight test patterns $pqr$? Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le...
TAOCP 7.2.2.2 Exercise 479
Section 7.2.2.2: Satisfiability Exercise 479. ▶ [ 25 ] [25] Use SAT technology to find optimum circuits for the following problems: a) Compute $z_2, z_1$, and $z_0$, when $x_1 + x_2 + x_3 + x_4 = (z_2 z_1 z_0)_2$ (see 7.1.2–(27)). b) Compute $z_3, z_1$, and $z_0$, when $x_1 + x_2 + x_3 + x_4 + x_5 = (z_2 z_1 z_0)_2$. c) Compute all four symmetric functions $S_0, S_1, S_2,...
TAOCP 7.2.2.2 Exercise 478
Section 7.2.2.2: Satisfiability Exercise 478. ▶ [ 23 ] [23] Suggest ways to break symmetry in the clauses of exercise 477 . Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 477
Section 7.2.2.2: Satisfiability Exercise 477. ▶ [ 23 ] [23] ( Optimum Boolean evaluation. ) Construct clauses that are satisfiable if and only if an $r$-step normal Boolean chain that computes $m$ given functions $g_1$, $\ldots, g_m$ on $n$ variables. (For example, if $n = 3$ and $g_1 = (x_1 x_2 x_3)$, $g_2 = x_1 \oplus x_2 \oplus x_3$, such clauses with $r = 4$ and $5$ enable a SAT...
TAOCP 7.2.2.2 Exercise 476
Section 7.2.2.2: Satisfiability Exercise 476. [**] [$M23$] For $n \le 5$, find Boolean functions of $n$ variables that are (a) asymmetric but not totally asymmetric; (b) totally asymmetric. Furthermore, your functions should be the easiest possible (in the sense of having a smallest possible Boolean chain), among all functions that qualify. Hint: Combine exercises 475 and 477. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$...
TAOCP 7.2.2.2 Exercise 475
Section 7.2.2.2: Satisfiability Exercise 475. [**] [$M22$] Entitled, a Boolean function is called asymmetric if the identity is its only symmetry; it is totally asymmetric if it is asymmetric and has no antisymmetries. a) If $f$ is totally asymmetric, how many functions are equivalent to $f$ under the operations of permuting variables, complementing variables, and/or complementing the function? b) According to (a) and 7.1.1–(95), the function $(x \vee y) \wedge...
TAOCP 7.2.2.2 Exercise 474
Section 7.2.2.2: Satisfiability Exercise 474. [**] [$M20$] A signed permutation is a symmetry of $f(x)$ if and only if $f(x) = f(\bar{x}\sigma)$ for all $x$, and it is an antisymmetry if and only if we have $f(x) = f(\bar{x}\sigma)$ for all $x$. a) How many signed permutations of $n$ elements are possible? b) Write 7514263 in cycle form, as an unsigned permutation of $(1, \ldots, 7, 1, \ldots, 7)$. c)...
TAOCP 7.2.2.2 Exercise 473
Section 7.2.2.2: Satisfiability Exercise 473. ▶ [**] [$M23$] Generalize exercise 470 to endomorphisms for the unsatisfiable clauses of Tseytin's graph parity problems in exercise 245. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains...
TAOCP 7.2.2.2 Exercise 472
Section 7.2.2.2: Satisfiability Exercise 472. [**] [$M25$] Prove that even-odd endomorphisms such as (190) in the domino covering problem can be regarded as instances of the endomorphisms in exercise 470. Verified: no Solve time: 3m54s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$....
TAOCP 7.2.2.2 Exercise 471
Section 7.2.2.2: Satisfiability Exercise 471. [ 16 ] [16] Find all fixed points of the mappings in exercise 470 when the graph is $K_{20}$. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the...
TAOCP 7.2.2.2 Exercise 470
Section 7.2.2.2: Satisfiability Exercise 470. ▶ [**] [$M22$] Another class of endomorphisms, one for every 4-cycle, can also be used in perfect matching problems: Let the vertices (instead of the edges) be totally ordered in some fashion. Every 4-cycle can be written $v_0 - v_1 - v_2 - v_3 - v_0$, with $v_0 > v_1 > v_3$ and $v_0 > v_2$; the corresponding endomorphism changes any solution for which $v_0...
TAOCP 7.2.2.2 Exercise 47
Section 7.2.2.2: Satisfiability Exercise 47. [ 30 ] $[30]$ Suppose a circuit such as Fig. 34 has $m$ outputs and $n$ inputs, with $g$ gates that transform two signals into one and $h$ gates that transform one signal into two. Find a relation between $g$ and $h$, by expressing the total number of wires in two ways. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$...
TAOCP 7.2.2.2 Exercise 469
Section 7.2.2.2: Satisfiability Exercise 469. ▶ [**] [$M25$] Find a certificate of unsatisfiability $(C_1, C_2, \ldots, C_t)$ for the fact that an $8 \times 8$ chessboard minus cells $(1, 8)$ and $(8, 1)$ cannot be exactly covered by dominoes $h_{ij}$ and $v_{ij}$ that are fixed under all of the even-odd endomorphisms. Each $C_k$ for $1 \le k \le t$ should be a single positive literal. (Therefore the clauses for this...
TAOCP 7.2.2.2 Exercise 468
Section 7.2.2.2: Satisfiability Exercise 468. [ 20 ] [20] Experiment with the mutilated chessboard problem when the even-odd endomorphisms are modified so that (a) they use the same rule for all $i$ and $j$; or (b) they each make an independent random choice between horizontal and vertical. Verified: no Solve time: 3m48s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write...
TAOCP 7.2.2.2 Exercise 467
Section 7.2.2.2: Satisfiability Exercise 467. [ 20 ] $[20]$ Mutilate the $7 \times 8$ and $8 \times 7$ boards by removing the upper right and lower left cells. What domino coverings are fixed by all the even-odd endomorphisms like (190)? Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$...
TAOCP 7.2.2.2 Exercise 466
Section 7.2.2.2: Satisfiability Exercise 466. [ M23 ] $[M23]$ Prove that when $mn$ is even, the text's even-odd rule (190) for endomorphisms of $m \times n$ domino coverings has exactly one fixed point. Verified: no Solve time: 3m48s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 465
Section 7.2.2.2: Satisfiability Exercise 465. [ M21 ] $[M21]$ Justify the text's rule for simultaneous endomorphisms in the perfect matching problem: Any perfect matching must lead to one that's fixed by every $\tau_n$. Verified: no Solve time: 3m48s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 464
Section 7.2.2.2: Satisfiability Exercise 464. ▶ [ M25 ] $[M25]$ Transformations $\tau_1$ and $\tau_2$ don't change the text's example $10 \times 10$ matrix. Prove that they will never change any $10 \times 10$ matrix of sweep 3 that has $\nu X = 51$. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$...
TAOCP 7.2.2.2 Exercise 463
Section 7.2.2.2: Satisfiability Exercise 463. ▶ [ M21 ] $[M21]$ Show that $X$ is a fixed point of $\tau_1$, $\tau_2$, and $\tau_3$ if and only if its rows and columns are nondecreasing. Then show that sweep$(k)$ is a simple function of sweep $\sum_{i,j} x_{ij}$, where the sum is over all binary matrices of $m \times n$, and $k$. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable...
TAOCP 7.2.2.2 Exercise 462
Section 7.2.2.2: Satisfiability Exercise 462. [ 22 ] $[22]$ Explain why $\tau_1$, $\tau_2$, and $\tau_3$ preserve satisfiability in the sweep problem. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 461
Section 7.2.2.2: Satisfiability Exercise 461. [ 20 ] $[20]$ What additional clauses will rule out non-fixed points of $\tau_1$ and $\tau_2$? Verified: no Solve time: 3m54s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 460
Section 7.2.2.2: Satisfiability Exercise 460. [ 21 ] $[21]$ Given $m$, $n$, $k$, and $r$, construct clauses that are satisfied by an $m \times n$ binary matrix $X = (x_{ij})$ if and only if sweep$(X) \le k$ and $\sum_{i,j} x_{ij} \ge r$. Verified: no Solve time: 7m07s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where...
TAOCP 7.2.2.2 Exercise 46
Section 7.2.2.2: Satisfiability Exercise 46. [ 30 ] $[30]$ Find the largest perfect square less than $2^{100}$ that is a binary palindrome. Verified: no Solve time: 3m52s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 459
Section 7.2.2.2: Satisfiability Exercise 459. ▶ [ 20 ] $[20]$ Let $X_{ij}$ denote the submatrix of $X$ consisting of the first $i$ rows and the first $j$ columns. Show that the numbers sweep$(X_{ij})$ satisfy a simple recurrence, from which it's easy to compute sweep$(X)$ = sweep$(X_{mn})$. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$...
TAOCP 7.2.2.2 Exercise 458
Section 7.2.2.2: Satisfiability Exercise 458. [ 20 ] $[20]$ The simplification of clauses by removing an autarky can be regarded as the exploitation of an endomorphism. Explain why. Verified: no Solve time: 3m42s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct...
TAOCP 7.2.2.2 Exercise 457
Section 7.2.2.2: Satisfiability Exercise 457. [ HM19 ] $[HM19]$ Show that every Boolean $f(x_1, x_2, x_3, x_4)$ has more than 51 quadrillion endomorphisms, and an $n$-variable function has more than $2^{2^{n-1}}$ endomorphisms. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has...
TAOCP 7.2.2.2 Exercise 456
Section 7.2.2.2: Satisfiability Exercise 456. [ M21 ] $[M21]$ For how many functions $f(x_1, x_2, x_3, x_4)$ is (187) an endomorphism? Verified: no Solve time: 3m48s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 455
Section 7.2.2.2: Satisfiability Exercise 455. [ M20 ] $[M20]$ Suppose we know that (187) is an endomorphism of some given clauses $F$ on the variables ${x_1, x_2, x_3, x_4}$. Can we be sure that $F$ is satisfiable if and only if $F \wedge C$ is satisfiable, when (a) $C = 124$, i.e., $C = (\bar{x}_1 \vee x_2 \vee \bar{x}_4)$? (b) $C = 234$? (c) $C = 123$? (d) $C =...
TAOCP 7.2.2.2 Exercise 454
Section 7.2.2.2: Satisfiability Exercise 454. [ 15 ] $[15]$ If $\tau$ is an endomorphism for the solutions of $f$, show that $f(x) = f(x\tau)$ for every cyclic element $x$ (every element that's in a cycle of $\tau$). Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le...
TAOCP 7.2.2.2 Exercise 453
Section 7.2.2.2: Satisfiability Exercise 453. [ M23 ] $[M23]$ An $m \times n$ matrix $X = {x_{ij}}$ is said to be decomposable if it has row indices $R \subseteq {1, \ldots, m}$ and column indices $C \subseteq {1, \ldots, n}$ such that $0 < |R| + |C| < m + n$, with $x_{ij} = 0$ whenever $(i \in R$ and $j \notin C)$ or $(i \notin R$ and $j \in...
TAOCP 7.2.2.2 Exercise 452
Section 7.2.2.2: Satisfiability Exercise 452. [ 34 ] $[34]$ Find a nonchromatic rectangle with four colors on an $18 \times 18$ board. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 451
Section 7.2.2.2: Satisfiability Exercise 451. ▶ [ 28 ] [28] Find a way to color the squares of a $10 \times 10$ board with three colors, so that no rectangle has all four corners of the same color. Prove furthermore that every such "nonchromatic rectangle" board has the color distribution ${34, 34, 32}$, not ${34, 33, 33}$. But show that if any square of the board is removed, a nonchromatic...
TAOCP 7.2.2.2 Exercise 450
Section 7.2.2.2: Satisfiability Exercise 450. [ 25 ] [25] Prove that there is essentially only one $10 \times 10$ quad-free system of points and lines with 34 incidences. Hint: First show that every line must contain either 3 points or 4 points; hence every point must belong to either 3 lines or 4 lines. Verified: no Solve time: 3m51s Solution In the direct encoding, each variable $x_i$ is represented by...
TAOCP 7.2.2.2 Exercise 45
Section 7.2.2.2: Satisfiability Exercise 45. [ 20 ] $[20]$ Specify clauses that constrain $(z_1 \ldots z_5)_2$ to be a perfect square. Verified: no Solve time: 3m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 449
Section 7.2.2.2: Satisfiability Exercise 449. [ 21 ] [21] Exhibit $n \times n$ quad-free matrices that contain the maximum number of 1s and obey the lexicographic constraints (185), (186), for $8 \le n \le 16$. Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if...
TAOCP 7.2.2.2 Exercise 448
Section 7.2.2.2: Satisfiability Exercise 448. [ M23 ] What is $Z(m,n)$ when $m$ is odd and $n = m(m-1)/6$? Hint: See 6.5–(16). Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 447
Section 7.2.2.2: Satisfiability Exercise 447. ▶ [ 22 ] [22] Determine the maximum number of edges in a girth-8 subgraph of $K_{8,8}$. Verified: no Solve time: 7m52s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing...
TAOCP 7.2.2.2 Exercise 446
Section 7.2.2.2: Satisfiability Exercise 446. [ M10 ] What's the maximum number of edges in a subgraph of $K_{m,n}$ that has girth $\ge 6$? (Express your answer in terms of $m$ and $n$.) Verified: no Solve time: 3m48s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 445
Section 7.2.2.2: Satisfiability Exercise 445. ▶ [ 22 ] [22] Find short certificates of unsatisfiability for the pigeonhole clauses (106)–(107), when they are supplemented by (a) (181); (b) (182); (c) (183). Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size...
TAOCP 7.2.2.2 Exercise 444
Section 7.2.2.2: Satisfiability Exercise 444. [ M26 ] The following single lookahead unit resolution algorithm, called SLUR, returns either 'sat', 'unsat', or 'maybe', depending on whether a given set $F$ of clauses is satisfiable, unsatisfiable, or beyond its ability to decide via easy propagations: E1. [Propagate.] If $F \vdash \epsilon$, terminate ('unsat'). Otherwise set $F \leftarrow F|{l \mid F \vdash l}$. E2. [Satisfied?] If $F = \emptyset$, terminate ('sat'). Otherwise...
TAOCP 7.2.2.2 Exercise 443
Section 7.2.2.2: Satisfiability Exercise 443. [**] [ M2$\frac{1}{4}$ ] ( A hierarchy of hardness. ) Continuing the previous exercise, a family of clauses $F$ is said to belong to class UC$_k$ if it has the property that $$F|L \vdash \epsilon \text{ implies } F|L \vdash_k \epsilon \quad \text{ for all sets of strictly distinct literals } L.$$ ("Whenever a partial assignment yields unsatisfiable clauses, the inconsistency can be detected by...
TAOCP 7.2.2.2 Exercise 442
Section 7.2.2.2: Satisfiability Exercise 442. ▶ [ M27 ] [M27] The unit propagation relation $\vdash_1$ can be generalized to $k$th order propagation $\vdash_k$ as follows: Let $F$ be a family of clauses and let $l$ be a literal. If $(l_1, l_2, \ldots, l_p)$ is a sequence of literals, we write $L_g^- = {l_1, \ldots, l_{g-1}, \bar{l}_g}$ for $1 \le g \le p$. Then $$F \vdash_0 l \iff l \in F;$$...
TAOCP 7.2.2.2 Exercise 441
Section 7.2.2.2: Satisfiability Exercise 441. [ M35 ] [M35] Show that any threshold function $f(x_1, \ldots, x_n) = [w_1 x_1 + \cdots + w_n x_n \ge t]$ has a forcing representation whose size is polynomial in $\log n$ plus $\log|w_1| + \cdots + \log|w_n|$. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j,...
TAOCP 7.2.2.2 Exercise 440
Section 7.2.2.2: Satisfiability Exercise 440. [ M33 ] [M33] Extend exercise 436 to context free languages , which can be defined by a set $S \subseteq N$ and by production rules $U$ and $W$ of the following well-known forms: $U \subseteq {P \to a \mid P \in N,\ a \in A}$ and $W \subseteq {P \to QR \mid P, Q, R \in N}$, where $N$ is a set of "nonterminal...
TAOCP 7.2.2.2 Exercise 44
Section 7.2.2.2: Satisfiability Exercise 44. ▶ [ 30 ] $[30]$ (Maximum ones.) Find the largest possible value of $vx + vy + v(xy)$, namely the greatest total number of 1 bits, over all multiplications of 32-bit binary $x$ and $y$. Verified: no Solve time: 3m45s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$...
TAOCP 7.2.2.2 Exercise 439
Section 7.2.2.2: Satisfiability Exercise 439. [ 20 ] [20] Construct forcing clauses expressing the constraint that $x_1 + \cdots + x_n = l$ and that there are no two consecutive 1s. (This is the special case $l_1 = \cdots = l_t = 1$ of the previous exercise, but a much simpler construction is possible.) Verified: no Solve time: 3m46s Solution In the direct encoding, each variable $x_i$ is represented by...
TAOCP 7.2.2.2 Exercise 438
Section 7.2.2.2: Satisfiability Exercise 438. [ 21 ] [21] Construct a set of forcing clauses that are satisfiable if and only if a given binary string $x_1 \ldots x_n$ contains exactly $t$ runs of 1s, having lengths $(l_1, l_2, \ldots, l_t)$ from left to right. (Equivalently, the string $x_1 \ldots x_n$ should belong to the language defined by the regular expression $0^ 1^{l_1}0^+1^{l_2}0^+ \ldots 0^+1^{l_t}0^ $.) Verified: no Solve time:...
TAOCP 7.2.2.2 Exercise 437
Section 7.2.2.2: Satisfiability Exercise 437. [ M21 ] [M21] Extend exercise 436 to the general case where $A$ has more than two letters. Verified: no Solve time: 3m49s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses...
TAOCP 7.2.2.2 Exercise 436
Section 7.2.2.2: Satisfiability Exercise 436. [ M32 ] [M32] (Nondeterministic finite-state automata.) A regular language $L$ on the alphabet $A$ can be defined in the following well-known way: Let $Q$ be a finite set of "states," and let $I \subseteq Q$ and $O \subseteq Q$ be designated "input states" and "output states." Also let $T \subseteq Q \times A \times Q$ be a set of "transition rules." Then the string...
TAOCP 7.2.2.2 Exercise 435
Section 7.2.2.2: Satisfiability Exercise 435. ▶ [ 28 ] [28] Given $l \ge 2$, construct a set of $O(n \log l)$ clauses that characterize the language $L_l$ of exercise 434 and are forcing. Verified: no Solve time: 3m53s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 434
Section 7.2.2.2: Satisfiability Exercise 434. [ 21 ] Let $L_l$ be the language defined by the regular expression $0^ 10^ $; in other words, the binary string $x_1 \ldots x_n$ is in $L_l$ if and only if it consists of zero or more 0s followed by exactly 1 1s followed by zero or more 0s. a) Explain why the following clauses are satisfiable if and only if $x_1, \ldots, x_n...
TAOCP 7.2.2.2 Exercise 433
Section 7.2.2.2: Satisfiability Exercise 433. [ 25 ] Are the lexicographic-constraint clauses in (169) forcing? Verified: no Solve time: 4m08s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly one value....
TAOCP 7.2.2.2 Exercise 432
Section 7.2.2.2: Satisfiability Exercise 432. [ 34 ] Exercise 404 gives clauses for the relation $|x - y| \ge a$. Are they forcing? Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses...
TAOCP 7.2.2.2 Exercise 431
Section 7.2.2.2: Satisfiability Exercise 431. ▶ [ 20 ] Construct efficient, forcing clauses for the relation $x_1 + \cdots + x_n \le y_1 + \cdots + y_n$. Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding...
TAOCP 7.2.2.2 Exercise 430
Section 7.2.2.2: Satisfiability Exercise 430. [ 25 ] Similarly, Sinz's clauses (18) and (19) are forcing. Verified: no Solve time: 3m51s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly one...
TAOCP 7.2.2.2 Exercise 43
Section 7.2.2.2: Satisfiability Exercise 43. ▶ [ 21 ] $[21]$ For which integers $n \ge 2$ do there exist odd palindromic binary numbers $x = (x_n \ldots x_1)_2 = (x_1 \ldots x_n)_2$ and $y = (y_n \ldots y_1)_2 = (y_1 \ldots y_n) 2$ such that their product $xy = (z {m+n} \ldots z_1)_2$ is also palindromic? Verified: no Solve time: 3m47s Solution In the direct encoding, each variable $x_i$ is...
TAOCP 7.2.2.2 Exercise 429
Section 7.2.2.2: Satisfiability Exercise 429. [ 22 ] Prove that Bailleux and Boufkhad's clauses (20), (21) are forcing: If any $r$ of the $x$'s have been set to 1, then unit propagation will force all the others to 0. Verified: no Solve time: 3m44s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and...
TAOCP 7.2.2.2 Exercise 428
Section 7.2.2.2: Satisfiability Exercise 428. [ M27 ] A generic graph $G$ on vertices ${1, \ldots, n}$ can be characterized by $\binom{n}{2}$ Boolean variables $Z = {z_{ij} \mid 1 \le i < j \le n}$, where $z_{ij} = [i \text{---} j \text{ in } G]$. Properties of $G$ can therefore be regarded as Boolean functions, $f(X)$. a) Let $f_{\text{nd}}(X) = [\chi(G) \le d]$; that is, $f_{\text{nd}}$ is true if and...
TAOCP 7.2.2.2 Exercise 427
Section 7.2.2.2: Satisfiability Exercise 427. [ M30 ] Exhibit a function $f(x_1, \ldots, x_n)$ for which every set of forcing clauses that uses no auxiliary variables has size $\Omega(3^n/n^2)$, although $f$ can actually be represented by a polynomial number of forcing clauses when auxiliary variables are introduced. Hint: See exercise 7.1.1–116. Verified: no Solve time: 3m56s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating...
TAOCP 7.2.2.2 Exercise 426
Section 7.2.2.2: Satisfiability Exercise 426. ▶ [ M20 ] Suppose $F$ is a set of clauses that represent $f(x_1, \ldots, x_n)$ using auxiliary variables $(a_1, \ldots, a_m)$ as in (170), where $m > 0$. Let $G$ be the clauses that result after variable $a_m$ has been set to 0 (as in 7.1.1–(8)). a) True or false: If $F$ is forcing then $G$ is forcing. b) True or false: If $F$...
TAOCP 7.2.2.2 Exercise 425
Section 7.2.2.2: Satisfiability Exercise 425. [ 18 ] A clause with exactly one positive literal is called a definite Horn clause, and Algorithm 7.1.1C computes the "core" of such clauses. If $F$ consists of definite Horn clauses, prove that $x$ is in the core if and only if $F \vdash_1 x$, if and only if $F \wedge (\bar{x}) \vdash_1 \epsilon$. Verified: no Solve time: 3m59s Solution In the direct encoding,...
TAOCP 7.2.2.2 Exercise 424
Section 7.2.2.2: Satisfiability Exercise 424. ▶ [ 20 ] The dual of the Pi function has the prime clauses ${123, 134, 234, 231, 12}$ (see 7.1.1–(30)). Can any of them be omitted from a forcing representation? Verified: no Solve time: 3m53s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$...
TAOCP 7.2.2.2 Exercise 423
Section 7.2.2.2: Satisfiability Exercise 423. [ 22 ] A representation $F$ that satisfies a condition like (180) but with $l$ replaced by $c$ can be called "weakly forcing." Exercise 422 shows that (175) and (176) are weakly forcing. Does the BDD of every function define a weakly forcing encoding, via (173)? Verified: no Solve time: 3m57s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating...
TAOCP 7.2.2.2 Exercise 422
Section 7.2.2.2: Satisfiability Exercise 422. [ 11 ] What does unit propagation deduce when the additional clause $(x_1)$ or $(\bar{x}_2)$ is appended to (a) $F$ in (175)? (b) $G$ in (176)? Verified: no Solve time: 3m58s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size...
TAOCP 7.2.2.2 Exercise 421
Section 7.2.2.2: Satisfiability Exercise 421. [ 18 ] Derive (176) mechanically from the branching program $I_5 = (\overline{3}2,4{:}3)$, $I_4 = (2\overline{1}{:}2)$, $I_3 = (\overline{2}7{:}0)$, $I_2 = (3\overline{7}{:}1)$, $I_1 = (\overline{3}7{:}0)$, beginning at $I_5$. Verified: no Solve time: 4m09s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain...
TAOCP 7.2.2.2 Exercise 420
Section 7.2.2.2: Satisfiability Exercise 420. [ 18 ] [18] Derive (175) mechanically (that is, "without thinking") from the Boolean chain $s \leftarrow x_1 \oplus x_2$, $c \leftarrow x_1 \wedge x_2$, $s' \leftarrow s \oplus x_3$, $c' \leftarrow s \wedge x_3$, requiring $c = c' = 0$. Verified: no Solve time: 4m22s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$...
TAOCP 7.2.2.2 Exercise 42
Section 7.2.2.2: Satisfiability Exercise 42. [ 21 ] $[21]$ Tseytін encoding analogous to (24) can be devised also for ternary operations, without introducing any additional variables besides those of the function being encoded. Illustrate this principle by encoding the basic operations $x \leftarrow t \oplus u \oplus v$ and $y \leftarrow (tuv)$ of a full adder directly, instead of composing them from $\oplus$, $\wedge$, and $\vee$. Verified: no Solve time:...
TAOCP 7.2.2.2 Exercise 419
Section 7.2.2.2: Satisfiability Exercise 419. [ M21 ] [M21] If $m, n \ge 3$, find (by hand) all solutions to the problem of exercise 418 such that (a) $\sum x_{ij} = m + 1$ (the minimum); (b) $\sum x_{ij} = mn - n - 1$ (the maximum). Verified: no Solve time: 3m56s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write...
TAOCP 7.2.2.2 Exercise 418
Section 7.2.2.2: Satisfiability Exercise 418. [ 23 ] [23] Use a branching program to construct clauses that are satisfiable if and only if $(x_{ij})$ is an $m \times n$ Boolean matrix whose rows satisfy the weighted bit condition $h_m$, and whose columns satisfy the complementary function $\bar{h}_m$. In other words, $$r_i = \sum_{j=1}^{m} x_{ij}, \quad c_j = \sum_{i=1}^{m} x_{ij}, \quad r_i = 2x_{i1} - 1, \quad c_j = 1,$$ for...
TAOCP 7.2.2.2 Exercise 417
Section 7.2.2.2: Satisfiability Exercise 417. [ 21 ] [21] Continuing exercise 432, what is the Tseytin encoding of the modus operation $s \leftarrow C , \mathtt{U} , z$"? Use it to justify the translation of branching programs via (174). Verified: no Solve time: 3m54s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and...
TAOCP 7.2.2.2 Exercise 416
Section 7.2.2.2: Satisfiability Exercise 416. [ 20 ] [20] Encode the condition: if $x_1 \ldots x_n = y_1 \ldots y_n$ then $a_1 \ldots a_m = v_1 \ldots v_m$, using $2m + 2n + 1$ clauses and $n + 1$ auxiliary variables. Hint: 2n of the clauses are in (172). Verified: no Solve time: 3m59s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible...
TAOCP 7.2.2.2 Exercise 415
Section 7.2.2.2: Satisfiability Exercise 415. [ M22 ] [M22] Generalize (169) to an encoding of lexicographic order on $d$-ary vectors, $(x_1 \ldots x_n) \le (y_1 \ldots y_n)_d$, where each $x_k = x_k^1 + \cdots + x_k^{d-1}$ and $y_k = y_k^1 + \cdots + y_k^{d-1}$ has the order encoding. What modifications to your construction will encode the strict relation $x_1 \ldots x_n < y_1 \ldots y_n$? Verified: no Solve time: 4m02s...
TAOCP 7.2.2.2 Exercise 414
Section 7.2.2.2: Satisfiability Exercise 414. [ M20 ] [M20] How many clauses will remain after the auxiliary variables $a_1, \ldots, a_{n-1}$ of (169) have been eliminated by resolution? Verified: no Solve time: 3m57s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct...
TAOCP 7.2.2.2 Exercise 413
Section 7.2.2.2: Satisfiability Exercise 413. [ M23 ] [M23] Find all CNF formulas for the function $(x_1 \oplus y_1) \vee \cdots \vee (x_n \oplus y_n)$. Verified: no Solve time: 3m58s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains...
TAOCP 7.2.2.2 Exercise 412
Section 7.2.2.2: Satisfiability Exercise 412. [ 40 ] [40] Experiment with the encoding of somewhat large numbers by using a radix-$d$ representation in which each digit has the order encoding. Verified: no Solve time: 3m59s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$....
TAOCP 7.2.2.2 Exercise 411
Section 7.2.2.2: Satisfiability Exercise 411. [ 25 ] [25] If $x = (x_m \ldots x_1)_2$, $y = (y_m \ldots y_1) 2$, and $z = (z {m+n} \ldots z_1)_2$ stand for binary numbers, the text explains how to encode the relation $xy = z$ with fewer than $20mn$ clauses, using Napier–Dadda multiplication. Explain how to encode the relations $xy \le z$ and $xy \ge z$ with fewer than $9mn$ and $11mn$...
TAOCP 7.2.2.2 Exercise 410
Section 7.2.2.2: Satisfiability Exercise 410. [ 24 ] [24] Exhibit clauses for the constraint $13x - 8y \le 7$ when $x$ and $y$ are log-encoded as 3-bit integers $x = (x_2 x_1 x_0)_2$ and $y = (y_2 y_1 y_0)_2$. (Compare with exercise 405(b).) Verified: no Solve time: 4m Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$...
TAOCP 7.2.2.2 Exercise 41
Section 7.2.2.2: Satisfiability Exercise 41. [ M31 ] $[M31]$ Determine the number of Boolean operations $\wedge$, $\vee$, $\oplus$ needed to multiply $m$-bit numbers by $n$-bit numbers with Dadda's scheme, when $2 \le m \le n$. Verified: no Solve time: 3m58s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if...
TAOCP 7.2.2.2 Exercise 409
Section 7.2.2.2: Satisfiability Exercise 409. ▶ [ M26 ] [M26] Continuing exercise 408, find the best makespans in the following cases: a) $m = 3$; $n = 3t + 1$; $w_{1j} = w_{2(j+1)} = w_{3(j+s)} = a_j$ for $1 \le j \le r$; $w_{1n} = w_{2n} = w_{3n} = \lfloor (a_1 + \cdots + a_r)/2 \rfloor$; otherwise $w_{ij} = 0$. (The positive integers $a_j$ are given.) b) $m = 4$;...
TAOCP 7.2.2.2 Exercise 408
Section 7.2.2.2: Satisfiability Exercise 408. ▶ [ 25 ] [25] (Open shop scheduling.) Consider a system of $m$ machines and $n$ jobs, together with an $m \times n$ matrix of nonnegative integer weights $W = (w_{ij})$ that represent the amount of uninterrupted time on machine $i$ that is needed by job $j$. The open shop scheduling problem seeks a way to get all the work done in $t$ units of...
TAOCP 7.2.2.2 Exercise 407
Section 7.2.2.2: Satisfiability Exercise 407. [ M22 ] [M22] If $x$, $y$, $z$ are order-encoded, with $0 \le x, y < d$ and $0 \le z < 2d-1$, the clauses $$\bigwedge_{k=1}^{2d-2} \bigwedge_{j=\max(0,k+1-d)}^{k} (x^j \vee \bar{y}^{k-j} \vee z^k)$$ are satisfiable if and only if $x + y \le z$; this is the basic idea underlying (20). Another way to encode the same relation is to introduce new order-encoded variables $u$ and...
TAOCP 7.2.2.2 Exercise 406
Section 7.2.2.2: Satisfiability Exercise 406. [ M24 ] [M24] Order-encode (a) $xy \le a$ and (b) $xy \ge a$, when $a$ is an integer constant. Verified: no Solve time: 3m56s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains...
TAOCP 7.2.2.2 Exercise 405
Section 7.2.2.2: Satisfiability Exercise 405. ▶ [ M25 ] [M25] The purpose of this exercise is to encode the constraint $ax + by \le c$, when $a$, $b$, $c$ are integer constants, assuming that $x$, $y$ are order-encoded with range $[0 ,.,. d)$. a) Prove that it suffices to consider cases where $a, b, c > 0$. b) Exhibit a suitable encoding for the special case $13x - 8y \le...
TAOCP 7.2.2.2 Exercise 404
Section 7.2.2.2: Satisfiability Exercise 404. ▶ [ 21 ] [21] Continuing exercise 403 , encode the condition $|x - y| \ge a$, for a given constant $a \ge 1$, using either (a) $d$ clauses of length $\le 4$ and no auxiliary variables; or (b) $2d - O(a)$ clauses of length $\le 3$, and one auxiliary variable. Verified: no Solve time: 4m04s Solution In the direct encoding, each variable $x_i$ is...
TAOCP 7.2.2.2 Exercise 403
Section 7.2.2.2: Satisfiability Exercise 403. [ 20 ] [20] Suppose $x$, $y$, $z$ have the order encoding, with $0 \le x, y, z < d$. What clauses enforce (a) $\min(x, y) \le z$? (b) $\max(x, y) \le z$? (c) $\min(x, y) \ge z$? (d) $\max(x, y) \ge z$? Verified: no Solve time: 4m05s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values....
TAOCP 7.2.2.2 Exercise 402
Section 7.2.2.2: Satisfiability Exercise 402. [ 18 ] [18] If $z$ has the $n$-ary representation $x^1 2^2 \cdots z^{d-1}$, encode the further condition that $x$ is (a) even; (b) odd. Verified: no Solve time: 4m08s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$....
TAOCP 7.2.2.2 Exercise 401
Section 7.2.2.2: Satisfiability Exercise 401. [ 16 ] [16] If $z$ has the unary representation $z^1 z^2 \ldots z^{d-1}$, what is the unary representation of (a) $y = \lfloor z/2 \rfloor$? (b) $z = \lfloor (x+1)/3 \rfloor$? Verified: no Solve time: 4m10s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le...
TAOCP 7.2.2.2 Exercise 400
Section 7.2.2.2: Satisfiability Exercise 400. [ 25 ] [25] Experiment with preclusion clauses versus support clauses by applying them to the $n$ queens problem. Use Algorithms L, C, and W for comparison. Verified: no Solve time: 4m40s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has...
TAOCP 7.2.2.2 Exercise 40
Section 7.2.2.2: Satisfiability Exercise 40. [ 01 ] $[01]$ Is the factorization problem (22) unsatisfiable whenever $x$ is a prime number? Verified: no Solve time: 4m Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each...
TAOCP 7.2.2.2 Exercise 399
Section 7.2.2.2: Satisfiability Exercise 399. [ 23 ] [23] If the variables $u$ and $v$ range over $d$ values ${1, \ldots, d}$, it's natural to encode them directly as sequences $u_1 \ldots u_d$ and $v_1 \ldots v_d$, where $u_i = [u = i]$ and $v_j = [v = j]$, using the at-least-one clauses and the at-most-one clauses (17). A binary constraint tells us which pairs $(i, j)$ are legal; for...
TAOCP 7.2.2.2 Exercise 398
Section 7.2.2.2: Satisfiability Exercise 398. [ 18 ] [18] Continuing exercise 397 , what's an appropriate way to enforce the all-different constraint when $x_0, \ldots, x_{p-1}$ are represented in the direct encoding? Verified: no Solve time: 9m43s Solution In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write $$ x_{i,j}=1\iff x_i=j, $$ where $0\le i<p$ and $1\le j\le d$ if the domain has...
TAOCP 7.2.2.2 Exercise 397
Section 7.2.2.2: Satisfiability Exercise 397. [ 22 ] [22] (N. Tamura, 2014.) Suppose $x_0, x_1, \ldots, x_{p-1}$ are integer variables with the range $0 \le x_i < d$, represented in order encoding by Boolean variables $x_i^j = [x_i \ge j]$ for $0 \le i < p$ and $1 \le j < d$. Show that the all-different constraint, "$x_i \ne x_j$ for $0 \le i < j < p$," can be...
TAOCP 7.2.2.2 Exercise 396
Section 7.2.2.2: Satisfiability Exercise 396. ▶ [ 23 ] [23] (Double clique hints.) If $x$ has one of the $d$ values ${0, 1, \ldots, d-1}$, we can represent it binarywise with respect to two different orderings by letting $x^i = [x \ge j]$ and $\bar{x}^i = [x \ge j]$ for $1 \le j < d$, where $\pi$ is any given permutation. For example, if $d = 4$ and $(0\pi, 1\pi,...
TAOCP 7.2.2.2 Exercise 395
Section 7.2.2.2: Satisfiability Exercise 395. [ 20 ] [20] What clauses should replace (15), (16), and (17) if we want to use the order encoding for a graph coloring problem? Verified: no Solve time: 9m10s Correctness The solution addresses the intended topic, namely replacing the direct graph coloring clauses with clauses for the order encoding. It correctly introduces order variables $x_{v,i}$ with the intended meaning that vertex $v$ has color...
TAOCP 7.2.2.2 Exercise 394
Section 7.2.2.2: Satisfiability Exercise 394. [ 25 ] [25] One way to encode the at-most-one constraint $S_1(y_1 \ldots y_p)$ is to introduce $l = \lfloor \lg p \rfloor$ auxiliary variables together with the following $nd + n - 2^l$ clauses, which essentially "broadcast" the value of $j$ when $y_j$ becomes true: $$(\bar{y}_j \vee (-1)^{b_t} a_t) \quad \text{for } 1 \le j \le p,\ 1 \le t \le q = \lfloor...
TAOCP 7.2.2.2 Exercise 393
Section 7.2.2.2: Satisfiability Exercise 393. [ 25 ] [25] (T. R. Dawson, 1911.) Show that it's possible for each white piece in the accompanying chess diagram to capture the corresponding black piece, via a path that doesn't intersect any of the other paths. How can SAT help to solve this problem? Verified: no Solve time: 3m54s Solution Write the binary representations as $$ x=(x_{l-1}\ldots x_0) 2,\qquad y=(y {l-1}\ldots y_0)_2 ....
TAOCP 7.2.2.2 Exercise 392
Section 7.2.2.2: Satisfiability Exercise 392. [ 22 ] [22] The blank spaces in the following diagrams can be filled with letters in such a way that all occurrences of the same letter are rookwise connected: a) Demonstrate how to do it. (Puzzle $(i)$ is easy; the others less so.) b) Similarly, solve the following puzzles, but use kingwise connectedness instead. c) Construct clauses with which a SAT solver can solve...
TAOCP 7.2.2.2 Exercise 391
Section 7.2.2.2: Satisfiability Exercise 391. [ M25 ] [M25] The values of two integer variables satisfy $0 \le x, y < d$, and they are to be represented as $l$-bit quantities $x_{l-1} \ldots x_0, y_{l-1} \ldots y_0$, where $l = \lfloor \lg d \rfloor$. Specify three different ways to encode the relation $x \ne y$: a) Let $x = (x_{l-1} \ldots x_0) 2$ and $y = (y {l-1} \ldots y_0)...
TAOCP 7.2.2.2 Exercise 390
Section 7.2.2.2: Satisfiability Exercise 390. [ 23 ] Let $G$ be a graph with vertices $V$, edges $E$, $|E| = m$, $|V| = n$, and $s, t \in V$. a) Construct $O(kn)$ clauses that are satisfiable if and only if there's a path of length $k$ or less from $s$ to $t$, given $k$. b) Construct $O(m)$ clauses that are satisfiable if and only if there's at least one path...
TAOCP 7.2.2.2 Exercise 39
Section 7.2.2.2: Satisfiability Exercise 39. [ M46 ] $[M46]$ Find an optimum radio coloring of the $n$-cube, for some value of $n > 6$. Verified: no Solve time: 3m56s Solution The definition of embedding gives a direct way to express several graph problems. If $H$ is embedded in $G$, every vertex of $H$ is assigned to a distinct vertex of $G$, and every edge of $H$ must be mapped to...
TAOCP 7.2.2.2 Exercise 389
Section 7.2.2.2: Satisfiability Exercise 389. [ 22 ] In this $4 \times 4$ diagram, it's possible to trace out the phrase 'THE_ART_OF_COMPUTER_PROGRAMMING' by making only king moves and knight moves, except for the final step from R to G. Rearrange the letters so that the entire phrase can be traced. T N T E F H I R . . U P O A . N M C G ....
TAOCP 7.2.2.2 Exercise 388
Section 7.2.2.2: Satisfiability Exercise 388. [ 20 ] Show that the problems of deciding whether or not a given graph $G$ (a) contains a $k$-clique, (b) can be $k$-colored, or (c) has a Hamiltonian cycle can all be regarded as graph embedding problems. Verified: no Solve time: 3m08s Solution The definition of embedding gives a direct way to express several graph problems. If $H$ is embedded in $G$, every vertex...
TAOCP 7.2.2.2 Exercise 387
Section 7.2.2.2: Satisfiability Exercise 387. [ 21 ] Graph $G$ is said to be embedded in graph $G'$ if every vertex $v$ of $G$ corresponds to a distinct vertex $v'$ of $G'$, where $u' - v'$ in $G'$ whenever $u - v$ in $G$. Explain how to construct clauses that are satisfiable if and only if $G$ can be embedded in $G'$. Verified: no Solve time: 4m58s Solution Let $G=(V,E)$...
TAOCP 7.2.2.2 Exercise 386
Section 7.2.2.2: Satisfiability Exercise 386. ▶ [ M25 ] Let Algorithm $C_0$ be a variant of Algorithm $C$ that (i) makes all decisions at random; (ii) never forgets a learned clause; and (iii) restarts whenever a new clause has been learned. (Thus, step C5 ignores $M_0$ and $M_1$; step C6 chooses $l$ uniformly at random from among the $2(n-F)$ currently unassigned literals; step C8 backjumps while $F > t_1$, instead...
TAOCP 7.2.2.2 Exercise 385
Section 7.2.2.2: Satisfiability Exercise 385. [**] Clause $C$ is called certifiable for $F$ if $F \wedge C \vdash_1 c$, as in (119). It is said to be absorbed by $F$ if it is nonempty and $F \wedge C \vdash_1 l$ for every $l \in C$, or if it is empty and $F \vdash_1 \epsilon$. (Every clause of $F$ is obviously absorbed by $F$.) a) True or false: If $C$ is...
TAOCP 7.2.2.2 Exercise 384
Section 7.2.2.2: Satisfiability Exercise 384. [ 25 ] [25] Continuing the previous exercise, show that we can always safely forget any clause $C$ that contains a literal $l$ for which $C \circ C'$ is certifiable for $\Phi \setminus C$ whenever $C' \in \Phi$ contains $\bar{l}$. What erp rule is appropriate? Verified: no Solve time: 3m19s Solution Let $C$ be a clause in $\Phi$, and suppose that $C$ contains a literal...
TAOCP 7.2.2.2 Exercise 383
Section 7.2.2.2: Satisfiability Exercise 383. ▶ [ 23 ] [23] ( Inprocessing .) A SAT solver can partition its database of current clauses into two parts, the "hard" clauses $\Phi$ and the "soft" clauses $\Psi$. Initially $\Psi$ is empty, while $\Phi$ is $F$, the set of all input clauses. Four kinds of changes are subsequently allowed: Learning. We can append a new soft clause $C$, provided that $\Phi \cup \Psi...
TAOCP 7.2.2.2 Exercise 382
Section 7.2.2.2: Satisfiability Exercise 382. [ 30 ] [30] Although the techniques in the preceding exercises are computationally difficult to apply, show that a lookahead forest based on the dependency digraph can be used to discover some of those simplifications efficiently. Verified: no Solve time: 3m50s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the...
TAOCP 7.2.2.2 Exercise 381
Section 7.2.2.2: Satisfiability Exercise 381. [ 22 ] [22] Combining exercises 379 and 380 , show that any one of the clauses in $$(\bar{x}_1 \vee x_2) \wedge (\bar{x} 2 \vee x_3) \wedge \cdots \wedge (\bar{x} {n-1} \vee x_n) \wedge (\bar{x}_n \vee x_1)$$ can be removed if there are no other clauses with negative literals. State the erp rules. Verified: no Solve time: 3m58s Solution The information provided is not sufficient...
TAOCP 7.2.2.2 Exercise 380
Section 7.2.2.2: Satisfiability Exercise 380. [ 21 ] Sometimes we can use self-subsumption backwards, for example by weakening the clause $(l_1 \vee l_2 \vee l_k)$ to $(l_1 \vee \cdots \vee l_j)$ if each intermediate replacement of $(l_1 \vee \cdots \vee l_j)$ by $(l_1 \vee \cdots \vee l_{j-1})$ is justifiable for $3 < j \le k$. Then, if we're lucky, the clause $(l_1 \vee \cdots \vee l_j)$ is weak enough to...
TAOCP 7.2.2.2 Exercise 38
Section 7.2.2.2: Satisfiability Exercise 38. [ M25 ] $[M25]$ How many consecutive colors are needed for a radio coloring of (a) the $n \times n$ square grid $P_n \square P_n$? (b) the vertices ${x \mid x_0 \mid z \mid x, y \ge 0, x + y + z = n}$, which form a triangular grid with $n+1$ vertices on each side. Verified: no Solve time: 3m45s Solution The information provided...
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: 3m45s Solution The information provided is not sufficient...
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: 3m53s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends...
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: 3m57s Solution The information provided is not sufficient to...
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: 3m46s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of...
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: 3m46s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$...
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: 3m50s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$...
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: 4m03s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$ in the surrounding text. The supplied section...
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: no Solve time: 3m52s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the...
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: no Solve time: 3m55s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$ in the surrounding text. The supplied section excerpt ends before...
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: no Solve time: 3m56s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$ in the surrounding text. The supplied section excerpt...
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: no Solve time: 3m47s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable...
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: no Solve time: 3m46s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a variable $v$, and the parameter $r$ in the surrounding text. The supplied section excerpt...
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: no Solve time: 3m50s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of...
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: no Solve time: 3m46s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$,...
TAOCP 7.2.2.2 Exercise 36
Section 7.2.2.2: Satisfiability Exercise 36. ▶ [**] $[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: no Solve time: 3m56s Solution The information provided is not sufficient to derive the requested formulas. Exercise 7.2.2.2.357 depends on equation (155) and on the definition of the quantities $\pi_0$, $\pi_s$, the “field” of a...
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: no Solve time: 3m Connection interrupted. Waiting for the complete answer
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: no Solve time: 8m40s
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: no Solve time: 3m44s Solution Let $E_j$ denote the expected number of executions of the resampling step associated with the bad event $A_j$, as in (152). The standard witness-tree expression for this expectation is $$ E_j=\sum_{\tau\in\mathcal{T}_j} w(\tau),...
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: no Solve time: 3m47s Solution Let $E_j$ denote the expected number of executions of the resampling step associated with the bad event $A_j$, as in (152). The standard witness-tree expression for this expectation is $$ E_j=\sum_{\tau\in\mathcal{T}_j} w(\tau), $$ where $\mathcal{T}_j$ is the family of proper...
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: no Solve time: 10m35s Solution Let $E_j$ denote the expected number of executions of the resampling step associated with the bad event $A_j$, as in (152). The standard witness-tree expression for this expectation is $$ E_j=\sum_{\tau\in\mathcal{T}_j} w(\tau), $$ where $\mathcal{T}_j$ is the family of proper witness trees whose...
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: no Solve time: 3m42s Setup Let $G$ be a graph with vertices numbered by the ancestor relation $\succ$ in a forest. A graph is tree-ordered...
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: no Solve time: 3m43s Solution A double coloring of a graph assigns a 2-element subset of a color set to each vertex, with adjacent vertices receiving disjoint subsets. A triple coloring is defined similarly with 3-element subsets. For a cycle, the color sets must therefore form a closed walk...
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: no Solve time: 3m47s Solution A double coloring of a graph assigns a 2-element subset of a color set to each vertex, with adjacent vertices receiving...
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: 2m37s Solution Let $\mathcal A$ be the alphabet of the trace monoid, and let $\operatorname{src}(\alpha)$ denote the set of sources of the trace $\alpha$. For a set of letters $S\subseteq\mathcal A$, define $$ T_S=\sum_{\operatorname{src}(\alpha)\subseteq S}\alpha , $$ where the sum extends over all traces whose sources are contained in...
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: 3m46s Solution A double coloring of a graph assigns a 2-element subset of...
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: 3m48s Solution A double coloring of a graph assigns a 2-element subset of a color set to each vertex, with adjacent vertices receiving disjoint subsets. A...
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 334
Section 7.2.2.2: Satisfiability Exercise 334. [ 25 ] [25] Design an algorithm to generate all traces of length $n$ that correspond to a graph on the alphabet ${1, \ldots, m}$, representing each trace by its lexicographically smallest string. Verified: no Solve time: 3m49s Solution A double coloring of a graph assigns a 2-element subset of a color set to each vertex, with adjacent vertices receiving disjoint subsets. A triple coloring...
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: 3m53s Solution A double coloring of a graph assigns a 2-element subset of a color set to each vertex, with adjacent vertices receiving disjoint subsets. A triple coloring is defined similarly with 3-element subsets. For a...
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: 3m48s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not imply the statement of Theorem J. Theorem J gives a bound under the specific...
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: 3m48s Solution No. Theorem J and Theorem L concern different probability...
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: 3m44s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W,...
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: 3m47s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not imply the statement of Theorem J. Theorem J gives a bound under the specific assumption...
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: 3m47s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not...
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: 3m51s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not imply the statement of Theorem J. Theorem J gives a bound under the specific assumption that the current assignment is at Hamming distance $d$ from a...
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: 3m55s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not imply the statement of Theorem J....
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: 4m04s Solution No. Theorem J and Theorem L concern different probability estimates for Algorithm W, and the hypotheses of Theorem L do not imply the statement of Theorem J. Theorem J gives a bound under the specific assumption that the current assignment is at Hamming distance $d$ from a...
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: no Solve time: 4m44s Solution No. Theorem J and Theorem L...
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: 16m
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: no Solve time: 10m12s Correctness The proposed solution does not answer Exercise 7.2.2.2.313. The exercise asks for a proof about Algorithm W. Specifically, it asks to show two facts about a cost-free literal flip in clause $C_j$: Flipping such a literal always decreases the number of unsatisfied clauses,...
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: 11m23s Correctness The proposed solution does not answer Exercise 7.2.2.2.313. The exercise asks for a proof about Algorithm W. Specifically, it asks to show two facts about a cost-free literal...
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: 11m43s Correctness The proposed solution does not answer Exercise 7.2.2.2.313. The exercise asks for...
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: 3m51s Solution The quantity $F_t(r)$ can be found by turning the defining condition into a family of satisfiability problems. For fixed $t$ and $r$, introduce Boolean...
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 31
Section 7.2.2.2: Satisfiability Exercise 31. [ 28 ] [28] Let $F_1(r)$ be the smallest $n$ for which there is a bit vector $x_1 \ldots x_n$ with $x_1 + \cdots + x_n = r$ and with no $t$ equally spaced 1s. For example, $F_3(12) = 30$ because of the unique solution 101100011010000000010110001101. Discuss how $F_t(n)$ might be computed efficiently with the help of a SAT solver. Verified: no Solve time: 10m20s...
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: 11m23s Correctness The proposed solution does not answer Exercise 7.2.2.2.305. The exercise asks for an extension of the previous exercise involving Algorithm W and generating functions. Specifically, it asks to add the clause $(\bar{x}_1 \vee \bar{x}_2)$, compute the...
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 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: 10m30s Correctness The proposed solution does not answer Exercise 7.2.2.2.305. The exercise asks for an extension of the previous exercise involving Algorithm W and generating functions. Specifically,...
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: 3m56s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. 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: 3m55s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement...
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: 3m48s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals,...
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: 3m47s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement...
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: 3m47s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and...
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: 3m48s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement belongs...
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: 3m51s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals,...
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: 3m59s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and...
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: 3m53s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one...
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: 3m58s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$...
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: 3m47s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement belongs to...
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: 3m45s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one...
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: 3m52s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of...
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: 4m01s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set...
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: 3m54s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction...
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: 3m59s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals,...
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: 3m52s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every...
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: 3m54s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals....
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: 3m51s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement belongs...
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: no Solve time: 3m52s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to...
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: no Solve time: 3m51s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose...
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: 4m02s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting every clause that contains one of these literals, and deleting from the remaining clauses every literal whose complement belongs...
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: 3m55s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$ to true, deleting...
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: no Solve time: 3m44s Solution The statement is true. Let $L={l_1,\ldots,l_r}$ be a set of strictly distinct literals. The restriction $F|L$ is obtained by setting every literal in $L$...
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: 8m06s Solution Let $C_{i-1}$ denote the clause currently at the end of MEM when the new learned clause $C_i$ has been produced. The only possible replacement is $$ C_{i-1}\leftarrow C_i, $$ and this replacement...
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: 13m42s Correctness The proposed solution does not answer Exercise 7.2.2.2.266. The exercise asks how a random decision policy in a CDCL SAT solver changes step C6 of the CDCL...
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: 13m08s Correctness The proposed solution does not answer Exercise 7.2.2.2.266. The exercise asks how...
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: 5m53s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the...
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: 5m51s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$...
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: 5m54s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be...
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: 5m50s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has seven literals,...
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: no Solve time: 6m09s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad...
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: 5m55s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$...
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: no Solve time: 5m56s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause...
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: 6m16s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are...
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: 5m56s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has seven...
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: 5m53s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from...
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: 5m55s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to...
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: 7m15s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since...
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: 5m59s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are...
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: 6m05s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the...
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: 5m56s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen...
TAOCP 7.2.2.2 Exercise 25
Section 7.2.2.2: Satisfiability Exercise 25. [ 21 ] [21] Show that (18)–(19) and (20)–(21) are equally effective when $r = 2$. Verified: no Solve time: 5m55s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has...
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: 5m51s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has seven literals, $$...
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: 6m01s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$...
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: 6m04s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from...
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: no Solve time: 5m58s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be 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: 5m59s Setup Let $F$...
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: 5m58s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are...
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: 6m11s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since...
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: 5m48s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to...
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: 6m04s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has seven literals,...
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: 5m58s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false. Since $C$ has seven literals, $$...
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: 6m01s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event...
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: no Solve time: 5m59s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are false....
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: 5m49s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals of $C$ are...
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: 6m01s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$....
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: 5m50s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to...
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: 5m47s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals...
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: 5m50s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define...
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: 5m44s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to...
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: 5m59s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly...
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: 5m57s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently...
TAOCP 7.2.2.2 Exercise 223
Section 7.2.2.2: Satisfiability Exercise 223. [ HM40 ] [HM40] Step X9 deduces a binary clause that cannot be derived by resolution (see exercise 166). Prove that, nevertheless, the running time of Algorithm L on unsatisfiable input will never be less than the length of a shortest treelike refutation. Verified: no Solve time: 5m49s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly...
TAOCP 7.2.2.2 Exercise 222
Section 7.2.2.2: Satisfiability Exercise 222. [ M30 ] [M30] (Oliver Kullmann, 2000.) Prove that, for every clause $C$ in a satisfiability problem $F$, there is an autarky satisfying $C$ if and only if $C$ cannot be used as the label of a source vertex in any resolution refutation of $F$. Verified: no Solve time: 5m53s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently...
TAOCP 7.2.2.2 Exercise 221
Section 7.2.2.2: Satisfiability Exercise 221. [ 16 ] [16] Draw the search tree analogous to Fig. 38 that is implicitly traversed when Algorithm A is applied to the unsatisfiable clauses ${12, 2, \bar{2}}$. Explain why it does not correspond to a resolution refutation that is analogous to Fig. 48. Verified: no Solve time: 5m52s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and...
TAOCP 7.2.2.2 Exercise 220
Section 7.2.2.2: Satisfiability Exercise 220. [ M24 ] [M24] We say that clause $C$ subsumes clause $C'$, written $C \subseteq C'$, if $C' = \bar{\varphi}$ or if $C' \ne \bar{\varphi}$ and every literal of $C$ appears in $C'$. a) True or false: $C \subseteq C'$ and $C' \subseteq C''$ implies $C \subseteq C''$. b) True or false: $(C \vee a) \diamond (C'' \vee \bar{a}) \subseteq (C \diamond C'') \vee a...
TAOCP 7.2.2.2 Exercise 22
Section 7.2.2.2: Satisfiability Exercise 22. [ 20 ] [20] Color the graph $\overline{C_5} \boxtimes \overline{C_5}$ with the fewest colors. (Two vertices of this graph can receive the same color if and only if they are a king move apart in a $5 \times 5$ torus.) Verified: no Solve time: 7m23s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For...
TAOCP 7.2.2.2 Exercise 219
Section 7.2.2.2: Satisfiability Exercise 219. ▶ [ M20 ] [M20] Formulate a general definition of the resolution operator $C = C' \diamond C''$ that (i) agrees with the earlier definition when $C' = \bar{x} \vee A'$ and $C'' = \bar{x} \vee A''$; (ii) applies to arbitrary clauses $C'$ and $C''$; (iii) has the property that $C' \wedge C''$ implies $C' \diamond C''$. Verified: no Solve time: 5m57s Setup Let $F$...
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: 5m58s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$ of $F$, define the bad event $A_C$ to be the event that all literals...
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: no Solve time: 5m58s Setup Let $F$ be a...
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: 5m57s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently...
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: 6m02s Setup Let $F$ be a 7SAT instance. Let the variables of $F$ be chosen independently and uniformly from ${0,1}$. For each clause $C$...
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: 5m48s I cannot produce a rigorous completed solution for this exercise from the information currently available. The obstacle is part (b). The exercise asks for a specific construction of a set of 16 unsatisfiable ternary clauses on 15 variables, and part (c)...
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: 6m10s I cannot produce a rigorous completed solution for this exercise from...
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: 8m21s I cannot produce a rigorous completed solution for this exercise from the information currently available. The obstacle is part (b). The exercise asks for a specific construction of a set...
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: 7m41s Working
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: 5m52s The previous text does not contain a proposed solution to...
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: no Solve time: 6m The previous text does not contain a proposed solution to Exercise 7.2.2.2.204. It contains a proposed solution and reviews for Exercise 7.2.2.2.203, which is a different problem about Model RB random satisfiability....
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: 5m51s Correctness The proposed solution does not answer the stated exercise. Exercise 7.2.2.2.202 asks about the proof of Theorem C, specifically...
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: 5m54s Correctness The proposed solution identifies the correct reformulation of the problem. A Boolean function...
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: 6m04s Correctness The proposed solution identifies the correct reformulation of the problem. A Boolean function on four variables is representable in $3$CNF exactly when its set of falsifying assignments is a union of subcubes of dimension at least $1$. The conversion between clauses and unions...
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: 5m37s Correctness The proposed solution identifies the correct reformulation of the problem. A Boolean function on four variables is representable in $3$CNF...
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: no Solve time: 5m13s Correctness The proposed solution identifies the correct reformulation of the problem. A Boolean function on four variables is representable in $3$CNF exactly when its set of falsifying assignments is a...
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: no Solve time: 5m33s Correctness The proposed solution identifies the correct reformulation of the...
TAOCP 7.2.2.1 Exercise 91
Section 7.2.2.1: Dancing Links Exercise 91. [ 40 ] [40] For given $W$, find the largest $p$ such that $\text{WORDS}(W)$ supports a word stair of period $p$. [There are two questions for each $W$, examining stairs to the left, right.] Verified: no Solve time: 3m53s Solution A Boolean function on variables $x_1,\ldots,x_4$ is represented by a $3$CNF formula exactly when its set of falsifying assignments is a union of subcubes...
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: no Solve time: 2m02s Solution A Boolean function on variables $x_1,\ldots,x_4$ is represented by a $3$CNF formula exactly when its set of falsifying assignments is a union of subcubes of dimension at...
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: 1m54s Solution A Boolean function on variables $x_1,\ldots,x_4$ is represented by a $3$CNF formula exactly when its set of falsifying assignments is a union of subcubes of dimension at least $1$ in the...
TAOCP 7.2.2.1 Exercise 362
Section 7.2.2.1: Dancing Links Exercise 362. [ 10 ] $[10]$ A reduced pattern is called strictly reduced if each of its subrectangles $[a \ldots b) \times [c \ldots d)$ has $(a, b) \ne (0, m)$ and $(c, d) \ne (0, n)$, in other words, if no subrectangle "cuts all the way across." Modify the construction of exercise 360 so that it produces only strictly reduced solutions. How many $3 \times...
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: 2m07s Solution A Boolean function on variables $x_1,\ldots,x_4$ is represented by a $3$CNF formula exactly when its set of falsifying assignments is a union of subcubes of dimension at least $1$ in the $4$-dimensional Boolean cube. A clause with three literals is false on an...
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: no Solve time: 5m51s Correctness The proposed solution does not answer the stated exercise. Exercise 7.2.2.2.489 asks for a recurrence for $T_n$, the number of signed involutions on $n$ elements. The proposed solution instead...
TAOCP 7.2.2.1 Exercise 359
Section 7.2.2.1: Dancing Links Exercise 359. [ 29 ] $[29]$ Nick Baxter devised an innocuous-looking but maddeningly difficult "Square Dissection" puzzle for the International Puzzle Party in 2014, asking that the nine pieces be placed flat into a $65 \times 65$ square. One quickly checks that $17 \times 20 + 18 \times 20 + \cdots + 24 \times 25 = 65^2$; yet nothing seems to work! Solve his puzzle with...
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: 5m30s Correctness The proposed solution does not answer the stated exercise. Exercise 7.2.2.2.489 asks for a recurrence for $T_n$, the number of signed involutions on $n$ elements. The proposed solution instead...
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: 3m50s Solution Let $B_m$ denote the reduced ordered binary decision diagram obtained after conjoining $m$ distinct random $k$SAT clauses on $n=50$ variables. The quantity of interest is the number of...
TAOCP 7.2.2.1 Exercise 351
Section 7.2.2.1: Dancing Links Exercise 351. [ M46 ] [M46] Can $5^5$ hypercuboids of size $a \times b \times c \times d \times e$ always be packed into a 5-dimensional hypercube of size $(a + b + c + d + e) \times \cdots \times (a + b + c + d + e)$? Verified: no Solve time: 10m16s Correctness The proposed solution does not answer the stated exercise. Exercise...
TAOCP 7.2.1.2 Exercise 60
Section 7.2.1.2: Generating All Permutations Exercise 60. ▶ [ 21 ] [21] A Gray cycle for permutations is a cycle (π0, π1, . . . , πn!−1) that includes every permutation of {1, 2, . . . , n} and has the property that πk differs from π(k+1) mod n! by an adjacent transposition. It can also be described as a Hamiltonian cycle on the Cayley graph for the group...
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 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...