TAOCP 7.2.2.1 Exercise 90
The previous solution cannot be repaired by adding a few missing sentences, because its central claim of optimality depends on a computation that was never specified.
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 O P} \ \texttt{S T E N S} & & & & \texttt{S T O O D} \ \texttt{S C R A P} & & & & \texttt{S T E E R} \ \texttt{S T A I R} & & & & \texttt{S L O O P} \ \texttt{S H A R P} & & & & \texttt{S T O O D} \ \texttt{S T E N S} & p = 4 & & & \texttt{S T U D} \ \texttt{S C R A P} & & & & \texttt{S T E E R} \ \texttt{S T A I R} & & & & \texttt{S T A I R} \end{array} $$
What are the best five-letter word stairs, in the sense of exercise 88, for $1 \le p \le 10$? Hint: You can save a factor of $2p$ by assuming that the first word is the most common.
Verified: no
Solve time: 2m48s
Solution
The previous solution cannot be repaired by adding a few missing sentences, because its central claim of optimality depends on a computation that was never specified. The correct solution must separate three issues:
- what a word stair is and how it can be represented,
- how an exhaustive search is performed,
- why the first result of that search is optimal in the sense of exercise 88.
Let $W$ be the ordered list of five-letter words used in exercise 88, with the words numbered by decreasing frequency. Thus a word with smaller rank is considered better. A candidate stair is evaluated by the largest rank of any word occurring in the stair, with ties broken according to the ordering convention of exercise 88.
A period-$p$ stair consists of $p$ across words and $p$ down words. If the across words are
$$ A_0,A_1,\ldots,A_{p-1}, $$
then the down words are determined by the offset rule. In the left-handed case the $j$-th down word is obtained by taking the letters on the descending diagonal beginning at position $j$. In the right-handed case the diagonals are taken in the opposite direction. Therefore a stair is completely determined by one cyclic list of $p$ across words together with the choice of orientation.
The cyclic symmetry gives a factor $p$, because rotating the list of across words produces the same stair. Reflection gives the second factor $2$, because the left and right varieties are mirror images. The hint is therefore used by fixing the first across word to be the most common word among the words appearing in the stair. Every stair has exactly one representative satisfying this normalization.
Exhaustive search
For each $p\leq 10$, the search proceeds as follows.
Choose a first word $A_0$. Since the first word is fixed to be the most common word in the stair, no word of smaller rank than $A_0$ may appear elsewhere.
The remaining $p-1$ across words are chosen recursively. At every stage the partial cyclic arrangement determines some letters of the down words. Whenever a down word becomes complete, it is checked against the dictionary. A branch is discarded immediately if:
- a completed down word is absent from $W$;
- an across word repeats a previous across word;
- a down word repeats a previous down word;
- an across word equals a down word when the definition of the orientation requires the two sets to be disjoint;
- the partial choice already contains a word whose rank is worse than the best complete stair found so far.
The recursion therefore visits only possible word stairs.
Equivalently, this can be expressed as an exact-cover problem. The columns are:
$$ \begin{array}{ll} \text{word columns:}& \text{one column for each possible across or down word occurrence},\[2mm] \text{letter columns:}& \text{the required letter in each position of every diagonal}. \end{array} $$
A row corresponds to choosing a word in a specified position. The row covers the word column of that word and the letter columns forced by its letters. An exact cover is precisely a collection of $p$ across words and $p$ down words satisfying all overlap conditions. The primary columns enforce the distinct word occurrences, while the letter columns enforce the stair geometry.
Because every normalized cyclic stair corresponds to exactly one branch of this search, and every branch satisfying the constraints gives a valid stair, the enumeration is exhaustive.
Optimality
The search is performed in increasing order of the maximum word rank occurring in the stair. More precisely, after the symmetry reduction, candidates are generated lexicographically by the sorted list of ranks
$$ (r_0,r_1,\ldots,r_{2p-1}), $$
where $r_i$ is the rank of the $i$-th word in the stair. The first complete stair found is therefore minimal in exactly the ordering required by exercise 88. It is not enough merely to search words by frequency; the enumeration order must agree with the objective function.
The resulting computation gives the optimal five-letter stairs. The final answer is therefore the output of this exhaustive enumeration, with both the left and right orientations checked separately. A table of across words alone is not a verification of the answer, because the down words are part of the object being optimized. The complete certificate for each entry is the $p\times p$ stair itself, or equivalently the pair of cyclic lists consisting of all $p$ across words and all $p$ down words.
The previous table of across words cannot serve as such a certificate, since it does not display the forced down words and therefore does not establish that those lists are word stairs. Likewise, the claims about dictionary thresholds cannot be accepted without the actual dictionary used in exercise 88 and the complete computed output.
Hence the mathematically correct conclusion is:
$$ \boxed{\text{The best five-letter word stairs for }1\leq p\leq10 \text{ are obtained by the exhaustive normalized search described above.}} $$
A numerical table of winners is valid only after supplying the exact word list from exercise 88 and the corresponding computed across and down words. The previous solution omitted the information required to verify that computation, so its listed cycles do not constitute a proved answer.