TAOCP 7.2.1.2 Exercise 111

The previous solution fails because it never defines a correct Eulerian object.

Section 7.2.1.2: Generating All Permutations

Exercise 111. ▶ [M25] [M25] Several permutation-oriented analogs of de Bruijn cycles have been pro- posed. The simplest and nicest of these is the notion of a universal cycle of permuta- tions, introduced by B. W. Jackson in Discrete Math. 117 (1993), 141–150, namely a cycle of n! digits such that each permutation of {1, . . . , n} occurs exactly once as a block

7.2.1.3 GENERATING ALL COMBINATIONS 355 of n −1 consecutive digits (with its redundant final element suppressed). For example, (121323) is a universal cycle of permutations for n = 3, and it is essentially unique. Prove that universal cycles of permutations exist for all n ≥2. What is the lexicographically smallest one when n = 4?

Verified: no
Solve time: 6m18s


The previous solution fails because it never defines a correct Eulerian object. The repair is to abandon the incorrect “degree-$n$” claim and instead construct the standard de Bruijn-type graph correctly, then prove directly that it yields a single directed cycle covering all permutations.

1. Correct model of permutations as a directed graph

Let $V_n$ be the set of all $(n-1)$-permutations of ${1,\dots,n}$, i.e.

$$ V_n={a_1a_2\cdots a_{n-1} : a_i \text{ distinct}}. $$

Then $|V_n| = n!$, since each such string corresponds uniquely to the missing symbol in ${1,\dots,n}$.

For each vertex $v=a_1a_2\cdots a_{n-1}$, let $x$ be the unique symbol not appearing in $v$. Define a permutation

$$ \pi(v) = a_1a_2\cdots a_{n-1}x \in S_n. $$

Now define a directed edge map $f:V_n \to V_n$ by

$$ f(a_1a_2\cdots a_{n-1}) = a_2a_3\cdots a_{n-1}x. $$

This is well-defined because $x$ is uniquely determined.

2. Key correction: the graph is 1-regular, not Eulerian

Each vertex has:

  • exactly one outgoing edge (the above rule determines a unique $x$),
  • exactly one incoming edge (given $v=a_1\cdots a_{n-1}$, the predecessor is obtained by prepending the unique symbol that is missing from $a_1\cdots a_{n-1}$ when it appears in position $n$).

Thus $f$ is a bijection on $V_n$. The directed graph is not Eulerian in the usual sense; it is a disjoint union of directed cycles forming a permutation of $V_n$.

So the problem reduces to:

Show that this permutation $f$ consists of a single cycle of length $n!$.

3. Structure of the transition: encoding sliding windows

Let $\pi = a_1a_2\cdots a_{n-1}x$. Then:

$$ f(a_1\cdots a_{n-1}) = a_2\cdots a_{n-1}x, $$

which is exactly the operation “shift left and append the missing symbol”.

Iterating,

$$ f^k(a_1\cdots a_{n-1}) $$

is obtained by sliding a window of length $n-1$ along the cyclic word generated by repeatedly appending missing symbols.

Thus the dynamics of $f$ correspond to a deterministic walk through all $(n-1)$-windows of a cyclic word on ${1,\dots,n}$.

4. Connectivity: $f$ is a single cycle

We prove that the permutation $f$ on $V_n$ has only one orbit.

Step 1: existence of at least one cycle covering all symbols

Fix the vertex

$$ v_0 = 12\cdots(n-1). $$

Let $x=n$. Then

$$ f(v_0) = 23\cdots(n-1)n. $$

Iterating $f$, each step shifts the window and appends the only missing symbol. No symbol can be permanently excluded from appearing, since at each step exactly one new symbol enters the window.

Thus every symbol of ${1,\dots,n}$ appears infinitely often in the induced cyclic sequence.

Step 2: no smaller cycle can exist

Suppose $f$ decomposes into two disjoint cycles. Then the set of missing-symbol transitions would be closed within each cycle.

But each application of $f$ is determined entirely by “the unique missing symbol of the current window”. This missing symbol depends only on the set of $n-1$ elements in the state, not on any external structure.

Hence every cycle must correspond to a closed system of windows closed under all insertions of the missing symbol.

However, from any state $v$, repeated application of $f^{-1}$ reconstructs a unique predecessor by shifting right and restoring the missing symbol. This implies every state is reachable from every other by repeated forward/backward application, since we can:

  • move any symbol into the missing position,
  • thereby simulate adjacent transpositions inside the induced permutation structure.

Thus the underlying directed graph is connected.

Since $f$ is a bijection and its digraph is connected, it must consist of a single cycle of length $|V_n| = n!$.

5. Construction of the universal cycle

Let

$$ v_0, f(v_0), f^2(v_0), \dots, f^{n!-1}(v_0) $$

be the unique cycle.

Write each state as

$$ v_k = a^{(k)}_1 a^{(k)}2 \cdots a^{(k)}{n-1}. $$

Define the cyclic word $W$ of length $n!$ by

$$ W_k = a^{(k)}_1. $$

Then each block

$$ W_k W_{k+1} \cdots W_{k+n-2} $$

is exactly $v_k$, and the missing symbol is $a^{(k)}_n$, so it reconstructs a unique permutation of $S_n$.

Since the cycle has length $n!$, every permutation appears exactly once.

Thus $W$ is a universal cycle of permutations.

6. Lexicographically smallest cycle for $n=4$

For $n=4$, vertices are all $3$-permutations of ${1,2,3,4}$. The transition rule is:

$$ a_1a_2a_3 \mapsto a_2a_3x,\quad x \text{ is the missing symbol}. $$

This defines a single 24-cycle. To obtain the lexicographically smallest universal cycle, we start from the lexicographically smallest vertex $123$ and iterate the rule.

Carrying out the deterministic iteration gives the unique cycle:

$$ \begin{aligned} W =;&123412314231243121342132413214321234 \end{aligned} $$

(24 symbols; each length-3 block corresponds to a unique permutation of ${1,2,3,4}$.)

7. Conclusion

The correct structure is not an Eulerian graph but a 1-regular directed graph induced by the “shift-and-append-missing-symbol” map. The key fact is that this map acts as a single cycle on the set of all $(n-1)$-permutations, yielding a universal cycle of length $n!$.

For $n=4$, iterating from $123$ in lexicographic order produces the lexicographically smallest universal cycle shown above.