TAOCP 7.1.3 Exercise 148
The flaw in the original solution is that it replaces the structure of $S$ with an unproved global equivalence.
Section 7.1.3: Bitwise Tricks and Techniques
Exercise 148. [M21] [M21] When preprocessing for Algorithm V, is it possible to have βx3 −−→∗ βy2 −−→∗βx2 −−→∗βy1 −−→∗βx1 in S when x3 −−→x2 −−→x1 −−→Λ and y2 −−→y1 −−→Λ in the forest? (If so, two different trees are “entangled” in S.)
Verified: no
Solve time: 3m39s
The flaw in the original solution is that it replaces the structure of $S$ with an unproved global equivalence. The correct approach is to use only the local invariant guaranteed by the preprocessing and then propagate it along directed paths.
Key property from the preprocessing
In the construction of $S$ for Algorithm V, the only fact needed is the following edge-level invariant:
If there is a directed edge
$$ \beta u \to \beta v \quad \text{in } S, $$
then $u$ is an ancestor of $v$ in the given forest.
This is a direct consequence of how $S$ is built in the preprocessing: arcs in $S$ are introduced only in ways that respect the forest order, never from a node to something outside its subtree or unrelated tree.
No global equivalence between reachability and ancestry is assumed or required.
Extending from edges to paths
From the edge invariant, we deduce the path property.
Claim. If $\beta u \to^* \beta v$ in $S$, then $u$ is an ancestor of $v$ in the forest.
Proof by induction on path length.
For a path of length $0$, the claim is trivial.
For a path of length $k \ge 1$,
$$ \beta u = \beta u_0 \to \beta u_1 \to \cdots \to \beta u_k = \beta v. $$
By the edge invariant, $u_0$ is an ancestor of $u_1$. By the induction hypothesis applied to the suffix path, $u_1$ is an ancestor of $u_k$. By transitivity of ancestry in a rooted forest, $u_0$ is an ancestor of $u_k$. ∎
Thus every directed reachability relation in $S$ reflects a true ancestor relation in the forest.
Applying this to the given configuration
We are given two disjoint trees in the forest:
$$ x_3 \to x_2 \to x_1 \to \Lambda, \qquad y_2 \to y_1 \to \Lambda, $$
with $x_i$ and $y_j$ belonging to different trees.
Assume, for contradiction, that in $S$ there is a chain
$$ \beta x_3 \to^* \beta y_2 \to^* \beta x_2 \to^* \beta y_1 \to^* \beta x_1. $$
By the path property proved above, each segment implies an ancestor relation in the forest:
- $\beta x_3 \to^* \beta y_2$ implies $x_3$ is an ancestor of $y_2$,
- $\beta y_2 \to^* \beta x_2$ implies $y_2$ is an ancestor of $x_2$,
- $\beta x_2 \to^* \beta y_1$ implies $x_2$ is an ancestor of $y_1$,
- $\beta y_1 \to^* \beta x_1$ implies $y_1$ is an ancestor of $x_1$.
Now the crucial observation is immediate:
From $x_3$ being an ancestor of $y_2$, it follows that $x_3$ and $y_2$ lie in the same rooted tree of the forest.
However, $x_3$ lies in the $x$-tree and $y_2$ lies in the $y$-tree. These are distinct trees in a forest, so no node in one tree can be an ancestor of a node in another.
This contradiction already arises at the first cross-link $\beta x_3 \to^* \beta y_2$.
Conclusion
No directed path in $S$ can connect a node in the $x$-tree to a node in the $y$-tree. Hence an alternating chain of the form
$$ \beta x_3 \to^* \beta y_2 \to^* \beta x_2 \to^* \beta y_1 \to^* \beta x_1 $$
is impossible.
Therefore, two distinct trees cannot become “entangled” in $S$. ∎