On the central levels problem

The central levels problem asserts that the subgraph of the $(2m+1)$-dimensional hypercube induced by all bitstrings with at least $m+1-\ell$ many 1s and at most $m+\ell$ many 1s, i.e., the vertices in the middle $2\ell$ levels, has a Hamilton cycle for any $m\geq 1$ and $1\le \ell\le m+1$. This problem was raised independently by Buck and Wiedemann, Savage, by Gregor and \v{S}krekovski, and by Shen and Williams, and it is a common generalization of the well-known middle levels problem, namely the case $\ell=1$, and classical binary Gray codes, namely the case $\ell=m+1$. In this paper we present a general constructive solution of the central levels problem. Our results also imply the existence of optimal cycles through any sequence of $\ell$ consecutive levels in the $n$-dimensional hypercube for any $n\ge 1$ and $1\le \ell \le n+1$. Moreover, extending an earlier construction by Streib and Trotter, we construct a Hamilton cycle through the $n$-dimensional hypercube, $n\geq 2$, that contains the symmetric chain decomposition constructed by Greene and Kleitman in the 1970s, and we provide a loopless algorithm for computing the corresponding Gray code.


Introduction
The n-dimensional hypercube, or n-cube for short, is the graph Q n formed by all {0, 1}-strings of length n, with an edge between any two bitstrings that differ in exactly one bit. This family of graphs has numerous applications in computer science and discrete mathematics, many of which are tied to famous problems and conjectures, such as the sensitivity conjecture of Nisan and Szegedy [29], recently proved by Huang [23]; Erdős and Guys' crossing number

Our results
In this paper we consider the central levels problem, a broad generalization of the middle levels problem: Does the subgraph of the (2m + 1)-cube induced by the middle 2 levels, i.e., by levels m + 1 − , . . . , m + , have a Hamilton cycle for any m ≥ 1 and 1 ≤ ≤ m + 1? This problem was raised independently by Savage [34], Gregor and Škrekovski [20], and by Shen and Williams [38]. Clearly, the case = 1 of the central levels problem is the aforementioned middle levels problem (solved in [27]). Moreover, the case = 2 was solved affirmatively in a paper by Gregor, Jäger, Mütze, Sawada, and Wille [16] presented at ICALP 2018. Also, the case = m + 1 is established by the binary reflected Gray code Γ 2m+1 . Furthermore, the case = m was solved by El-Hashash and Hassan [7], and in a more general setting by Locke and Stong [26], and the case = m − 1 was settled in [20].
The main contribution of this paper is to solve the central levels problem affirmatively in full generality; see Figure 1 (a)-(d).

Theorem 1.
For any m ≥ 1 and 1 ≤ ≤ m + 1, the subgraph of the (2m + 1)-cube induced by the middle 2 levels has a Hamilton cycle.
The most general question in this context is to ask for a Hamilton cycle in Q n that visits all vertices in any sequence of consecutive levels, i.e., the levels need not be symmetric around the middle, and the dimension n needs not be odd. These graphs are all bipartite, and to circumvent the imbalances that prevent the existence of a Hamilton cycle for general n and , we have to slightly generalize the notion of Hamilton cycles: Firstly, a saturating cycle in a bipartite graph is a cycle that visits all vertices in the smaller partition class (if it has P. Gregor, O. Mička, and T. Mütze 60:3 size 1, then a single edge is considered to be a cycle). Secondly, a tight enumeration in a (bipartite) subgraph of the cube is a cyclic listing of all its vertices where the total number of bits flipped is exactly the number of vertices plus the difference in size between the two partition classes. Clearly, if both partition classes have the same size, these two notions are equal to a Hamilton cycle. In fact, all cases of this more general problem, except the central levels problem, were solved already in [18], some of them conditional on a "yes" answer to the central levels problem. Combining Theorem 1 with these previous results, we now also obtain an unconditional result for this more general question.

Corollary 2.
For any n ≥ 1 and 1 ≤ ≤ n + 1, the subgraph of the n-cube induced by any sequence of consecutive levels has both a saturating cycle and a tight enumeration.
An essential tool in our proof of Theorem 1 are symmetric chain decompositions. This is a well-known concept from the theory of posets, which we now define specifically for the n-cube using graph-theoretic language. A symmetric chain in Q n is a path (x k , x k+1 , . . . , x n−k ) in the n-cube where x i is from level i for all k ≤ i ≤ n − k, and a symmetric chain decomposition, or SCD for short, is a partition of the vertices of Q n into symmetric chains. It is well-known that the n-cube has an SCD for all n ≥ 1, and the simplest explicit construction was given by Greene and Kleitman [15] (see Section 2.2 below). Streib and Trotter [40] first investigated the interplay between SCDs and Hamilton cycles in the n-cube, and they described an SCD in Q n that can be extended to a Hamilton cycle; see Figure 1 (e). Their SCD, however, is different from the aforementioned Greene-Kleitman SCD. In this paper, we extend Streib and Trotter's result as follows; see Figure 1 (f).

Theorem 3.
For any n ≥ 2, the Greene-Kleitman SCD can be extended to a Hamilton cycle in Q n .
The Greene-Kleitman SCD has found a large number of applications in the literature, e.g., to construct symmetric Venn diagrams [21,33], to solve the Littlewood-Offord problem [3,Chap. 4], or to learn monotone Boolean functions [25, Sec. 7.2.1.6] (see also [1,6,31,37,42]). Knowing that this SCD extends to a Hamilton cycle and that it is a crucial ingredient for solving the general central levels problem adds to this list of interesting properties and applications. Observe also that a Hamilton cycle that extends an SCD has the intriguing property that it minimizes the number of changes of direction from moving up to moving down, or vice versa, between consecutive levels in the cube. For comparison, the monotone paths constructed by Savage and Winkler [36] maximize these changes.
Motivated by these results and by the aforementioned conjecture of Ruskey and Savage [32] that every matching in Q n extends to a Hamilton cycle, we raise the following conjecture:

Conjecture 4. Every SCD can be extended to a Hamilton cycle in Q n .
Although every SCD of Q n is the union of two matchings, there are matchings in Q n that do not extend to an SCD; take for example the two edges obtained by starting at the vertices 0 n and 1 n and flipping the same bit. Consequently, an affirmative answer to Conjecture 4 would cover only some cases of the Ruskey-Savage conjecture.

Efficient algorithms
Our proof of Theorem 1 is constructive and translates directly into an algorithm for computing the Hamilton cycle in time and space that are polynomial in the size of the graph (the middle 2 levels of Q n , n := 2m + 1), which is exponential in n. Often, it is desirable to have 60:4 On the Central Levels Problem a "local" algorithm that uses only time and space that are polynomial in n. Ideally, one might hope for O(n) space to store the current bitstring and some additional data structures, and O(1) time to compute the next bitstring on the cycle. Such algorithms are known for the binary reflected Gray code Γ n [2], and for the middle levels problem [28], i.e., for the extreme cases = m + 1 and = 1 of the central levels problem. There are fundamental obstacles that prevent us to obtain such a local algorithm from our proof, and it remains a challenging open problem to find such an algorithm. Our Theorem 3 on the other hand, can be translated into a simple algorithm that uses only O(n) space and O(1) time in every iteration to compute the next bitstring along the Hamilton cycle. A pseudocode description of this algorithm is available in [17]. We also implemented it in C++, available for download and for demonstration on the Combinatorial Object Server [5].

Proof ideas
We first describe the ideas for proving Theorem 1. For any m ≥ 1 we define n := 2m + 1, and for 1 ≤ ≤ m + 1 we let Q n, denote the subgraph of Q n induced by the middle 2 levels. To prove that Q n, has a Hamilton cycle for general m and , we combine and generalize the tools and techniques developed for the cases = 1 and = 2 in [19] and [16], respectively. Our proof proceeds in two steps: In a first step, we construct a cycle factor in Q n, , i.e., a collection of disjoint cycles which together visit all vertices of Q n, . In a second step, we use local modifications to join the cycles in the factor to a single Hamilton cycle. Essentially, this technique reduces the Hamiltonicity problem in Q n, to proving that a suitably defined auxiliary graph is connected, which is much easier.
In fact, the predecessor paper [16] already proved the existence of a cycle factor in Q n, , but this construction does not seem to yield a factor that would be amenable to analysis. In this paper, we therefore construct another cycle factor in Q n, , based on modifying the aforementioned Greene-Kleitman SCD of Q n by the lexical matchings introduced by Kierstead and Trotter [24]. The resulting cycle factor in Q n, has a rich structure, in particular the number of cycles and their lengths can be described combinatorially.
The simplest way to join two cycles C and C from this factor to a single cycle is to consider a 4-cycle F that shares exactly one edge with each of the cycles C and C (the other two edges of F must then go between C and C ), and to take the symmetric difference of the edge sets of C ∪ C and of F , yielding a single cycle (C ∪ C ) F on the same vertex set as C ∪ C . We refer to such a cycle F as a flipping 4-cycle. For example, if we interpret the binary reflected Gray code Γ n as a cycle in Q n , we see that Γ n+1 = (0Γ n ∪ 1Γ R n ) F where F is the 4-cycle F = 0 n+1 , 010 n−1 , 110 n−1 , 10 n . In addition to flipping 4-cycles, we also use flipping 6-cycles, which intersect with the two cycles to be joined in a slightly more complicated way, albeit with the same effect of joining them to a single cycle. The most technical aspect of this part of the proof is to ensure that all flipping cycles used are edge-disjoint, so that the joining operations do not interfere with each other.
To prove Theorem 3, we proceed by induction from dimension n to n + 2, treating the cases of even and odd n separately. We first specify a particular ordering of all chains of the Greene-Kleitman SCD, and then show that this ordering admits a matching that alternatingly joins the bottom or top vertices of any two consecutive chains in our ordering. In fact, there is a close relation between our proofs of Theorem 1 and 3: The aforementioned construction of a cycle factor in Q n, is particularly nice for = m + 1, i.e., for the case where we consider the entire cube. Specifically, in this case our cycle factor contains all chains from the Greene-Kleitman SCD. These cycles can be joined to a single Hamilton cycle in such a way, so as to give exactly the aforementioned Hamilton cycle constructed for proving Theorem 3.

60:6
On the Central Levels Problem

Outline of this paper
In Section 2 we discuss the Greene-Kleitman SCD and lexical matchings, and collect some other preliminaries. In Section 3 we describe our construction of a cycle factor in Q n, . Due to space constraints, in this extended abstract we are unable to provide the full details of the analysis of this cycle factor, and how to join its cycles to a Hamilton cycle. We rather give an informal high-level sketch of these steps in Section 4. In Section 5 we present our proof of Theorem 3. The omitted proof details, together with the pseudocode description of the corresponding loopless algorithm can be found in [17].

Preliminaries
For the reader's convenience, important notations that are introduced in the following and used repeatedly in the paper are summarized in Table 1 at the end of this paper.

Bitstrings and lattice paths
For any string x and any integer k ≥ 0, we let x k denote the concatenation of k copies of x.
We often interpret a bitstring x as a path in the integer lattice Z 2 starting at the origin (0, 0), where every 0-bit is interpreted as a -step that changes the current coordinate by (+1, −1) and every 1-bit is interpreted as an -step that changes the current coordinate by (+1, +1); see Figure 2.

Figure 2
The correspondence between bitstrings (top) and lattice paths (bottom).
Let D 2k denote the set of bitstrings with exactly k many 1s and k many 0s, such that in every prefix, the number of 0s is at least as large as the number of 1s. We also define D := k≥0 D 2k . Note that D 0 = {ε}, where ε denotes the empty bitstring. In terms of lattice paths, D corresponds to so-called Dyck paths that never move above the line y = 0 and end on this line. If a lattice path x contains a substring u ∈ D, then we refer to this substring u as a valley in x.

The Greene-Kleitman SCD
We now describe Greene and Kleitman's [15] construction of an SCD in the n-cube; see Figure 3. For any vertex x of the n-cube, we interpret the 0s in x as opening brackets and the 1s as closing brackets. By matching closest pairs of opening and closing brackets in the natural way, the chain containing x is obtained by flipping the leftmost unmatched 0 to ascend the chain, or the rightmost unmatched 1 to descend the chain, until no more unmatched bits can be flipped. It is easy to see that this indeed yields an SCD of the n-cube for any n ≥ 1. We always work with this SCD due to Greene and Kleitman, and whenever referring to a chain, we mean a chain from this decomposition. 1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 1 0 1  1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 0 0 1  1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 0 0 1  1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 0 0 0 1  1 1 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 0 0 1  1 1 1 1 1 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1  1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1  1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1  Each chain C of length h in Q n can be encoded compactly as a string of length n over the alphabet {0, 1, * } in the form where u 0 , . . . , u h ∈ D. The symbols * represent unmatched positions, and the vertices along the chain are obtained by replacing the * s by 1s followed by 0s in all possible ways; see (2). For example, the chain shown in Figure 3 is C = * * * * * 01 * 01 * 010011 * * * 01, so we have Given a chain C of length h as in (1), the ith vertex of C from the bottom is where i = 0, . . . , h, and this vertex belongs to level k = n−h 2 + i. Note that every vertex x of Q n can be written uniquely in the form (2), and we refer to this as the chain factorization of x. For the following arguments, it will be crucial to consider the lattice path representation of x, with the valleys u 0 , . . . , u h that are separated by i many -steps, followed by h − i many -steps, i.e., the valley u i is the highest one on the lattice path. We

Lexical matchings
Lexical matchings in Q n were introduced by Kierstead and Trotter [24], and they are parametrized by some integer p ∈ {0, 1, . . . , n − 1}. These matchings are defined as follows; see Figure 4. We interpret a bitstring x as a lattice path, and we let x denote the lattice 60:8 On the Central Levels Problem path that is obtained by appending -steps to x until the resulting path ends at height −1. If x ends at a height less than −1, then x := x. Similarly, we let x denote the lattice path obtained by appending -steps to x until the resulting path ends at height +1. If x ends at a height more than +1, then x := x. We let L n,k denote the set of all vertices on level k of Q n , and we define a matching by two partial mappings M p,↑ n,k : L n,k → L n,k+1 and M p,↓ n,k : L n,k+1 → L n,k defined as follows: For any x ∈ L n,k we consider the lattice path x and scan it row-wise from top to bottom, and from right to left in each row. The partial mapping M p,↑ n,k (x) is obtained by flipping the pth -step encountered in this fashion, where counting starts with 0, 1, . . ., if this -step is part of the subpath x of x ; otherwise x is left unmatched. Similarly, for any x ∈ L n,k+1 we consider the lattice path x and scan it row-wise from top to bottom, and from left to right in each row. The partial mapping M p,↓ n,k (x) is obtained by flipping the pth -step encountered in this fashion if this -step is part of the subpath x of x ; otherwise x is left unmatched. It is straightforward to verify that these two partial mappings are inverse to each other, so they indeed define a matching between levels k and k + 1 of Q n , called the p-lexical matching, which we denote by M p n,k . We also define M p n := 0≤k<n M p n,k , where we omit the index n whenever it is clear from the context. In the following, we will only ever use p-lexical edges for p = 0, 1, 2. For instance, it is well-known that taking the union of all 0-lexical edges, i.e., the set M 0 , yields exactly the Greene-Kleitman SCD [24]. This property is captured by the following lemma, together with several other explicit perfect matchings, consisting of {0, 1, 2}-lexical edges between certain sets of vertices from our SCD; see Figure 5.
To state the lemma, for a set M of edges of Q n and disjoint sets X, Y of vertices, we let M [X, Y ] denote the set of all edges of M between X and Y . Moreover, for any vertex x ∈ C − h,i , 1 < i < h ≤ n, we consider the chain factorization x = u 0 1 · · · u i−2 1 u i−1 1 0 u i+1 · · · 0 u h with u 0 , . . . , u h ∈ D, and we define a neighbor z(x) on the level below by Note that (x, z(x)) is a 0-lexical or 2-lexical edge in the first or second case, respectively.

Lemma 5.
For every n ≥ 3, the following sets of edges M [X, Y ] are perfect matchings in Q n between the vertex sets X and Y . ( The proof of Lemma 5 can be found in [17].

Cycle factor construction
We now construct a cycle factor C n, in the graph Q n, , n = 2m + 1, i.e., in the subgraph of the n-cube induced by the middle 2 levels. Throughout this section we consider fixed m ≥ 1 and 2 ≤ ≤ m + 1. We construct the cycle factor incrementally, starting with chains from the Greene-Kleitman SCD and adding {0, 1, 2}-lexical edges between certain sets of vertices, see Figure 6. In the following, when referring to a subgraph given by a set of edges, we mean the subgraph of Q n, induced by those edges. Moreover, we say that a chain is short if its length is at most 2 − 3, i.e., if it does not span all levels of Q n, . Our construction starts by taking all those short chains, formally respectively. Note that the only vertices of short chains that have degree 1 in the set Next, between every pair of consecutive levels of Q n, we take all 0-lexical and 1-lexical edges that are not incident to a degree-2 vertex in X. Specifically, between these pairs of levels we take all 0-lexical edges from chains that are not short and all 1-lexical edges between chains that are not short. In addition, between the top two levels we take all 1- for 1 ≤ k ≤ . Note that Y 1 and Y contain all {0, 1}-lexical edges between the bottom two levels or the top two levels of Q n, , respectively. We also define As a consequence of these definitions and Lemma 5 (i) and (ii), the only vertices of Q n, that have degree 1 in the set X ∪ Y are exactly the vertices of C − 2 −1,i for 1 ≤ i ≤ 2 − 2. We thus add the edges defined in part (iii) of Lemma 5, which makes a cycle factor in the graph Q n, .

Comparison with previous constructions
Our cycle factor construction generalizes the construction for = 1 presented in [19,27], which simply consisted in taking the union of all 0-lexical and 1-lexical edges between the middle two levels. It also generalizes the construction for = 2 presented in [16], which also only used {0, 1, 2}-lexical matchings. In fact, all these earlier papers actually used {m, m − 1, m − 2}-lexical matching edges, but these are isomorphic to {0, 1, 2}-lexical edges by reversing bitstrings. The earlier construction for = 2 seemed rather arbitrary at the time, but now nicely fits into the general picture shown in Figure 6 1 .
1 As the picture of this construction resembles a rocket, with the tip on the left and the boosters on the right, one might be tempted to consider this rocket science. Figure 6 Illustration of the cycle factor C n, for = 2, 3, 4. Each bullet represents an entire set of vertices, as specified in the figure, lines between them specify perfect matchings between these sets. The {0, 1, 2}-lexical edges are drawn with solid, dashed, and dotted lines, respectively. In the bottom part, various sets of matching edges are highlighted.

Sketch of the remaining proof steps
It turns out that each cycle from the factor C n, defined in (7) visits vertices from an interval of 2r levels, where 2 ≤ r ≤ , around the middle. We refer to the number 2r as the range of the cycle, and we say the cycle is short if 2 ≤ r < , and long if r = . One can show that any short cycle with range r has length 8(r For long cycles, on the other hand, we are lacking such a detailed understanding of their structure. However, we are able to identify certain vertices on them, and to describe the operation of moving along one cycle from one such special vertex to the next one in terms of certain rotation operations on ordered rooted trees. Consequently, long cycles are obtained as equivalence classes of ordered rooted trees under such rotations. As outlined in Section 1.3, to join the cycles in our factor to a Hamilton cycle, we explicitly construct flipping 4-cycles and 6-cycles. The 4-cycles are used to join short cycles among each other and to long cycles, in such a way that every short cycle is joined to some long cycle, possibly via other short cycles. For this we exploit the fact that certain pairs of short chains from the Greene-Kleitman SCD are connected by many 4-cycles. Specifically, consider any short chain C of length h ≥ 3, and any chain C of length h − 2 obtained from C by replacing two consecutive *s at positions a and b by 0 and 1, respectively. Using the definition of Greene-Kleitman chains, it is easy to check that C and C are connected by h − 2 many 4-cycles, each using a distinct edge of C and C , except the two consecutive edges of C that I C A L P 2 0 2 0 60:12 On the Central Levels Problem flip the coordinates a and b. The Greene-Kleitman SCD has an abundance of such pairs of heavily connected pairs of chains, and as our cycle factor contains all these short chains, we can exploit this to join short cycles to each other and to some long cycle in a tree-like fashion, by considering the short cycles by increasing range. Particular care must be taken to ensure that all selected flipping 4-cycles are edge-disjoint from each other, so that they do not interfere with each other in the joining process. The remaining task is to join long cycles to each other, and for this we use flipping 6-cycles between the topmost two levels of Q n, , ensuring that they are edge-disjoint from any flipping 4-cycles, which all live in the levels below. Such a flipping 6-cycle can be used to connect two long cycles with each other, and this operation can again be interpreted in terms of an operation on ordered rooted trees, which we call a pull operation. These 6-cycles have been described and used heavily already in the predecessor papers [16,19], where it was shown that they are all edge-disjoint. To complete the proof of Theorem 1, we show that all long cycles can be joined to each other by flipping 6-cycles, by showing that all equivalence classes of ordered rooted trees under the aforementioned rotations (which correspond to long cycles) can be transformed into each other by pull operations (which correspond to flipping 6-cycles). This step of the proof reduces the Hamiltonicity problem in Q n, to proving that a suitably defined auxiliary graph is connected, which turns out to be much easier.

Proof of Theorem 3
In this section, we prove Theorem 3. All lemmas stated below follow from straightforward calculations; see [17] for details. For any chain C, we let |C| denotes its length, i.e., the number of * s in C. For any chain C with |C| ≥ 2, we let f (C) and (C), respectively, denote the chains obtained by replacing the first two * s or the last two * s in C by 0 and 1. Note that if |C| ≥ 2, then we have f ( ( * C * )) = (f ( * C * )).
Our goal is to order the chains of the Greene-Kleitman SCD in Q n , n ≥ 2, so that any consecutive pair of chains is joined at their top end vertices or bottom end vertices alternatingly, with the exception of any two consecutive chains of length 1 that are connected from the bottom end of one of them to the top end of the other, so as to form a Hamilton cycle. We call such an ordering of chains a cycle ordering. The following simple but powerful lemma, valid for arbitrary SCDs, shows that the direction in which each chain is traversed along the Hamilton cycle (upwards or downwards) is determined only by the chain length. Lemma 6. Let Λ n be a cycle ordering of chains of an SCD in Q n , n ≥ 2. In this Hamilton cycle, any two chains C and C with |C| ≡ |C | (mod 4) are traversed in the same direction.
We now define a cycle ordering Λ n , n ≥ 2, for the Greene-Kleitman SCD. The corresponding Hamilton cycle is oriented so that it traverses the longest chain * n , which will be the first in the ordering Λ n , from bottom to top. Our construction works inductively, and the induction step goes from n to n + 2, with separate rules for even and odd n. The base cases are n = 0 and n = 1, for which the entire cube consists only of a single vertex and a single edge, respectively, so for these cases the notion of a cycle ordering is not defined.
We call the chains of λ(C) arising from C the descendants of C. This rule replaces each chain C in Λ n by its descendants λ(C), where the order of descendants can be reversed, indicated by the superscript R, depending on the length of C modulo 4. For odd n, we define Λ 1 := * , and for n ≥ 1 and given Λ n we define Λ n+2 := ρ(Λ n ), where ρ is as before and  To complete the proof of Theorem 3, it remains to show that any two consecutive chains in Λ n can be joined by an edge between their top ends or bottom ends alternatingly. For this we need the following simple lemmas that guarantee these connecting edges. All connecting edges between top and bottom ends among the descendants of a chain guaranteed by Lemma 8 are shown in Figure 7. The next two lemmas are illustrated in Figure 8.

Proof of Theorem 3 (even n).
We show that Λ n , n ≥ 2 even, defined in (9) is a cycle ordering of the Greene-Kleitman chains, by proving that any consecutive pair of chains is connected at their top or bottom ends alternatingly, starting with the first chain * n of length n that is traversed from bottom to top. We will also establish the following additional property P: For any two consecutive chains C and C connected at their top ends, we either have C = f (C ) or f (C) = C . These invariants can easily be checked for the induction base case n = 2, which is given by Λ 2 = * * , 01.
For the induction step consider n ≥ 2 to be even, and assume that Λ n is a cycle ordering satisfying property P. By Lemma 8, the descendants λ(C) for any chain C from Λ n can be joined as shown on the left hand side of Figure 7, so we only need to check the connections between the first and last chains among consecutive groups of descendants. Indeed, if C and C are consecutive in Λ n and joined at their bottom ends, then C is traversed from top to bottom and C from bottom to top in the Hamilton cycle; see the left part of Figure 8. Consequently, by Lemma 6, we have |C| ≡ | * n | = n (mod 4) and |C | ≡ n (mod 4), i.e., by (8) the sequence Λ n+2 contains λ(C) R and λ(C ), and indeed, the bottom vertex of the last chain of λ(C) R , namely * C * , is connected to the bottom vertex of the first chain of λ(C ), namely * C * , by Lemma 9. Similarly, if C and C are consecutive in Λ n and joined at their top ends, then C is traversed from bottom to top and C from top to bottom in the Hamilton cycle; see the right part of Figure 8. Consequently, by Lemma 6, we have |C| ≡ n (mod 4) and |C | ≡ n (mod 4), i.e., by (8) the sequence Λ n+2 contains λ(C) and λ(C ) R , and indeed, the bottom vertex of the last chain of λ(C), namely ( * C * ), is connected to the bottom vertex of the first chain of λ(C ) R , namely ( * C * ), using that by property P we have either C = f (C ) or f (C) = C , so we can invoke Lemma 10. Moreover, property P still holds for Λ n+2 by the definition (9) (note that if |C| = 0, then we have 0C1 = f ( * C * )).
The proof of Theorem 3 for odd n is very similar. In [17] we provide all details and a loopless algorithm for computing this Gray code. An implementation of this algorithm in C++ is available for download and for demonstration [5]. Table 1 A glossary for notation used in the paper.

Qn
n ≥ 1 the n-dimensional hypercube Q n, 1 ≤ ≤ m + 1 the subgraph of Qn induced by the middle 2 levels n = 2m + 1, m ≥ 1 D 2k k ≥ 0 the set of all Dyck paths (bitstrings) of length 2k D the set of all Dyck paths C a chain C = u0 * u1 * · · · * u h−1 * u h of length h ≥ 0 in the Greene-Kleitman decomposition, ui ∈ D for every i C h,i 0 ≤ i ≤ h the set of the ith vertices in all chains of length h C − h,i 0 ≤ i ≤ h as above but only in chains with ui = ε C + h,i 0 ≤ i ≤ h as above but only in chains with ui = ε L n,k 0 ≤ k ≤ n the set of vertices on level k in Qn M p n,k 0 ≤ k < n, 0 ≤ p < n the p-lexical matching between L n,k and L n,k+1 M p n , M p 0 ≤ p < n the set of all p-lexical edges in Qn |C| the length of a chain C, i.e., |C| = h for C as above f (C) |C| ≥ 2 the chain f (C) = u0 0 u1 1 u2 * · · · * u h for C as above l(C) |C| ≥ 2 the chain l(C) = u0 * · · · * u h−2 0 u h−1 1 u h for C as above λ(C) a sequence of descendant chains for a chain C, see (9), (10)