TAOCP 7.1.4 Exercise 62
Algorithm D in Section 7.
Section 7.1.4: Binary Decision Diagrams
Exercise 62. ▶ [M21] [M21] If f(x) = ⌊n/2⌋ j=1 (x2j−1 ∧x2j) and g(x) = (x1 ∧xn)∨⌈n/2⌉−1 j=1 (x2j ∧x2j+1), what are the asymptotic values of B(f), B(g), B(f ⋄g), and B(f ∨g) as n →∞?
Verified: no
Solve time: 6m33s
Solution
Algorithm D in Section 7.2.1.1 is the standard coroutine-based construction that interleaves two cyclic generators $f$ and $f'$, each producing an $m$-ary de Bruijn cycle, and uses a control parameter $r$ to determine how many symbols are taken from one coroutine before switching to the other. The output is a cyclic sequence obtained by concatenating controlled segments of the two streams.
The coroutines are given as trivial cycles
$01234,01234,01234\ldots$
so both $f$ and $f'$ output the same infinite periodic word of period $5$.
Since $m=5$ and $n=1$, each coroutine produces symbols in $\mathbb{Z}_5$, and the state space of Algorithm D reduces to tracking only the current output symbol of each coroutine and the switching mechanism governed by $r=3$.
Let the output stream of both $f$ and $f'$ be denoted
$s = 0,1,2,3,4,0,1,2,3,4,\ldots.$
Algorithm D alternates between the two identical streams. Since the streams are identical, the only effect of interleaving is a fixed shift in phase between the two copies of $s$.
The parameter $r=3$ determines that three consecutive symbols are taken from one coroutine before switching. After initialization, suppose $f$ is advanced by one full cycle prefix relative to $f'$, which is consistent with the standard setup in Algorithm D where the second coroutine begins after a delay determined by $r$.
Thus the output is obtained by merging
$f = s$
and
$f' = s$
with a relative phase shift of $3$ positions modulo $5$.
Shifting $s$ by $3$ positions yields
$s^{(3)} = 3,4,0,1,2,3,4,0,1,2,\ldots.$
Interleaving $s$ and $s^{(3)}$ under the rule of Algorithm D produces a sequence in which each step takes the next symbol from the active coroutine and then switches after $r=3$ symbols. Since both streams are periodic and identical up to shift, the combined output stabilizes into a single periodic cycle whose period is the least common multiple of the underlying cycle length $5$ and the induced shift structure, hence period $5$.
To determine the actual cycle, it suffices to compute the first five output symbols. Start with $f$:
First three outputs from $f$ are
$0,1,2.$
Switch to $f'$ at the same phase position, which corresponds to the shifted stream starting at $3$. The next three symbols from $f'$ are
$3,4,0.$
Switch back to $f$, continuing its stream, producing
$3,4,0,\ldots$ aligned with the cyclic continuation.
After one full traversal of all distinct residues mod $5$, the process closes the cycle.
Thus the produced de Bruijn-type cycle is the same cyclic word as the underlying generator:
$01234.$
Since Algorithm D outputs a cyclic sequence of length $m^n = 5$, the full output is the repetition of this base cycle:
$01234,01234,01234\ldots.$
Expressed as a cycle, the result is
$\boxed{01234}.$