1 Introduction

Consider a finite bag (multiset) of n (\(n \ge 1\)) natural numbers, serving as symbols, where the symbol i occurs \(k_i\) times; thus, \(n = \sum _{i=0}^\infty \,k_i\). We denote this bag by \(B(k_0, k_1, \ldots )\), and call the tuple \((k_0, k_1, \ldots )\) its signature. We omit trailing \(k_i = 0\). The number of non-zero \(k_i\) is called the arity. An example for \(n=4\) is \(B(1, 2, 1) = [\, 0, 1, 1, 2 \,]\); it is ternary. A permutation of such a bag is a way of putting the symbols in a sequence. The twelve permutations of B(1, 2, 1) are the vertices of the graph in Fig. 1.

Fig. 1
figure 1

Neighbor-swap graph for \(B(1, 2, 1) = [\, 0, 1, 1, 2 \,]\) (12 vertices, 15 edges)

Two permutations are related by a neighbor swap when they can be obtained from each other by swapping (interchanging) two distinct adjacent symbols. We denote this relation by \(\sim \). The neighbor-swap graph of \(B(k_0, k_1, \ldots )\) has all permutations of \(B(k_0, k_1, \ldots )\) as vertices, where two permutations are connected by an edge when they are related by a neighbor swap. Figure 1 shows the neighbor-swap graph for B(1, 2, 1), and Fig. 2 for B(2, 1, 2). Note that neighbor-swap graphs whose signatures are a permutation of each other are isomorphic.

Fig. 2
figure 2

Neighbor-swap graph for \(B(2, 1, 2) = [\, 0, 0, 1, 2, 2 \,]\) (30 vertices, 48 edges)

We are interested in finding a path along the edges of the neighbor-swap graph visiting each vertex exactly once. Such a path is known as a Hamiltonian path. If the start and end vertex of the path are also connected by a graph edge (not appearing in the path), then we speak of a Hamiltonian cycle.

Generation of permutations in such a minimum-change order is relevant, because it minimizes energy consumption in hardware and maximizes the ability to reuse results cached while processing previously generated permutations [6, §7.2]. This has for instance applications in cryptology. In [13], we explain how we encountered this problem in the context of choreographing a line dance, where each symbol corresponds to the color of an outfit.

If no Hamiltonian path exists, then we can relax the constraints somewhat. One such relaxation is a maximal path (or cycle) without duplicates, that is, a path that visits a maximal number of vertices exactly once, such that the unvisited vertices are at minimum distance from the path. An unvisited vertex u at distance 1 can be visited by sidestepping from a vertex v on the path to u and then immediately back again to v. In the resulting path, v occurs twice, with only u in-between. In [8], Lehmer calls such a sidestep to an unvisited vertex at distance 1 a spur (see Fig. 3), and a Hamiltonian path extended with spurs that visits all vertices he called an imperfect Hamiltonian path. We will call it a Lehmer path:

Definition 1

A Lehmer path (cycle) in a graph is a path (cycle), possibly with single spurs, that visits the spur bases twice and all other vertices once.

Fig. 3
figure 3

Path with four spurs; at A and C there are single spurs, at B a double spur

Lehmer conjectured in [8] (also see [6, Exercise 53 of §7.2.1.3]):

Conjecture 2

Every neighbor-swap graph admits a Lehmer path.

Another relevant relaxation is to find a (vertex-)disjoint cycle cover, that is, a set of vertex-disjoint simple cycles that visit all permutations exactly once.

In Sect. 2, we review the known results. The condition for existence of a Hamiltonian path (i.e., without spurs) is presented in Sect. 3, together with a new proof of its necessity, based on stutter permutations. In Sect. 4, we prove Lehmer’s conjecture for the binary case, including a new proof for the known case where a Hamiltonian path exists. Finally, Sect. 5 addresses the general case, proving the existence of a disjoint cycle cover, and Sect. 6 concludes the article.

2 Known results

The special case where symbols occur just once, corresponds to permutations of a set. Its neighbor-swap graph is also known as a permutohedron. In this case, there exists a Hamiltonian path for every n, and even a Hamiltonian cycle if \(n\ge 3\) [3, 5, 10]. Apparently, 17th-century change ringers were already aware of this [1] and [6, §7.2.1.2].

The special case of arity two (\(n = k_0 + k_1\)) corresponds to combinations, or permutations of a bit string, or \(k_0\)-subsets of an n-element set. In [2], this problem is partly solved: a Hamiltonian path exists precisely when either it is trivial (a \(k_i\) equals 0 or 1), or n is even and both \(k_i\) are odd. A more efficient algorithm to construct a Hamiltonian path, when it exists, is given in [4]. An alternative construction is presented in [12].

The general case (ternary or larger arity) was partly solved in [7, 9]. In [7] it was shown that for a Hamiltonian path to exist it is necessary that the signature has at least two odd \(k_i\). And in [9], a construction for a Hamiltonian path is presented when the signature has at least two odd \(k_i\). This is summarized in

Theorem 3

There exists a Hamiltonian path in the neighbor-swap graph of \(B(k_0, k_1, \ldots )\) precisely when either it is linear (consists of one path), or when at least two \(k_i\) are odd.

In fact, [9] even presents a Hamiltonian cycle for all those cases, except for signatures of the form (2k, 1, 1) or a permutation thereof, which are shown not to admit a Hamiltonian cycle.

That leaves the case where the signature has fewer than two odd \(k_i\), and no Hamiltonian path exists. In Sect. 4, we prove this for the binary case, and in Sect. 5 we prove the existence of a disjoint cycle cover.

3 Condition for Hamiltonian path and its necessity

In this section, we provide a new elementary proof that the condition in Theorem 3 is necessary. To that end, we will partition the vertices of the neighbor-swap graph into even and odd vertices, such that edges only connect an even vertex with an odd vertex (i.e., the neighbor-swap graph is bipartite). Hence, on every path, even and odd vertices alternate. If the difference between the number of even and odd vertices exceeds one, then there cannot exist a Hamiltonian path. In fact, we give a closed formula for that difference in Theorem 4 below (it is the proof of this theorem that is new).

Let \(M(k_0, k_1, \ldots )\) be the number of permutations of \(B(k_0, k_1, \ldots )\), then

$$\begin{aligned} M(k_0, k_1, \ldots )= & {} n \atopwithdelims (){k_0\, k_1\, \ldots } \end{aligned}$$
(1)

where the right-hand side is the multinomial coefficient defined by

$$\begin{aligned} n \atopwithdelims (){k_0\, k_1\, \ldots }= & {} \frac{n!}{k_0! k_1! \ldots } \end{aligned}$$
(2)

Thus, the neighbor-swap graph consists of a single vertex, precisely when all except at most one \(k_i\) are zero. Also observe that the neighbor-swap graph is linear exactly when its signature is binary and at least one \(k_i=1\).

An inversion in a permutation of \(B(k_0, k_1, \ldots )\) is defined as a pair of (not necessarily adjacent) symbols in the permutation occurring out of order, that is, where the symbol occurring on the left exceeds (in value) the symbol occurring on the right. Thus, the number of inversions in the permutation \(2\,1\,1\,0\) is five, because out of the six pairs all except the pair \(1\,1\) are out of order.

The parity of a permutation is defined as the parity of its number of inversions. The number of inversions of a permutation changes by exactly one, when two distinct adjacent elements are swapped. Thus, neighboring permutations differ in parity. Observe that the graphs in Figs. 1 and 2 are organized such that the vertices appear in columns, where the number of inversions increases from left to right. In the first graph, there are six even and six odd vertices, while the second graph has 16 even and 14 odd vertices (also see Fig. 4, where the vertices are colored by parity). Hence, the second graph definitely does not admit a Hamiltonian path.

Let \(D(k_0, k_1, \ldots )\) be the number of even permutations minus the number of odd permutations of \(B(k_0, k_1, \ldots )\). Below, we give a new proof for

Theorem 4

(3)

where \(\div \) denotes division without remainder.

To conclude the proof of necessity in Theorem 3, note that \(D(k_0, k_1, \ldots )\) equals 1 when at most one \(k_i\) is odd and \(M(k_0 \div 2, k_1 \div 2, \ldots ) = 1\). This boils down to either (i) a singleton graph (all except at most one \(k_i\) equal 0), or (ii) one \(k_i=1\), another \(k_i\) is even and positive, and all others equal 0. In the latter case, the graph is linear. \(\square \)

Proof of Theorem 4

Let \(\varPi (k_0, k_1, \ldots )\) be the set of all permutations of \(B(k_0, k_1, \ldots )\). First, we define a subset \(S(k_0, k_1, \ldots )\) of the even permutations in \(\varPi (k_0, k_1, \ldots )\). Next, we exhibit a 1–1 correspondence between all the odd permutations and all those even permutations not occurring in \(S(k_0, k_1, \ldots )\), establishing that the size of \(S(k_0, k_1, \ldots )\) equals the left-hand side of (3). Finally, we show that the size of \(S(k_0, k_1, \ldots )\) equals the right-hand side of (3).

Fig. 4
figure 4

Neighbor-swap graph for B(2, 1, 2) with parity, stutter permutations, and even-odd pairs of non-stutter permutations marked

To define \(S(k_0, k_1, \ldots )\), we consider the elements of a permutation to be indexed from the left, starting at index 1. There are two kinds of adjacent element pairs, depending on the parity of the index of the left element. Here, we focus on adjacent pairs whose left index is odd, in short, referred to as lio pairs. Lio pairs do not overlap, and look like this:

$$\begin{aligned} e_1\,e_2\mid e_3\,e_4\mid \ldots \mid e_{2j-i}\,e_{2j}\mid \ldots \end{aligned}$$

Definition 5

We call a permutation a stutter permutation when all lio pairs consist of two equal elements, that is, when the element at index 2j equals the element at index \(2j-1\), for all relevant j.

Hence, a stutter permutation has the form \(a\,a\,b\,b\,\ldots \,y\,y\), possibly with a trailing single z. For example, \(2\,2\,1\,1\,0\) is a stutter permutation, but \(2\,1\,1\,0\) is not.

Now define \(S(k_0, k_1, \ldots )\) as the set of stutter permutations in \(\varPi (k_0, k_1, \ldots )\), and \(N(k_0, k_1, \ldots )\) as the set of non-stutter permutations in \(\varPi (k_0, k_1, \ldots )\):

$$\begin{aligned} \varPi (k_0, k_1, \ldots ) = S(k_0, k_1, \ldots ) \uplus N(k_0, k_1, \ldots ) \end{aligned}$$
(4)

Observe that a stutter permutation is even, since all out-of-order pairs occur in even bunches due to the stuttering.

Next, we define a 1–1 correspondence between the even and odd permutations in \(N(k_0, k_1, \ldots )\). Note that all permutations with \(n<2\) are stutter permutations; so, \(N(k_0, k_1, \ldots ) = \varnothing \). Consider a non-stutter permutation, hence \(n\ge 2\). Because it is a non-stutter permutation, there is a lio pair whose elements differ. This permutation is now coupled to the one obtained by swapping the elements in, say, the leftmost lio pair whose elements differ. That new permutation is also a non-stutter permutation and it has the opposite parity. See Fig. 4 for an example of this correspondence. Conclusion: \(D(k_0, k_1, \ldots ) = \# S(k_0, k_1, \ldots )\).

Finally, in a stutter permutation, all symbols, except at most one, occur an even number of times. Therefore, when two or more \(k_i\) are odd, there are no stutter permutations, and thus \(S(k_0, k_1, \ldots )\) is empty. When at most one \(k_i\) is odd, \(S(k_0, k_1, \ldots )\) is non-empty. To determine its size, coalesce each lio pair into a single element, and drop a possibly trailing single element (which always is the same symbol). You now see that the size of \(S(k_0, k_1, \ldots )\) equals the size of \(\varPi (k_0\div 2, k_1\div 2, \ldots )\), which by definition equals \(M(k_0\div 2, k_1\div 2, \ldots )\). Conclusion: the right-hand side of (3) equals \(\# S(k_0, k_1, \ldots )\).

This completes the proof of Theorem 4. \(\square \)

For later use, we present some properties related to stutter permutations in the following lemma.

Lemma 6

  1. 1.

    The number of odd permutations never exceeds the number of even permutations.

  2. 2.

    The number of non-stutter permutations is even.

  3. 3.

    There are no stutter permutations when the signature has two or more odd \(k_i\).

  4. 4.

    There is exactly one stutter permutation when the signature is unary, or when it is binary and one \(k_i=1\) and the other is even, that is, when the graph is linear.

  5. 5.

    A stutter permutation of arity two or more is at distance 1 (in the neighbor-swap graph) from a non-stutter permutation.

  6. 6.

    The distance (in the neighbor-swap graph) between two distinct stutter permutations is a multiple of 4.

Theorem 7

To prove Conjecture 2, it suffices to prove the existence of a Hamiltonian path (or cycle) on all non-stutter permutations.

Proof of Theorem 7

Assume we have a Hamiltonian path (cycle) on all non-stutter permutations. The stutter permutations, being at distance 1 from that path (Lemma 6.5), can serve as spur tips in a Lehmer path (cycle). These spurs are single, since their tips are a multiple of 4 apart (Lemma 6.6), and the distance between the tips of higher-order spurs is only 2 (also see Fig. 3). \(\square \)

We now strengthen Conjecture 2 and generalize Theorem 3:

Conjecture 8

For every neighbor-swap graph, the subgraph consisting of its non-stutter permutations admits a Hamiltonian path. Furthermore, there even exists a Hamiltonian cycle on the non-stutter permutations, except when

  1. 1.

    the signature arity is zero or one, or

  2. 2.

    the signature is binary, and at least one of the \(k_i\) is odd, or

  3. 3.

    the signature is a permutation of (2k, 1, 1).

A Hamiltonian cycle is impossible in the indicated cases, because

  1. 1.

    the graph is a singleton;

  2. 2.

    at least one of the permutations \(0^{k_0}1^{k_1}\) and \(1^{k_1}0^{k_0}\) is a non-stutter permutation, and it has only one neighbor;

  3. 3.

    the edges \(0^i120^j \sim 0^i210^j\), for \(0\le i,j\) and \(i+j = k_0\), form a disconnecting set, and there is an odd number of them (a Hamiltonian cycle would need to cross over an even number of times between the two components connected by these edges; in one component 1 precedes 2 in all its permutations, and in the other 2 precedes 1).

Note that if there is only one stutter permutation (Lemma 6.2). then the graph is linear and the stutter permutation can in fact be incorporated into the path.

4 Proof of the binary case

We prove the binary case of Conjecture 8 (see Theorem 9 below for a precise formulation). We could focus on the missing part only, where at least one \(k_i\) is even. However, it turns out that the odd-odd case can be incorporated into the induction nicely, thanks to the generalization.

We distinguish three cases: odd-even (Sect. 4.2), even-even (Sect. 4.3), and odd-odd (Sect. 4.4). Before diving into the details, it helps the induction to strengthen the theorem a bit further, as follows.

Theorem 9

The neighbor-swap graph of binary (i.e., of arity 2) non-stutter permutations admits a Hamiltonian path. If \(k_0\) and \(k_1\) are both even, then there exists a Hamiltonian cycle. Moreover, we have:

  1. 1.

    The path for the odd-even case \((k_0, k_1)\) can run between

    $$\begin{aligned} 0^{k_0}1^{k_1}&\mathop {\sim }\limits ^{*}&1^{k_1-1}0^{k_0}1 \end{aligned}$$
    (5)

    Note that this path cannot avoid the edge

    $$\begin{aligned} 0^{k_0}1^{k_1}\sim & {} 0^{k_0-1}101^{k_1-1} \end{aligned}$$
    (6)
  2. 2.

    The cycle for the even-even case \((k_0, k_1)\) can include these two specific edges (the underlined bits in the middle are swapped):

    $$\begin{aligned} 0^{k_0-2}\underline{10}1^{k_1-1}0\sim & {} 0^{k_0-1}1^{k_1}0 \end{aligned}$$
    (7)
    $$\begin{aligned} 1^{k_1-2}\underline{01}0^{k_0-1}1\sim & {} 1^{k_1-1}0^{k_0}1 \end{aligned}$$
    (8)

Observe that the involved vertices are indeed in \(N(k_0, k_1)\).

We prove Theorem 9 by strong induction on \(n = k_0 + k_1\) (the length of the permutations) with \(k_0, k_1 \ge 1\). The induction hypothesis is that the theorem holds for all smaller values of n. There is no need for a separate base case (in a way, the cases \((1, k_1)\) act as base case, because their reduction involves another argument than just the induction hypothesis; they are trivial anyway because these graphs are linear).

4.1 Preliminary definition and lemma

We recall a definition and lemma (without proof) from [9].

Definition 10

Given four distinct vertices a, b, c, and d in a graph, edge \(a \sim b\) is said to be parallel to edge \(c \sim d\) when also edges \(a \sim c\) and \(b \sim d\) exist. The latter edges are called cross edges. We call two isomorphic subgraphs parallel when all the corresponding edges are parallel.

Lemma 11

If a path (cycle) and a cycle are vertex disjoint and have a pair of parallel edges, then they can be glued into a single path (cycle) on the union of their vertices.

4.2 The odd-even case

Without loss of generality, we may assume that \(k_0 \ge 1\) is odd and \(k_1 \ge 2\) even. Split the graph into two parts, based on the trailing bit of each permutation:

$$\begin{aligned} \varPi (k_0, k_1)= & {} \varPi (k_0, k_1-1) \cdot 1 \cup \varPi (k_0-1, k_1) \cdot 0 \end{aligned}$$
(9)

where \(V\cdot w\) denotes the set \(\{\,vw \mid v \in V\,\}\) (Fig. 5). Observe that \(\varPi (k_0, k_1-1)\) is now an odd-odd case without stutter permutations, and \(\varPi (k_0-1, k_1)\) an even-even case. Hence, for the (non-)stutter permutations of \(\varPi (k_0, k_1)\) we have

$$\begin{aligned} S(k_0, k_1)= & {} S(k_0-1, k_1) \cdot 0 \end{aligned}$$
(10)
$$\begin{aligned} N(k_0, k_1)= & {} \varPi (k_0, k_1-1) \cdot 1 \cup N(k_0-1, k_1) \cdot 0 \end{aligned}$$
(11)

The induction hypothesis gives us a Hamiltonian path H for \(\varPi (k_0, k_1-1)\), from \(a=0^{k_0}1^{k_1-1}\) to \(c=1^{k_1-1}0^{k_0}\), including the edge \(b \sim c\) with \(b=1^{k_1-2}010^{k_0-1}\), since \(k_0, k_1-1 \ge 1\). If \(k_0=1\), then \(N(k_0-1, k_1) = \varnothing \), and \(H\cdot 1\) is already a Hamiltonian path for \(N(k_0, k_1)\). Now assume \(k_0 \ge 3\); hence, \(k_0-1, k_1 \ge 2\). Then the induction hypothesis gives us a Hamiltonian cycle C for \(N(k_0-1, k_1)\) that includes the edge (8) between \(d=1^{k_1-2}010^{k_0-2}1 \sim e=1^{k_1-1}0^{k_0-1}1\).

Fig. 5
figure 5

How the odd-even case splits, based on the trailing bit, with a path H, cycle C, and five special vertices a1, b1, c1, d0, and e0, all defined in the text

Thus, \(H\cdot 1\) and \(C\cdot 0\) together visit all vertices of \(N(k_0, k_1)\) exactly once. Note that edge \(b1 \sim c1\) is parallel to edge \(d0 \sim e0\), in the sense that edges \(b1 \sim d0\) and \(c1 \sim e0\) exist (swap the trailing two bits):

$$\begin{aligned} \begin{array}{ccc} b1 &{} &{} c1 \\ 1^{k_1-2}010^{k_0-1}1 &{} \sim &{} 1^{k_1-1}0^{k_0}1 \\ \wr &{} &{} \wr \\ 1^{k_1-2}010^{k_0-2}10 &{} \sim &{} 1^{k_1-1}0^{k_0-1}10 \\ d0 &{} &{} e0 \end{array} \end{aligned}$$

Using Lemma 11, the path \(H\cdot 1\) and cycle \(C\cdot 0\) can now be combined as \(a1 \mathop {\sim }\limits ^{*} b1 \sim d0 \mathop {\sim }\limits ^{*} e0 \sim c1\) to obtain a Hamiltonian path for \(N(k_0, k_1)\) from \(0^{k_0}1^{k_1}\) to \(1^{k_1-1}0^{k_0}1\).

This completes the proof for the odd-even case.

4.3 The even-even case

Assuming that both \(k_i \ge 2\) are even, split the graph into two parts, based on the trailing bit of each permutation (Fig. 6):

$$\begin{aligned} \varPi (k_0, k_1)= & {} \varPi (k_0, k_1-1) \cdot 1 \cup \varPi (k_0-1, k_1) \cdot 0 \end{aligned}$$
(12)

Observe that \(\varPi (k_0, k_1-1)\) is now an even-odd case and \(\varPi (k_0-1, k_1)\) an odd-even case, and for the (non-)stutter permutations of \(\varPi (k_0, k_1)\) we have

$$\begin{aligned} S(k_0, k_1)= & {} S(k_0, k_1-1) \cdot 1 \cup S(k_0-1, k_1) \cdot 0 \end{aligned}$$
(13)
$$\begin{aligned} N(k_0, k_1)= & {} N(k_0, k_1-1) \cdot 1 \cup N(k_0-1, k_1) \cdot 0 \end{aligned}$$
(14)

The induction hypothesis gives us

  • a Hamiltonian path H for \(N(k_0, k_1-1)\), from \(a = 1^{k_1-1}0^{k_0}\) to \(c = 0^{k_0-1}1^{k_1-1}0\), including the unavoidable edge (6) \(a \sim b\) with \(b = 1^{k_1-2}010^{k_0-1}\) (remember that we need to interchange the role of 0 and 1 to get an odd-even case), and

  • a Hamiltonian path \(H^\prime \) for \(N(k_0-1, k_1)\), from \(d = 0^{k_0-1}1^{k_1}\) to \(f = 1^{k_1-1}0^{k_0-1}1\), including the unavoidable edge (6) \(d \sim e\) with \(e = 0^{k_0-2}101^{k_1-1}\).

Fig. 6
figure 6

How the even-even case splits, based on the trailing bit, with two paths H and \(H^\prime \), and six special vertices a1, b1, c1, d0, e0, and f0, all defined in the text

Thus, \(H\cdot 1\) and \(H^\prime \cdot 0\) visit all vertices of \(N(k_0, k_1)\) exactly once. Because of the edges \(c1 \sim d0\) and \(f0 \sim a1\) (swap the trailing two bits):

$$\begin{aligned} c1 = 0^{k_0-1}1^{k_1-1}\underline{01}\sim & {} 0^{k_0-1}1^{k_1}0 = d0 \\ f0 = 1^{k_1-1}0^{k_0-1}\underline{10}\sim & {} 1^{k_1-1}0^{k_0}1 = a1 \end{aligned}$$

we can combine \(H\cdot 1\) and \(H^\prime \cdot 0\) into a single Hamiltonian cycle for \(N(k_0, k_1)\), which moreover includes the required specific edges (7) and (8):

$$\begin{aligned} e0 = 0^{k_0-2}101^{k_1-1}0\sim & {} 0^{k_0-1}1^{k_1}0 = d0 \\ b1 = 1^{k_1-2}010^{k_0-1}1\sim & {} 1^{k_1-1}0^{k_0}1 = a1 \end{aligned}$$

This completes the proof for the even-even case.

4.4 The odd-odd case

Let both \(k_i\) be odd. Since the cases where one of the \(k_i =1\) are trivial (linear graph), we assume \(k_i \ge 3\). We split the graph into four parts, based on the trailing two bits of each permutation (Fig. 7):

$$\begin{aligned} \varPi (k_0, k_1)= & {} \begin{array}[t]{l} \varPi (k_0, k_1-2) \cdot 11 \cup {} \\ \varPi (k_0-1, k_1-1) \cdot \{\,01, 10\,\} \cup {} \\ \varPi (k_0-2, k_1) \cdot 00 \end{array} \end{aligned}$$
(15)

Observe that \(\varPi (k_0, k_1-2)\) and \(\varPi (k_0-2, k_1)\) are now odd-odd cases and \(\varPi (k_0-1, k_1-1)\) is an even-even case. There are no stutter permutations in \(\varPi (k_0, k_1)\), but there are in \(\varPi (k_0-1, k_1-1)\). So, we have to incorporate those somehow. For that we need to look in more detail at \(\varPi (k_0-1, k_1-1)\).

Fig. 7
figure 7

How the odd-odd case splits, based on the trailing two bits; the two even-even parts are isomorphic and parallel (by swapping the trailing two bits), with two paths H and \(H^\prime \), two cycles C, and six special vertices a11, b11, c01, d10, e00, and f00, all defined in the text

First, let us deal with the easier parts. The induction hypothesis gives us

  • a Hamiltonian path H for \(\varPi (k_0, k_1-2)\), from \(a = 0^{k_0}1^{k_1-2}\) to \(b = 1^{k_1-2}0^{k_0}\),

  • a Hamiltonian cycle C for \(N(k_0-1, k_1-1)\), visiting the (non-stutter) permutations \(c = 1^{k_1-2}0^{k_0-1}1\) and \(d = 0^{k_0-2}1^{k_1-1}0\), and

  • a Hamiltonian path \(H^\prime \) for \(\varPi (k_0-2, k_1)\), from \(e = 0^{k_0-2}1^{k_1}\) to \(f = 1^{k_1}0^{k_0-2}\).

Note that we have the edges \(c01 \sim b11\) and \(d10 \sim e00\) between these parts (swap underlined bits):

$$\begin{aligned} c01 = 1^{k_1-2}0^{k_0-1}\underline{10}1\sim & {} 1^{k_1-2}0^{k_0}11 = b11 \end{aligned}$$
(16)
$$\begin{aligned} d10 = 0^{k_0-2}1^{k_1-1}\underline{01}0\sim & {} 0^{k_0-2}1^{k_1}00 = e00 \end{aligned}$$
(17)

The two cycles \(C\cdot 01\) and \(C\cdot 10\) are isomorphic and parallel, and can incorporate the stutter permutations \(N(k_0-1, k_1,-1)\cdot \{\,01, 10\,\}\) as spurs. These two spurred cycles can be combined into one cycle, since the length of C is even (Lemma 6.2). The following lemma states this in general terms.

Lemma 12

Two parallel cycles of even length and parallel single spurs can be combined into one cycle. Furthermore, we can select a specific edge of a cycle without spurs to appear in the combined cycle.

Proof

See Fig. 8. The two cycles can be combined into one cycle by using all cross edges, alternating up and down. This works because the cycle has an even length. The spurs are incorporated by replacing the cross edge at its base with the edge to the neighboring spur tip, its cross edge, and the edge back to the corresponding neighbor in the other cycle.

Note that of each cycle (without spurs), every other edge is included in the combined cycle, such that no parallel edges are present. Thus, there are two versions, depending on which edge is selected at the start. \(\square \)

Fig. 8
figure 8

Parallel even-length cycles with single spurs (left); combined into one cycle (right)

Unfortunately, this cycle for \(\varPi (k_0-1, k_1-1)\cdot \{\,01, 10\,\}\) cannot be combined easily with the two paths to form a path for \(\varPi (k_0, k_1)\). We need to look into the structure of the two isomorphic even-even parts. They can be split further based on two more trailing bits (see Fig. 9). This reveals two parallel even-even subparts for \((k_0-1, k_1-3)\) on the left, four doubly parallel odd-odd subparts for \((k_0-2, k_1-2)\) in the middle, and two more parallel even-even subparts for \((k_0-3, k_1-1)\).

Fig. 9
figure 9

How the two parallel cycles for the even-even parts in Fig. 7 split, based on two more trailing bits

The stutter permutations are in the even-even subparts. The two cycles for \((k_0-1, k_1-3)\) can be combined with the stutter permutations as spurs according to Lemma 12. The same applies to the two cycles for \((k_0-3, k_1-1)\). Note these permutations u01, \(c^\prime 01\), v10, and \(d^\prime 10\):

$$\begin{aligned} u01 = 0^{k_0-2}1^{k_1-3}\underline{01}101\sim & {} 0^{k_0-2}1^{k_1-2}0101 = c^\prime 01 \\ v10 = 1^{k_1-2}0^{k_0-3}\underline{10}010\sim & {} 1^{k_1-2}0^{k_0-2}1010 = d^\prime 10 \end{aligned}$$

Permutations u01 and v10 are on the even-even cycles, and they are not at the base of a spur. If \(k_1=3\), then u is a stutter permutation itself. Similarly, if \(k_0=3\), then v is a stutter permutation. In those cases, the even-even subpart consists of one permutation only, and will be incorporated like the double cycle in other cases. According to Lemma 12, we can cover

  • \(\varPi (k_0-1, k_1-3) \cdot \{\,1101, 1110\,\}\) by a Hamiltonian cycle, including the stutter permutations of \(\varPi (k_0-1, k_1-3)\) and the edge \(u01 \sim u10\), and

  • \(\varPi (k_0-3, k_1-1) \cdot \{\,0001, 0010\,\}\) by a Hamiltonian cycle, including the stutter permutations of \(\varPi (k_0-3, k_1-1)\) and the edge \(v10 \sim v01\).

We now focus on the four doubly parallel paths for the odd-odd subparts:

$$\begin{aligned} \varPi (k_0-2, k_1-2) \cdot \{\,0101, 1001, 0110, 1010\,\} \end{aligned}$$

They can easily be combined into one cycle, but we need a path from c01 to d10, such that the two Hamiltonian cycles can be combined with it. To achieve this combination, we will see to it that this path will contain the edges \(c^\prime 01 \sim c^\prime 10\) and \(d^\prime 10 \sim d^\prime 01\), which are parallel to the edges on the cycles mentioned above.

Fig. 10
figure 10

Four doubly parallel paths (left) combined into one modular path (right)

The four paths have even length (Lemma 6.2). Figure 10 shows how isomorphic modules of length 2 can be used to walk from c01 to w. This module can be repeated, closing off with the module from w to d10. It is also clear that the desired edges \(c^\prime 01 \sim c^\prime 10\) and \(d^\prime 10 \sim d^\prime 01\) are on the combined path.

This completes the proof for the odd-odd case, and of Theorem 9. \(\square \)

5 The general case

Since [9] solved the general case when at least two \(k_i\) are odd, only the case of arity three or more with at most one odd \(k_i\) remains. In that case, there are (at least two) stutter permutations. We will prove a somewhat weaker result that looks like a promising step towards proving Conjecture 8.

Theorem 13

When the arity is at least 3 and at most one \(k_i\) is odd, the neighbor-swap graph of non-stutter permutations admits a disjoint cycle cover, that is, a set of vertex-disjoint cycles that visit all permutations exactly once.

To prove Conjecture 8, it now suffices to show that these cycles have suitable parallel edges. Experimental evidence shows an abundance of choices for cycles and such edges. For instance, our proof below constructs a cover for the 90 permutations of \(\varPi (2, 2, 2)\) with 6 cycles, where these cycles have 16 pairs of parallel edges.

We prove Theorem 13 by strong induction on n, distinguishing the cases all-even (Sect. 5.1) and all-but-one-even (Sect. 5.2), where the latter has one special case: \((\text {even}, 2, 1)\), handled in Sect. 5.3, which in turn involves the cases (even, 1, 1) in Sect. 5.4 and (odd, 2, 1) in Sect. 5.5. The induction hypothesis is that the theorem holds for all smaller n. Let k be the arity (number of non-zero \(k_i\)).

5.1 The all-even case

Split the graph based on the trailing two symbols x and y of each permutation. There are two cases, depending on whether the two trailing symbols are equal.

  • Case \(x = y\): This gives rise to k subgraphs with an all-even signature of arity k or \(k-1\). These have the stutter permutations of the original graph. The induction hypothesis gives us a disjoint cycle cover for the non-stutter permutations of each of these subgraphs.

  • Case \(x \ne y\): This gives rise to \(k \atopwithdelims ()2\) pairs of subgraphs of arity k that have exactly two odd \(k_i\). They have no stutter permutations. According to [9], each admits at least a Hamiltonian path (in fact, a cycle, except in the case of \((\text {even}, 1, 1)\)). Of each pair, one subgraph has permutations ending in xy, the other ending in yx. Hence, they are isomorphic and parallel. Thus, the two paths can be combined into one Hamiltonian cycle for the pair.

All these cycles together form a disjoint cycle cover of the non-stutter permutations. This completes the proof of the all-even case.

5.2 The all-but-one-even case, not \((\text {even}, 2, 1)\)

Split the graph based on the trailing symbol x of each permutation. There are two cases, depending on the parity of \(k_x\) (how often x occurs).

  • Case \(k_x\) is odd: This gives rise to one subgraph with all-even signature of arity k or \(k-1\). This has the stutter permutations of the original graph. The induction hypothesis (or Theorem 9 if the arity dropped to 2) gives us a disjoint cycle cover for the non-stutter permutations of this subgraph.

  • Case \(k_x\) is even: This gives rise to \(k-1\) subgraphs with arity k and exactly two odd \(k_i\). According to [9], each admits a Hamiltonian cycle, except when its signature is a permutation of \((\text {even}, 1, 1)\). This happens when the original graph has a signature that is a permutation of \((\text {even}, 2, 1)\). This actually happens twice in case of (2, 2, 1). We deal with the case \((\text {even}, 2, 1)\) in Sect. 5.3.

All these cycles together form a disjoint cycle cover of the non-stutter permutations. This completes the proof of the all-but-one-even case, except for \((\text {even}, 2, 1)\).

5.3 The special case \((\text {even}, 2, 1)\)

In [11], a non-inductive construction is given for a Hamiltonian cycle on the non-stutter permutations of \((\text {even}, 2, 1)\). We now present a simpler construction, that uses inductive constructions of special Hamiltonian paths for \((\text {even}, 1, 1)\) and \((\text {odd}, 2, 1)\).

As previously in Sect. 5.2, we split the graph based on the trailing symbol x. There are three cases (also see Fig. 11):

  • Case \(x=0\): This leads to a subgraph with signature \((\text {odd}, 2, 1)\), having no stutter permutations. It may admit a Hamiltonian cycle, but we will show in Sect. 5.5 that there is also a Hamiltonian path from \(a = 120^{k_0-1}1\) to \(b = 0210^{k_0-2}1\).

  • Case \(x=1\): This leads to a subgraph with signature \((\text {even}, 1, 1)\), having no stutter permutations. It admits a Hamiltonian path from \(c = 120^{k_0}\) to \(d = 0210^{k_0-1}\), which we will exhibit in Sect. 5.4.

  • Case \(x=2\): This leads to a subgraph with signature \((\text {even}, 2)\), contributing all stutter permutations. It admits a Hamiltonian cycle on the non-stutter permutations according to Theorem 9.

Fig. 11
figure 11

On the left N(4, 2, 1) split according to trailing symbol: \(N(4, 2)\cdot 2\) at the top, \(\varPi (4, 1, 1)\cdot 1\) at the back right, \(\varPi (3, 2, 1)\) in the front left; on the right \(\varPi (4, 1, 1)\) with special vertices marked

Note that in the original graph, we have the edges \(a0 \sim c1\) and \(b0 \sim d1\):

$$\begin{aligned} a0 = 120^{k_0-1}\underline{10}\sim & {} 120^{k_0}1 = c1 \\ b0 = 0210^{k_0-2}\underline{10}\sim & {} 0210^{k_0-1}1 = d1 \end{aligned}$$

So, the paths for \(x=0\) and \(x=1\) can be connected into one cycle. In its turn, this new cycle can be glued with the cycle for \(x=2\).

This completes the case \((\text {even}, 2, 1)\).

5.4 The special case \((\text {even}, 1, 1)\)

We need to establish a Hamiltonian path for \(\varPi (\text {even}, 1, 1)\) from \(c = 120^{k_0}\) to \(d = 0120^{k_0-1}\). The inductive structure of \(\varPi (\text {even}, 1, 1)\) is clear from Fig. 11 (right). The entire top line has permutations that end in 2; the top left-hand corner corresponds to \(10^{k_0}2\); the top right-hand corner to \(0^{k_0}12\). The right line below the top has permutations ending in 1; the bottom right-hand corner corresponds to \(20^{k_0}1\), and the bottom left-hand corner to \(210^{k_0}\). Incrementing \(k_0\) by 2 adds two lines at the top, and two lines at the right, which can be connected to the shown path as an L turned \(180^\circ \). This establishes a path from vertex c to d for \((\text {even}, 1, 1)\).

5.5 The special case \((\text {odd}, 2, 1)\)

Although a Hamiltonian path is known to exist for \(\varPi (\text {odd}, 2, 1)\), we want a path from \(a = 120^{k_0}1\) to \(b = 0210^{k_0-1}1\), in order to solve \((\text {even}, 2, 1)\). We split \(\varPi (\text {odd}, 2, 1)\) according to the trailing one or two symbols (Fig. 12, left):

Fig. 12
figure 12

On the left \(\varPi (3, 2, 1)\) split according to trailing symbols (see text); on the right \(\varPi (3, 1, 1)\cdot 1 \cup \varPi (3, 1)\cdot 12\) with special vertices marked

  • Case \(\underline{\quad }00\): This yields a subgraph with signature \((\text {odd}, 2, 1)\). By the induction hypothesis, we have a Hamiltonian path from \(a^\prime = 120^{k_0-2}1\) to \(b = 0210^{k_0-3}1\). It is shown in the front left of Fig. 12.

  • Case \(\underline{\quad }20\) and \(\underline{\quad }02\): These are two isomorphic and parallel subgraphs with signature \((\text {even}, 2)\). They include stutter permutations. Theorem 9 gives us a Hamiltonian cycle on the non-stutter permutations, and by Lemma 12 these cycles can be combined with the stutter permutations, into a single cycle without duplicates. They are shown at the top front of Fig. 12.

  • Case \(\underline{\quad }10\): This yields a subgraph with signature \((\text {even}, 1, 1)\). From Sect. 5.4 we obtain a Hamiltonian path from \(c^\prime \) to \(d^\prime \), that can be connected to \(\varPi (odd, 1, 1)\cdot 00\) via edges \(a^\prime \) and \(b^\prime \), to yield a cycle. It is shown at the bottom center of Fig. 12.

  • Cases \(\underline{\quad }12\) and \(\underline{\quad }1\): The first is a linear subgraph with signature \((\text {odd}, 1)\). The second concerns a subgraph with signature \((\text {odd}, 1, 1)\). For their union, there is a Hamiltonian path from a to b. The construction is similar to the one for (even, 1, 1) presented in Sect. 5.4. This path is shown in the back right of Fig. 12, and also to the far right.

The resulting cycles and paths can be combined, through appropriate parallel edges (there are many choices that work), into the desired path for \(\varPi (odd, 2, 1)\) from a to b.

This completes the proof of special case \((\text {odd}, 2, 1)\), and of Theorem 13. \(\square \)

6 Conclusion

Fifty years ago in [8], D. H. Lehmer conjectured that the neighbor-swap graph on permutations of any symbol (number) sequence admits a Lehmer path, that is, it admits an ‘imperfect’ Hamiltonian path possibly involving spurs.

Our main contribution is the insight that the stutter permutations can serve as the spur tips. This allowed us to reformulate the conjecture in terms of the existence of a Hamiltonian path on the set of non-stutter permutations (Conjecture 8), since each stutter permutation is at distance 1 from a non-stutter permutation. These stutter permutations also allowed us to present a more elegant proof of the necessary condition for the existence of Hamiltonian paths in the general case.

We have presented a proof for Lehmer’s conjecture in case of binary sequences involving just two symbols. That is, the set of non-stutter permutations of a binary sequence admits a Hamiltonian path. For the general case (ternary or higher arity), we proved the existence of a disjoint cycle cover on the set of non-stutter permutations. The part of our new conjecture that remains open is that the neighbor-swap graph on the non-stutter permutations of any sequence of arity at least three with at most one odd frequency \(k_i\) admits a Hamiltonian cycle.

Our inductive approach to the general case looks promising since there are actually many choices for disjoint cycle covers and the cycles have many parallel edges. To glue the cycles of our disjoint cycle cover into a single Hamiltonian cycle, careful attention is needed for administrative details about the presence of parallel edges among the cycles.

It should be noted that the approach of [9], based on linearizations of posets, does not work for the set of non-stutter permutations, since in general this set is not equal to the set of linearizations of some poset. However, another structure than posets might well be the key. Our approach possibly also opens the door for a new proof of the case with two or more odd frequencies.

We implemented and tested our constructions in Mathematica [14].