Cyclic Shift Problems on Graphs
CCyclic Shift Problems on Graphs (cid:63)
Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta
School of Information Science, Japan Advanced Institute of Science and Technology(JAIST), Japan. { saikwonkham,uehara,johnny } @jaist.ac.jp Abstract.
We study a new reconfiguration problem inspired by classicmechanical puzzles: a colored token is placed on each vertex of a givengraph; we are also given a set of distinguished cycles on the graph. Weare tasked with rearranging the tokens from a given initial configurationto a final one by using cyclic shift operations along the distinguished cy-cles. We first investigate a large class of graphs, which generalizes severalclassic puzzles, and we give a characterization of which final configura-tions can be reached from a given initial configuration. Our proofs areconstructive, and yield efficient methods for shifting tokens to reach thedesired configurations. On the other hand, when the goal is to find ashortest sequence of shifting operations, we show that the problem isNP-hard, even for puzzles with tokens of only two different colors.
Keywords: cyclic shift puzzle, permutation group, NP-hard problem
Recently, variations of reconfiguration problems have been attracting much in-terest, and several of them are being studied as important fundamental problemsin theoretical computer science [8]. Also, many real puzzles which can be mod-eled as reconfiguration problems have been invented and proposed by the puzzlecommunity, such as the 15-puzzle and Rubik’s cube. Among these, we focus ona popular type of puzzle based on cyclic shift operations: see Fig. 1. In thesepuzzles, we can shift some elements along predefined cycles as a basic operation,and the goal is to rearrange the pieces into a desired pattern.In terms of reconfiguration problems, this puzzle can be modeled as fol-lows. The input of the problem is a graph G = ( V, E ), a set of colors
Col = { , , . . . , c } , and one colored token on each vertex in V . We are also given a set C of cycles of G . The basic operation on G is called “shift” along a cycle C in C ,and it moves each token located on a vertex in C into the next vertex along C .This operation generalizes the token swapping problem, which was introducedby Yamanaka et al. [11], and has been well investigated recently. Indeed, whenwe restrict each cycle in C to have length two (each cycle would correspond to anedge in E ), the cyclic shift problem is equivalent to the token swapping problem. (cid:63) This work is partially supported by KAKENHI grant numbers 17H06287 and18H04091. a r X i v : . [ c s . CC ] S e p Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta
Fig. 1.
Commercial cyclic shift puzzles: Turnstile (left) and Rubik’s Shells (right)
In the mathematical literature, the study of permutation groups and theirgenerators has a long history. An important theorem by Babai [1] states thatthe probability that two random permutations of n objects generate either thesymmetric group S n (i.e., the group of all permutations) or the alternating group A n (i.e., the group of all even permutations) is 1 − /n + O ( n ). However, thetheorem says nothing about the special case where the generators are cycles.In [4], Heath et al. give a characterization of the permutations that, togetherwith a cycle of length n , generate either A n or S n , as opposed to a smallerpermutation group. On the other hand, in [7], Jones shows that A n and S n are the only finite primitive permutation groups containing a cycle of length n − π in the group is decidable in polynomial time, and an expressionfor π in terms of the generators is also computable in polynomial time [2].In contrast, Jerrum showed that computing the distance between two givenpermutations in terms of two generators is PSPACE-complete [6]. However, thegenerators used for the reduction are far from being cycles.In this paper, after giving some definitions (Section 2), we study the configu-ration space of a large class of cyclic shift problems which generalize the puzzlesin Fig. 1 (Section 3). We show that, except for one special case, the permutationgroup generated by a given set of cycles is S n if at least one of the cycles haseven length, and it is A n otherwise. This result is in agreement with Babai’stheorem [1], and shows a similarity with the configuration space of the (general-ized) 15-puzzle [10]. Moreover, our proofs in Section 3 are constructive, and yieldpolynomial upper bounds on the number of shift operations required to reacha given configuration. This is contrasted with Section 4, where we show thatfinding a shortest sequence of shift operations to obtain a desired configurationis NP-hard, even for puzzles with tokens of only two different colors. yclic Shift Problems on Graphs 3 Let G = ( V, E ) be a finite, simple, undirected graph, where V is the vertex set,with n = | V | , and E is the edge set. Let Col = { , , . . . , c } be a set of colors,where c is a constant. A token placement for G is a function f : V → Col : thatis, f ( v ) represents the color of the token placed on the vertex v . Without loss ofgenerality, we assume f to be surjective.Let us fix a set C of cycles in G (note that C does not necessarily containall cycles of G ). Two distinct token placements f and f (cid:48) of G are adjacent with respect to C if the following two conditions hold: (1) there exists a cycle C = ( v , v , . . . , v j ) in C such that f (cid:48) ( v i +1 ) = f ( v i ) and f (cid:48) ( v ) = f ( v j ) or f (cid:48) ( v i ) = f ( v i +1 ) and f (cid:48) ( v j ) = f ( v ) for 1 ≤ i ≤ j , and (2) f (cid:48) ( w ) = f ( w ) for allvertices w ∈ V \ { v , . . . , v i } . In this case, we say that f (cid:48) is obtained from f by shifting the tokens along the cycle C . If an edge e ∈ E is not spanned by anycycle in C , e plays no role in shifting tokens. Therefore, without loss of generality,we assume that every edge is spanned by at least one cycle in C .We say that two token placements f and f are compatible if, for eachcolor c (cid:48) ∈ Col , we have (cid:12)(cid:12) f − ( c (cid:48) ) (cid:12)(cid:12) = (cid:12)(cid:12) f − ( c (cid:48) ) (cid:12)(cid:12) . Obviously, compatibility is anequivalence relation on token placements, and its equivalence classes are called compatibility classes for G and Col . For a compatibility class P and a cycle set C , we define the token-shifting graph of P and C as the undirected graph withvertex set P , where there is an edge between two token placements if and onlyif they are adjacent with respect to C . A walk in a token-shifting graph startingfrom f and ending in f (cid:48) is called a shifting sequence between f and f (cid:48) , and thedistance between f and f (cid:48) , i.e., the length of a shortest walk between them, isdenoted as dist( f, f (cid:48) ) (if there is no walk between f and f (cid:48) , their distance isdefined to be ∞ ). If dist( f, f (cid:48) ) < ∞ , we write f (cid:39) f (cid:48) .For a given number of colors c , we define the c -Colored Token Shift problemas follows. The input is a graph G = ( V, E ), a cycle set C for G , two compatibletoken placements f and f t (with colors drawn from the set Col = { , , . . . , c } ),and a non-negative integer (cid:96) . The goal is to determine whether dist( f , f t ) ≤ (cid:96) holds. In the case that (cid:96) is not given, we consider the c -Colored Token Shiftproblem as an optimization problem that aims at computing dist( f , f t ). For the purpose of this section, the vertex set of the graph G = ( V, E ) willbe V = { , , . . . , n } , and the number of colors will be c = n , so that Col = V , and a token placement on G can be interpreted as a permutation of V .To denote a permutation π of V , we can either use the one-line notation π =[ π (1) π (2) . . . π ( n )], or we can write down its cycle decomposition: for instance,the permutation [3 6 4 1 7 2 5] can be expressed as the product of disjoint cycles(1 3 4)(2 6)(5 7).Note that, given a cycle set C , shifting tokens along a cycle ( v , v , . . . , v j ) ∈ C corresponds to applying the permutation ( v v . . . v j ) or its inverse ( v j v j − . . . v ) Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta to V . The set of token placements generated by shifting sequences starting fromthe “identity token placement” f = [1 2 . . . n ] is therefore a permutation groupwith the composition operator, which we denote by H C , and we call it configura-tion group generated by C . Since we visualize permutations as functions mappingvertices of G to colors (and not the other way around), it makes sense to composechains of permutations from right to left, contrary to the common convention inthe permutation group literature. So, for example, if we start from the identitytoken placement for n = 5 and we shift tokens along the cycles (1 2 3) and (3 4 5)in this order, we obtain the token placement(1 2 3)(3 4 5) = [2 3 1 4 5] [1 2 4 5 3] = [2 3 4 5 1] = (1 2 3 4 5) . (Had we composed permutations from left to right, we would have obtained thetoken placement [2 4 1 5 3] = (1 2 4 5 3) as a result.)One of our goals in this section is to determine the configuration groups H C generated by some classes of cycle sets C . Our choice of C will be inspiredby the puzzles in Fig. 1, and will consist of arrangements of cycles that shareeither one or two adjacent vertices. As we will see, except in one special case,the configuration groups that we obtain are either the symmetric group S n (i.e.,the group of all permutations) or the alternating group A n (i.e., the group of alleven permutations), depending on whether the cycle set C contains at least oneeven-length cycle or not: indeed, observe that a cycle of length j corresponds toan even permutation if and only if j is odd.Note that the set of permutations in the configuration group H C coincideswith the connected component of the token-shifting graph (as defined in theprevious section) that contains f . The other connected components are simplygiven by the cosets of H C in S n (thus, they all have the same size), while thenumber of connected components of the token-shifting graph is equal to theindex of H C in S n , i.e., n ! / | H C | .The other goal of this section is to estimate the diameter of the token-shiftinggraph, i.e., the maximum distance between any two token placements f and f t such that f (cid:39) f t . To this end, we state some basic preliminary facts, which arefolklore, and can be proved by mimicking the “bubble sort” algorithm. Proposition 1.1.
The n -cycle (1 2 . . . n ) and the transposition (1 2) can generate any per-mutation of { , , . . . , n } in O ( n ) shifts. The n -cycle (1 2 . . . n ) and the 3-cycle (1 2 3) can generate any evenpermutation of { , , . . . , n } in O ( n ) shifts. The 3-cycles (1 2 3) , (2 3 4) , . . . , ( n − n − n ) can generate any evenpermutation of { , , . . . , n } in O ( n ) shifts. (cid:117)(cid:116) All upper bounds given in Proposition 1 are worst-case asymptotically optimal(refer to [6] for some proofs). Of course, the two cycles generate strictly more than A n (hence S n ) if and only if n is even; however, we will only apply Proposition 1.2 to generate even permutations.yclic Shift Problems on Graphs 5 We first investigate the case where the cycle set C contains exactly two cycles α and β , either of the form α = (1 2 . . . a ) and β = ( a a +1 . . . n ) with 1 < a < n ,or of the form α = (1 2 . . . a ) and β = ( a − a a + 1 . . . n ), with 1 < a ≤ n .The first puzzle is called ( a, b ) -puzzle , where n = a + b −
1, and thesecond one is called ( a, b ) -puzzle , where n = a + b − a > b > α and β , respectively).See Fig. 2 for some examples. Note that the Turnstile puzzle in Fig. 1 (left) canbe regarded as a 2-connected (6 , α βα β
123 4 56 7 8 913 12 11 10123 4 5 611 710 89
Fig. 2.
A 1-connected (5 , , Theorem 1.
The configuration group of a 1-connected ( a, b ) -puzzle is A n if both a and b are odd, and it is S n otherwise. Any permutation in the configurationgroup can be generated in O ( n ) shifts.Proof. Observe that the commutator of α and β − is the 3-cycle α − βαβ − =( a − a a + 1). So, we can apply Proposition 1.2 to the n -cycle αβ = (1 2 . . . n )and the 3-cycle ( a − a a + 1) to generate any even permutation in O ( n ) shifts.If a and b are odd, then α and β are even permutations, and therefore cannotgenerate any odd permutation.On the other hand, if a is even (the case where b is even is symmetric),then the a -cycle α is an odd permutation. So, to generate any odd permutation π ∈ S n , we first generate the even permutation πα in O ( n ) shifts, and then wedo one extra shift along the cycle α − . (cid:117)(cid:116) Our first observation about 2-connected ( a, b )-puzzles is that the compositionof α − and β is the ( n − α − β = ( a − a − . . . a a + 1 . . . n ), whichexcludes only the element a −
1. Similarly, αβ − = (1 2 . . . a − n n − . . . a +1),which excludes only the element a . We will write γ and γ as shorthand for α − β Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta and αβ − respectively, and we will use the permutations γ and γ to conjugate α and β , thus obtaining different a -cycles and b -cycles. Lemma 1.
In a 2-connected (3 , b ) -puzzle, any even permutation can be gener-ated in O ( n ) shifts.Proof. If we conjugate the 3-cycle α − by the inverse of γ , we obtain the 3-cycle γ α − γ − = (2 3 4). By applying Proposition 1.2 to the ( n − β and the3-cycle (2 3 4), we can generate any even permutation of V \ { } in O ( n ) shifts.Let π ∈ A n be an even permutation of V . In order to generate π , we firstmove the correct token π (1) to position 1 in O ( n ) shifts, possibly scrambling therest of the tokens: let σ be the resulting permutation. If σ is even, then σ − π isan even permutation of V \ { } , and we can generate it in O ( n ) shifts as shownbefore, obtaining π .On the other hand, if σ is odd, then one of the generators α and β must beodd, too. Since α is a 3-cycle, it follows that β is odd. In this case, after placingthe correct token in position 1 via σ , we shift the rest of the tokens along β , andthen we follow up with β − σ − π , which is an even permutation of V \ { } , andcan be generated it in O ( n ) shifts. Again, the result is σββ − σ − π = π . (cid:117)(cid:116) Lemma 2.
In a 2-connected ( a, b ) -puzzle with a ≥ and b ≥ , any even per-mutation can be generated in O ( n ) shifts.Proof. As shown in Fig. 3, the conjugate of β by γ is the b -cycle δ = γ − βγ = ( a a + 1 . . . n − a − , and the conjugate of β − by γ is the b -cycle δ = γ − β − γ = ( n n − . . . a + 2 a a − a − . Their composition is δ δ = (1 a a − a − n )( a + 1 a + 2), and therefore( δ δ ) is the 3-cycle (1 a − a ). Conjugating this 3-cycle by α − , we finallyobtain the 3-cycle τ = α ( δ δ ) α − = (1 2 a − τ has been generatedin a number of shifts independent of n . Now, since the 3-cycle τ and the ( n − γ induce a 2-connected (3 , n − V , we can apply Lemma 1 togenerate any even permutation of V in O ( n ) shifts. (cid:117)(cid:116) Theorem 2.
The configuration group of a 2-connected ( a, b ) -puzzle is: Isomorphic to S n − = S if a = b = 4 . A n if both a and b are odd. S n otherwise.Any permutation in the configuration group can be generated in O ( n ) shifts. If g and h are two elements of a group, the conjugate of g by h is defined as h − gh .In the context of permutation groups, conjugation by any h is an automorphism thatpreserves the cycle structure of permutations [9, Theorem 3.5].yclic Shift Problems on Graphs 7
123 4 56 7 8 913 12 11 10 δ δ
23 4 6 7 8 913 12 11 101 5 δ δ Fig. 3.
Some permutations constructed in the proof of Lemma 2
Proof.
By the symmetry of the puzzle, we may assume a ≤ b . The case with a = 2 is equivalent to Proposition 1.1, so let a ≥
3. If a (cid:54) = 4 or b (cid:54) = 4, thenLemmas 1 and 2 apply, hence we can generate any even permutation in O ( n )shifts: the configuration group is therefore at least A n . Now we reason as inTheorem 1: if a and b are odd, then α and β are even permutations, and cannotgenerate any odd one. If a is even (the case where b is even is symmetric), then α is an odd permutation. In this case, to generate any odd permutation π ∈ S n ,we first generate the even permutation πα in O ( n ) shifts, and then we do onemore shift along the cycle α − to obtain π .The only case left is a = b = 4. To analyze the 2-connected (4 , ψ : S → S defined on a generating set of S as follows (cf. [9, Corollary 7.13]): ψ ((1 2)) = (1 5)(2 3)(4 6) , ψ ((1 3)) = (1 4)(2 6)(3 5) ,ψ ((1 4)) = (1 3)(2 4)(5 6) , ψ ((1 5)) = (1 2)(3 6)(4 5) ,ψ ((1 6)) = (1 6)(2 5)(3 4) . Because ψ is an automorphism, the subgroup of S generated by α and β isisomorphic to the subgroup generated by the permutations ψ ( α ) and ψ ( β ). Since α = (1 2 3 4) = (1 2)(1 3)(1 4) and β = (3 4 5 6) = (1 3)(1 4)(1 5)(1 6)(1 3),and recalling that ψ ( π π ) = ψ ( π ) ψ ( π ) for all π , π ∈ S , we have: ψ ( α ) = ψ ((1 2)) ψ ((1 3)) ψ ((1 4)) = [1 5 6 4 3 2] = (2 5 3 6) and ψ ( β ) = ψ ((1 3)) ψ ((1 4)) ψ ((1 5)) ψ ((1 6)) ψ ((1 3)) = [3 1 5 4 2 6] = (1 3 5 2) . Note that the new generators ψ ( α ) and ψ ( β ) both leave the token 4 in place, andso they cannot generate a subgroup larger than S (up to isomorphism). On theother hand, we have ψ ( α ) ψ ( β ) = (1 6 2). This 3-cycle, together with the 4-cycle ψ ( α ), induces a 2-connected (3 , { , , , , } : as shown before, theconfiguration group of this puzzle is (isomorphic to) S . We conclude that theconfiguration group of the 2-connected (4 , S , as well.A given permutation π ∈ S is in the configuration group if and only if ψ ( π )leaves the token 4 in place. (cid:117)(cid:116) Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta
Let us generalize the ( a, b )-puzzle to larger numbers of cycles. (As far as theauthors know, there are commercial products that have 2, 3, 4, and 6 cycles.)We say that two cycles are properly interconnected if they share exactly onevertex, of if they share exactly two vertices which are consecutive in both cycles.Note that all 1-connected and 2-connected ( a, b )-puzzles consist of two properlyinterconnected cycles. Given a set of cycles C in a graph G = ( V, E ), let usdefine the interconnection graph ˆ G = ( C , ˆ E ), where there is an (undirected) edgebetween two cycles of C if and only if they are properly interconnected.Let us assume | V | > C consist of k cycles of lengths n , n , . . . , n k , respectively. We say that C induces a generalized ( n , n , . . . , n k ) -puzzle on V if there is a subset C (cid:48) ⊆ C such that:(1) C (cid:48) contains at least two cycles;(2) the induced subgraph ˆ G [ C (cid:48) ] is connected;(3) each vertex of G is contained in at least one cycle in C (cid:48) .When we fix such a subset C (cid:48) , the cycles in C (cid:48) are called relevant cycles , and thevertices of G that are shared by two properly interconnected relevant cycles arecalled relevant vertices for those cycles. See Fig. 4 for an example of a generalizedpuzzle. Fig. 4.
A generalized puzzle where any permutation can be generated in O ( n ) shifts,due to Theorem 3. Note that the blue cycle is the only cycle of even length, and isnot properly interconnected with any other cycle. Also, the two red cycles and the twogreen cycles intersect each other but are not properly interconnected. The next two lemmas are technical; their proof is found in the Appendix.
Lemma 3.
In a generalized puzzle with three relevant cycles, C (cid:48) = { C , C , C } ,such that C and C induce a 2-connected (4 , -puzzle, any permutation involv-ing only vertices in C and C can be generated in O ( n ) shifts. (cid:117)(cid:116) yclic Shift Problems on Graphs 9 Lemma 4.
Let V = { , . . . , n } , and let W = ( w , . . . , w m ) ∈ V m be a sequencesuch that each element of V appears in W at least once, and any three consecutiveelements of W are distinct. Then, the set of 3-cycles C = { ( w i − w i w i +1 ) |
The configuration group of a generalized ( n , n , . . . , n k ) -puzzle is A n if n , n , . . . , n k are all odd, and it is S n otherwise. Any permutation in theconfiguration group can be generated in O ( n ) shifts.Proof. Observe that it suffices to prove that the given cycles can generate anyeven permutation in O ( n ) shifts. Indeed, if all cycles have odd length, theycannot generate any odd permutation. On the other hand, if there is a cycle ofeven length and we want to generate an odd permutation π , we can shift tokensalong that cycle, obtaining an odd permutation σ , and then we can generate theeven permutation σ − π in O ( n ) shifts, obtaining π .Let us fix a set of k (cid:48) ≥ C (cid:48) ⊆ C : we will show how togenerate any even permutation by shifting tokens only along relevant cycles.By properties (2) and (3) of generalized puzzles, there exists a walk W on G that visits all vertices (possibly more than once), traverses only edges of relevantcycles, and transitions from one relevant cycle to another only if they are properlyinterconnected, and only through a relevant vertex shared by them. We will nowslightly modify W so that it satisfies the hypotheses of Lemma 4, as well assome other conditions. Namely, if w i − , w i , w i +1 are any three vertices that areconsecutive in W , we would like the following conditions to hold:(1) w i − , w i , w i +1 are all distinct (this is the condition required by Lemma 4);(2) either w i − and w i are in the same relevant cycle, or w i and w i +1 are in thesame relevant cycle;(3) w i − and w i +1 are either in the same relevant cycle, or in two properlyinterconnected relevant cycles.To satisfy all conditions, it is sufficient to let W do a whole loop around a relevantcycle before transitioning to the next (note that Lemma 4 applies regardless ofthe length of W ). The only case where this is not possible is when W hasto go through a relevant 2-cycle C = ( u u ) that is a leaf in the inducedsubgraph ˆ G [ C (cid:48) ], such that C shares exactly one relevant vertex, say u , withanother relevant cycle C (cid:48) = ( v u v v . . . ). To let W cover C in a waythat satisfies the above conditions, we set either W = ( . . . , v , u , u , v , . . . )or W = ( . . . , v , u , u , v , . . . ): that is, we skip u after visiting u . After thismodification, W is no longer a walk on G , but it satisfies the hypotheses ofLemma 4, as well as the three conditions above.We will now show that the 3-cycle ( w i − w i w i +1 ) can be generated in O ( n )shifts, for all 1 < i < | W | . By Lemma 4, we will therefore conclude that anyeven permutation of V can be generated in O ( n ) · O ( n ) = O ( n ) shifts. Dueto conditions (2) and (3), we can assume without loss of generality that w i − and w i are both in the same relevant cycle C , and that w i +1 is either in C orin a different relevant cycle C which is properly interconnected with C . In the first case, by property (1) of generalized puzzles, there exists another relevantcycle C properly interconnected with C . So, in all cases, C and C induce a1-connected or a 2-connected ( | C | , | C | )-puzzle.That the 3-cycle ( w i − w i w i +1 ) can be generated in O ( n ) shifts now followsdirectly from Theorems 1 and 2, except if | C | = | C | = 4 and C and C shareexactly two vertices: indeed, the 2-connected (4 , V > C , which is properly interconnected with C or C . Our claim now follows from Lemma 3. (cid:117)(cid:116) In this section, we show that the 2-Colored Token Shift problem is NP-hard.That is, for a graph G = ( V, E ), cycle set C , two token placements f and f t for G , and a non-negative integer (cid:96) , it is NP-hard to determine if dist( f , f t ) ≤ (cid:96) . Theorem 4.
The 2-Colored Token Shift problem is NP-hard.Proof.
We will give a polynomial-time reduction from the NP-complete problem3-Dimensional Matching, or 3DM [3]: given three disjoint sets X , Y , Z , each ofsize m , and a set of triplets T ⊆ X × Y × Z , does T contain a matching, i.e., asubset M ⊆ T of size exactly m such that all elements of X , Y , Z appear in M ?Given an instance of 3DM ( X, Y, Z, T ), with n = | T | , we construct the in-stance of the 2-Colored Token Shift problem illustrated in Fig. 5.The vertex set of G = ( V, E ) includes the sets X , Y , Z (shown with agreen background in the figure: these will be called green vertices ), as wellas the vertex u . Also, for each triplet ˆ t i = ( x, y, z ) ∈ T , with 1 ≤ i ≤ n ,the vertex set contains three vertices t i, , t i, , t i, (shown with a yellow back-ground in the figure: these will be called yellow vertices ), and the cycle set C has the three cycles ( u, t i, , t i, , t i, , x ), ( u, t i, , t i, , t i, , y ), and ( u, t i, , t i, , t i, , z )(drawn in blue in the figure). Finally, we have the vertex w , and the vertices v , v , . . . , v n − m ; for each i ∈ { , , . . . , n } , the cycle set C contains the cy-cle ( t i, , t i, , t i, , v , v , . . . , v n − m , w ) (drawn in red in the figure). In the initialtoken placement f , there are black tokens on the 3 n vertices of the form t i,j ,and white tokens on all other vertices. In the final token placement f t , there isa total of 3 m black tokens on all the vertices in X , Y , Z , plus 3 n − m blacktokens on v , v , . . . , v n − m ; all other vertices have white tokens. With thissetup, we let (cid:96) = 3 n .It is easy to see that, if the 3DM instance has a matching M = { ˆ t i , ˆ t i , . . . , ˆ t i m } ,then dist( f , f t ) ≤ (cid:96) . Indeed, for each ˆ t i j = ( x j , y j , z j ), with 1 ≤ j ≤ m , we canshift tokens along the three blue cycles containing the yellow vertices t i j , , t i j , , t i j , , thus moving their three black tokens into the green vertices x j , y j , and z j .Since M is a matching, these 3 m shifts eventually result in X , Y , and Z beingcovered by black tokens. Finally, we can shift the 3 n − m black tokens corre-sponding to triplets in T \ M along red cycles, moving them into the vertices v , yclic Shift Problems on Graphs 11 ZYX v m − n v. . .. . . v v wu v m − n v. . . v v wu , t , t , t , t , t , t. . . n, t n, t n, t ZYX . . . , t , t , t , t , t , t. . . n, t n, t n, t Fig. 5.
The initial token placement f (left) and the final token placement f t (right) v , . . . , v n − m . Clearly, this is a shifting sequence of length 3 n = (cid:96) from f to f t . We will now prove that, assuming that dist( f , f t ) ≤ (cid:96) , the 3DM instancehas a matching. Note that each shift, no matter along which cycle, can moveat most one black token from a yellow vertex to a non-yellow vertex. Since in f there are (cid:96) = 3 n black tokens on yellow vertices, and in f t no token is on ayellow vertex, it follows that each shift must cause exactly one black token tomove from a yellow vertex to a non-yellow vertex, and no black token to moveback into a yellow vertex.This implies that no black token should ever reach vertex u : if it did, itwould eventually have to be moved to some other location, because u does nothold a black token in f t . However, the black token in u cannot be shifted backinto a yellow vertex, and therefore it will be shifted into a green vertex along ablue cycle. Since every shift must cause a black token to leave the set of yellowvertices, such a token will move into u : we conclude that u will always containa black token, which is a contradiction. Similarly, we can argue that the vertex w should never hold a black token.Let us now focus on a single triplet of yellow vertices t i, , t i, , t i, . Exactlythree shifts must involve these vertices, and they must result in the three blacktokens leaving such vertices. Clearly, this is only possible if the three black tokensare shifted in the same direction. If they are shifted in the direction of t i, (i.e.,rightward in Fig. 5), they must move into green vertices (because they cannot go into w ); if they are shifted in the direction of t i, (i.e., leftward in Fig. 5),they must move into v (because they cannot go into u ).Note that, if a black token ever reaches a green vertex, it can no longer bemoved: any shift involving such a token would move it back into a yellow vertexor into u . It follows that the only way of filling all the green vertices with blacktoken is to select a subset of exactly m triplets of yellow vertices and shift eachof their black tokens into a different green vertex. These m triplets of yellowvertices correspond to a matching for the 3DM instance. (cid:117)(cid:116) In the above reduction, we can easily observe that the final token placement f t can always be reached from the initial token placement f in a polynomialnumber of shifts. Therefore, for this particular set of instances, the 2-ColoredToken Shift problem is in NP. The same is also true of the puzzles introducedin Section 3, due to the polynomal upper bound given by Theorem 3. However,we do not know whether this is true for the c -Colored Token Shift problem ingeneral, even assuming c = 2. A theorem of Helfgott and Seress [5] implies that,if f (cid:39) f t , the distance between f and f t has a quasi-polynomial upper bound;this, however, is insufficient to conclude that the problem is in NP. On theother hand, it is not difficult to see that the c -Colored Token Shift problem is inPSPACE; characterizing its computational complexity is left as an open problem.It would also be interesting to establish if the problem remains NP-hard whenrestricted to planar graphs or to graphs of constant maximum degree. References
1. L´aszl´o Babai. The Probability of Generating the Symmetric Group.
Journal ofCombinatorial Theory (Series A), 52:148–153, 1989.2. Merrick Furst, John Hopcroft, and Eugene Luks. Polynomial-Time Algorithms forPermutation Groups. In
Proceedings of the 21st Annual Symposium on Foundationsof Computer Science , 36–41, 1980.3. Michael R. Garey and David S. Johnson.
Computers and Intractability: A Guideto the Theory of NP-Completeness . W. H. Freeman and Company, 1979.4. Daniel Heath, I. M. Isaacs, John Kiltinen, and Jessica Sklar. Symmetric and Al-ternating Groups Generated by a Full Cycle and Another Element.
The AmericanMathematical Monthly , 116(5):447–451, 2009.5. Harald A. Helfgott and ´Akos Seress. On the Diameter of Permutation Groups.
Annals of Mathematics , 179(2):611–658, 2014.6. Mark R. Jerrum. The Complexity of Finding Minimum-Length Generator Se-quences.
Theoretical Computer Science , 36:265–289, 1985.7. Gareth A. Jones. Primitive Permutation Groups Containing a Cycle.
Bulletin ofthe Australian Mathematical Society , 89(1):159–165, 2014.8. Naomi Nishimura. Introduction to Reconfiguration.
Algorithms , 11(4):1–25, 2018.9. Joseph J. Rotman.
An Introduction to the Theory of Groups . Springer-Verlag, 4thedition, 1995.10. Richard M. Wilson. Graph Puzzles, Homotopy, and the Alternating Group.
Journalof Combinatorial Theory (Series B), 16:86–96, 1974.yclic Shift Problems on Graphs 1311. Katsuhisa Yamanaka, Takashi Horiyama, J. Mark Keil, David Kirkpatrick, YotaOtachi, Toshiki Saitoh, Ryuhei Uehara, and Yushi Uno. Swapping Colored Tokenson Graphs.
Theoretical Computer Science , 729:1–10, 2018.4 Kwon Kham Sai, Ryuhei Uehara, and Giovanni Viglietta
Appendix
Additional Figures
Fig. 6.
Some cyclic shift puzzles with two (not properly interconnected) cycles
Fig. 7.
More cyclic shift puzzles: Twiddler (left) and a puzzle found in the video gameHaunted Manor 2 (right)
Missing ProofsLemma 3.
In a generalized puzzle with three relevant cycles, C (cid:48) = { C , C , C } ,such that C and C induce a 2-connected (4 , -puzzle, any permutation involv-ing only vertices in C and C can be generated in O ( n ) shifts.Proof. Let α = (1 2 3 4) and β = (3 4 5 6) be the permutations correspondingto shifting tokens along C and C , respectively. As in Section 3.1, we set γ = yclic Shift Problems on Graphs 15 α − β = (1 4 5 6 2) and γ = αβ − = (1 2 3 6 5). Since we are assuming that | V | >
6, there must be a seventh vertex, and shifting along C corresponds to apermutation of the form τ = ( . . . . . . ).We will prove that it is always possible to generate a transposition of the form(3 x ), with x ∈ { , , , , } , in O ( n ) shifts. Indeed, such a transposition, to-gether with the 5-cycle γ , induces a 1-connected (2 , { , , , , , } .Our lemma will thus follow from Theorem 1 and the fact that, in a 1-connected(2 , | C | (cid:54) = 4, or if C is 1-connected with C or C , then the transposition (3 4)can be generated in O ( n ) shifts, due to Theorems 1 and 2. So, we may assumethat | C | = 4, and C is properly interconnected with C and shares exactly twovertices with it. Perhaps, C shares at least two vertices with C , as well. Theonly possible configurations, up to symmetry, are the following:(1) τ = (3 4 7 8). Then, τ and γ induce a 1-connected (4 , V , andcan generate the transposition (3 4) by Theorem 1.(2) τ = (5 6 7 8). Then, τ and γ induce a 2-connected (4 , V \ { } ,and can generate the transposition (3 5) by Theorem 2.(3) τ = (1 7 3 4). In this case, (3 2) = τ − ατ α .(4) τ = (1 3 4 7). In this case, (3 4) = αβ − α − τ βτ .(5) τ = (1 3 6 7). In this case, (3 5) = β − ατ − αβτ .(6) τ = (1 6 3 7). In this case, (3 1) = αβα − βτ − βτ .(7) τ = (2 6 3 7). In this case, (3 4) = α τ ατ .(8) τ = (2 3 6 7). In this case, (3 1) = τ − β − αβα − τ α . (cid:117)(cid:116) Lemma 4.
Let V = { , . . . , n } , and let W = ( w , . . . , w m ) ∈ V m be a sequencesuch that each element of V appears in W at least once, and any three consecutiveelements of W are distinct. Then, the set of 3-cycles C = { ( w i − w i w i +1 ) |