The n-dimensional hypercube \(Q_n\) is the graph that has as vertices all bitstrings of length n, and an edge between any two bitstrings that differ in a single bit. The weight of a vertex x of \(Q_n\) is the number of 1s in x. The kth level of \(Q_n\) is the set of vertices with weight k.

FormalPara Theorem 1

For all \(n\ge 1\), the subgraph of \(Q_{2n+1}\) induced by levels n and \(n+1\) has a Hamilton cycle.

Theorem 1 solves the well-known middle levels conjecture, and it was first proved in [2] (see this paper for a history of the problem). A shorter proof was presented in [1] (12 pages). Here, we present a proof from ‘the book’.

FormalPara Proof

We write \(D_n\) for all Dyck words of length 2n, i.e., bitstrings of length 2n with weight n in which every prefix contains at least as many 1s as 0s. We also define \(D:=\bigcup _{n\ge 0} D_n\). Any \(x\in D_n\) can be decomposed uniquely as \(x=1u0v\) with \(u,v\in D\). Furthermore, Dyck words of length 2n can be identified by ordered rooted trees with n edges as follows; see Fig. 1: Traverse the tree with depth-first search and write a 1-bit for every step away from the root and a 0-bit for every step towards the root. For any bitstring x, we write \(\sigma ^s(x)\) for the cyclic right rotation of x by s steps. We write \(A_n\) and \(B_n\) for the vertices of \(Q_{2n+1}\) in level n or \(n+1\), respectively, and we define \(M_n:=Q_{2n+1}[A_n\cup B_n]\). For any \(x\in D_n\), \(b\in \{0,1\}\) and \(s\in \{0,\ldots ,2n\}\) we define \(\langle x,b,s\rangle :=\sigma ^s(xb)\). Note that we have \(A_n=\{\langle x,0,s\rangle \mid x\in D_n\wedge 0\le s\le 2n\}\) and \(B_n=\{\langle x,1,s\rangle \mid x\in D_n\wedge 0\le s\le 2n\}\). Thus, we think of every vertex of \(M_n\) as a triple \(\langle x,b,s\rangle \), i.e., an ordered rooted tree x with n edges referred to as the nut, a bit \(b\in \{0,1\}\), and an integer \(s\in \{0,\ldots ,2n\}\) referred to as the shift.

The first step is to construct a cycle factor in the graph \(M_n\). For this we define a mapping \(f:A_n\cup B_n\rightarrow A_n\cup B_n\) as follows. Given an ordered rooted tree \(x=1u0v\in D_n\) with \(u,v\in D\), a tree rotation yields the tree \(r(x):=u1v0\in D_n\); see Fig. 2. We define \(f(\langle x,0,s\rangle ):=\langle r(x),1,s+1\rangle \) and \(f(\langle x,1,s\rangle ):=\langle x,0,s\rangle \). It is easy to see that f is a bijection. Indeed, the inverse mapping is \(f^{-1}(\langle x,0,s\rangle )=\langle x,1,s\rangle \) and \(f^{-1}(\langle x,1,s\rangle )=\langle r^{-1}(x),0,s-1\rangle \). Furthermore, f changes only a single bit. To see this observe that for \(x=1u0v\) with \(u,v\in D\) the bitstrings \(\langle x,0,s\rangle =\sigma ^s(1u0v0)\) and \(f(\langle x,0,s\rangle )=\langle r(x),1,s+1\rangle =\sigma ^{s+1}(u1v01)=\sigma ^s(1u1v0)\) differ only in the bit between the substrings u and v. We also note that \(f^2(\langle x,0,s\rangle )=\langle r(x),0,s+1\rangle \ne \langle x,0,s\rangle \). Consequently, for any vertex y of \(M_n\), the sequence \(C(y):=\big (y,f(y),f^2(y),\ldots \big )\) is a cycle, and \(F_n:=\{C(y)\mid y\in A_n\cup B_n\}\) is a cycle factor in \(M_n\).

As \(f^2(\langle x,0,s\rangle )=\langle r(x),0,s+1\rangle \), moving two steps forward along a cycle of \(F_n\) applies a tree rotation to the nut, and increases the shift by \(+1\). As the ordered rooted tree \(x\in D_n\) has n edges, we have \(x=r^{2n}(x)\). Consequently, the minimum integer \(t>0\) such that \(x=r^t(x)\) must divide 2n. It follows that \(\gcd (t,2n+1)=1\), hence all shifts of the nut x are contained in the cycle \(C(\langle x,0,0\rangle )\), i.e., \(\langle x,0,s\rangle \in C(\langle x,0,0\rangle )\) for all \(s\in \{0,\ldots ,2n\}\). Therefore, the cycles of \(F_n\) are in bijection with equivalence classes of ordered rooted trees with n edges under tree rotation, also known as plane trees. In particular, the number of cycles of \(F_n\) is the number of plane trees with n edges (OEIS A002995).

The second step is to glue the cycles of the factor \(F_n\) to a single Hamilton cycle. We call an ordered rooted tree \(x\in D_n\) pullable if \(x=110u0v\) for \(u,v\in D\), and we define \(p(x):=101u0v\in D_n\). We refer to p(x) as the tree obtained from x by a pull operation. In words, the leftmost leaf of x is in distance 2 from the root, and the edge leading to this leaf is removed and reattached as the new leftmost child of the root in p(x); see Fig. 3. For any pullable tree \(x=110u0v\in D_n\) with \(u,v\in D\), we define \(y:=\langle x,0,0\rangle =x0\) and \(z:=\langle p(x),0,0\rangle =p(x)0\), and we consider the 6-cycle \(G(x):=(y,f(y),f^6(y),f^5(y),z,f(z))=(110u0v0,110u1v0,100u1v0,101u1v0,101u0v0,111u0v0)\), which has the edges (yf(y)) and \((f^6(y),f^5(y))\) in common with the cycle C(y), and the edge (zf(z)) in common with the cycle C(z); see Fig. 4. Consequently, if C(y) and C(z) are two distinct cycles, then the symmetric difference between the edge sets of C(y), C(z) and G(x) is a single cycle on the same set of vertices, i.e., G(x) glues the cycles C(y) and C(z) together.

We define \(S(x):=\{f^i(y)\mid i=0,\ldots ,6\}\cup \{z,f(z)\}\), and we claim that for any two pullable trees \(x\ne x'\), we have \(S(x)\cap S(x')=\emptyset \), i.e., the cycles C(x) and \(C(x')\) are (vertex-)disjoint. To see this, consider the shifts of the vertices in S(x) and \(S(x')\), which are 0, 1, 1, 2, 2, 3, 3, 0, 1. It follows that if \(S(x)\cap S(x')\ne \emptyset \), then we have \(x=x'\), \(p(x)=x'\), or \(x=p(x')\). These cases are ruled out by the assumption \(x\ne x'\), the fact that \(p(x)=10\cdots \) and \(x'=11\cdots \) differ in the second bit, and that \(x=11\cdots \) and \(p(x')=10\cdots \) differ in the second bit, respectively.

To complete the proof, it remains to show that the cycles of the factor \(F_n\) can be glued to a single cycle via gluing cycles G(x) for a suitable set of pullable trees \(x\in D_n\). As argued before, none of the gluing operations interfere with each other. Using the interpretation of the cycles of \(F_n\) as equivalence classes of ordered rooted trees under tree rotation, it suffices to prove that every cycle can be glued to the cycle that corresponds to the star with n edges. As each gluing cycle corresponds to a pull operation, this amounts to proving that any ordered rooted tree \(x\in D_n\) can be transformed to the star \((10)^n\) via a sequence of tree rotations and/or pulls.

Fig. 1
figure 1

A Dyck word (left) and the corresponding ordered rooted tree (right)

Fig. 2
figure 2

Tree rotation

Fig. 3
figure 3

Pull operation

Fig. 4
figure 4

Gluing 6-cycle G(x)

Fig. 5
figure 5

Illustration of steps (i)–(iii) that make a tree more star-like

Indeed, this is achieved as follows: We fix a vertex c of x to become the center of the star (this vertex never changes), and we repeatedly perform the following three steps; see Fig. 5: (i) rotate x to a tree \(x'\) such that c is root and the leftmost leaf of \(x'\) is in distance \(d>1\) from c; (ii) apply \(d-2\) rotations to \(x'\) to obtain a tree \(x''\) whose leftmost leaf has distance 2 from the root; (iii) perform a pull. As step (iii) decreases the sum of distances of all vertices from c, we reach the star after finitely many steps.

This completes the proof of the theorem. \(\square \)