Prefix-reversal Gray codes Elena Konstantinova Sobolev Institute of Mathematics joint work with Alexey Medvedev, CEU Budapest
Modern Trends in Algebraic Graph Theory Villanova University, USA, June 2–5, 2014 Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
1 / 18
Binary reflected Gray code (BRGC) Gray code [F. Gray, 1953, U.S. Patent 2,632,058] The reflected binary code, also known as Gray code, is a binary numeral system where two successive values differ in only one bit.
Example n = 2: n = 3:
00 01 | 11 10 000 001 011 010 | 110 111 101 100
BRGC is related to Hamiltonian cycles of hypercube graphs b b
bb
b b
b b
110
10 bb
bb11
010
bb
bb
011 100
bb
00
bb
bb
01 000
Elena Konstantinova
Prefix-reversal Gray codes
111
101
bb
001 Villanova–2014
2 / 18
Gray codes: generating combinatorial objects Gray codes Now the term Gray code refers to minimal change order of combinatorial objects.
[D.E. Knuth, The Art of Computer Programming, Vol.4 (2010)] Knuth recently surveyed combinatorial generation: Gray codes are related to efficient algorithms for exhaustively generating combinatorial objects. (tuples, permutations, combinations, partitions, trees)
[P. Eades, B. McKay, An algorithm of generating subsets of fixed size with a strong minimal change property (1984)] They followed to Gray‘s approach to order the k–combinations of an n element set. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
3 / 18
Gray codes: generating permutations [V.L. Kompel’makher, V.A. Liskovets, Successive generation of permutations by means of a transposition basis (1975)] Q: Is it possible to arrange permutations of a given length so that each permutation is obtained from the previous one by a transposition? A: YES
[S. Zaks, A new algorithm for generation of permutations (1984)] In Zaks’ algorithm each successive permutation is generated by reversing a suffix of the preceding permutation. Start with In = [12 . . . n] and in each step reverse a certain suffix. Let ζn is the sequence of sizes of these suffixes defined by recursively as follows: ζ2 = 2 ζn = (ζn−1 n)n−1 ζn−1 , n > 2, where a sequence is written as a concatenation of its elements. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
4 / 18
Zaks’ algorithm: examples If n = 2 then ζ2 = 2 and we have: [12] [21] If n = 3 then ζ3 = 23232 and we have: [123] [231] [312] [132] [213] [321] If n = 4 then ζ4 = 23232423232423232423232 and we have: [1234] [2341] [3412] [4123] [1243] [2314] [3421] [4132] [1342] [2413] [3124] [4231] [1324] [2431] [3142] [4213] [1423] [2134] [3241] [4312] [1432] [2143] [3214] [4321] Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
5 / 18
Greedy Pancake Gray codes: generating permutations [A. Williams, J. Sawada, Greedy pancake flipping (2013)] Take a stack of pancakes, numbered 1, 2, ..., n by increasing diameter, and repeat the following: Flip the maximum number of topmost pancakes that gives a new stack.
[1234] [4321] [2341] [1432] [3412] [2143] [4123] [3214] [2314] [4132] [3142] [2413] [1423] [3241] [4231] [1324] [3124] [4213] [1243] [3421] [2431] [1342] [4312] [2134]
Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
6 / 18
Prefix–reversal Gray codes: generating permutations Each ’flip’ is formally known as prefix–reversal.
The Pancake graph Pn is the Cayley graph on the symmetric group Symn with generating set {ri ∈ Symn , 1 6 i < n}, where ri is the operation of reversing the order of any substring [1, i ], 1 < i 6 n, of a permutation π when multiplied on the right, i.e., [π1 . . . πi πi +1 . . . πn ]ri = [πi . . . π1 πi +1 . . . πn ].
Williams’ prefix–reversal Gray code: (rn rn−1 )n Flip the maximum number of topmost pancakes that gives a new stack.
Zaks’ prefix–reversal Gray code: (r3 r2 )3 Flip the minimum number of topmost pancakes that gives a new stack. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
7 / 18
Two scenarios of generating permutations: Zaks | Williams r4 !
r2 !
!
!
r2
!
r4
r3
!
!
!
!
r3 r2 !
r3 !
!
r4
r3
!
r2 !
r4
!
!
!
!
r3
!
r3
r4
r2 !
r3
r3 !
(a) Zaks’ code in P4
r4 !
r2
r3
!
r4
r3
!
r4 !
!
!
!
r2
!
r2
r2 !
r4 r3
!
!
!
!
r2
!
r4
r2 !
r4
r3
r3
!
r4
r4
!
r2 !
!
r4
!
!
r2 !
r4
!
r4
r3
r2
r2
r3
!
r3
!
!
!
r3
(b) Williams’ code in P4
Resume: both approaches are based on independent cycles in Pn Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
8 / 18
Pancake graph: cycle structure [A. Kanevsky, C. Feng, On the embedding of cycles in pancake graphs (1995)] All cycles of length ℓ, where 6 6 ℓ 6 n! − 2, or ℓ = n!, can embedded in Pn .
[J.J. Sheu, J.J.M. Tan, K.T. Chu, Cycle embedding in pancake interconnection networks (2006)] All cycles of length ℓ, where 6 6 ℓ 6 n!, can embedded in Pn .
Cycles in Pn All cycles of length ℓ, where 6 6 ℓ 6 n!, can be embedded in the Pancake graph Pn , n > 3, but there are no cycles of length 3, 4 or 5. Proofs are based on the hierarchical structure of Pn . Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
9 / 18
Pancake graphs: hierarchical structure Pn consists of n copies of Pn−1 (i ) = (V i , E i ), 1 6 i 6 n, where the vertex set V i is presented by permutations with the fixed last element. P1
P4
[1]
[1234]
r3
P2
r3
r2
[3214]
[2341] [2134]
r2 r2 [12]
[4321]
r4 r2
[3421]
r3
[21]
r2
r3
[3124]
[2431]
[2314]
[3241]
r2
r3
P3
r3
[321]
[213]
r3
r2
[312]
r3
r2 [132]
Elena Konstantinova
r2
r3
[4132]
[1423] [1342]
[4213]
r3
r3
r2
r2 [1243]
[4312] [231]
r4 r4
r4
r2
r3 [4231] [2413]
r4
r4
r4 r2
r3
[1324] [3142]
r4
[123]
r2
r4
[1432]
[4123]
r2
r2
r3 [3412]
Prefix-reversal Gray codes
r4
r3 [2143]
Villanova–2014
10 / 18
Hamiltonicity due to the hierarchical structure of Pn ⇔ Prefix–reversal Gray codes (PRGC) by Zaks and Williams Pn−1 (n) π2
Pn−1(n − 1)
rn
Lnn−1
π1 rn
π3
π2n
Ln−1 n−1 L1n−1 π4 rn rn
π5 n−2 Ln−1
Pn−1(1)
rn
Pn−1(n − 2)
Proposition 1. If there is a Gray code in Pn−1 then there is a Gray code in Pn given by the same algorithm. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
11 / 18
Small independent even cycles and PRGC Proposition 2. The Pancake graph Pn , n > 3, contains the maximal set of ℓ–cycles of the canonical form
n! ℓ
independent
Cℓ = (rk rk−1 )k , where ℓ = 2 k, for any 3 6 k 6 n.
Williams’ prefix–reversal Gray code: (rn rn−1 )n This code is based on the maximal set of independent 2n–cycles.
Zaks’ prefix–reversal Gray code: (r3 r2 )3 This code is based on the maximal set of independent 6–cycles. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
12 / 18
Independent cycles in Pn Theorem 1. The Pancake graph Pn , n > 4, contains the maximal set of ℓ–cycles of the canonical form
n! ℓ
independent
Cℓ = (rn rm )k ,
(1)
where ℓ = 2 k, 2 6 m 6 n − 1 and O(1) if m 6 ⌊ n2 ⌋; k= O(n) if m > ⌊ n2 ⌋ and n ≡ 0 (mod n − m); O(n2 ) else.
(2)
Corollary The cycles presented in Theorem 1 have no chords. Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
13 / 18
Hamilton cycles based on small independent even cycles
Hamilton cycle ⇒ PRGC
Definition The Hamilton cycle Hn based on independent ℓ–cycles is called a Hamilton cycle in Pn , consisting of paths of lengths l = ℓ − 1 of independent cycles, connected together with external to these cycles edges.
Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
14 / 18
Hamilton cycles based on small independent even cycles Definition The complementary cycle Hn′ to the Hamilton cycle Hn based on independent cycles is defined on unused edges of Hn and the same external edges. H4′
H4 ! !
!
!
!
!
!
!
! !
!
!
! !
!
!
!
!
!
!
!
! !
!
! !
!
!
!
!
! !
!
!
!
! !
! !
! !
!
!
!
!
(c) Hamilton cycle H4 in P4 Elena Konstantinova
!
!
!
(d) Complement cycle H4′ to H4 in P4
Prefix-reversal Gray codes
Villanova–2014
15 / 18
Hamilton cycles based on small independent even cycles
Theorem 2. There are no other Hamilton cycles in Pn , n > 5, based on independent cycles from Theorem 1 when k = O(1) and k = O(n), except from Zaks and Williams constructions.
Proof is based on examining the complementary cycles’ structures.
Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
16 / 18
Hamilton cycles based on independent
n! 2 –cycles
Theorem 3. There are no Hamilton cycles in Pn , n > 4, based on independent n! 2 –cycles but there are Hamilton paths based on the following two independent cycles: 1 Cn1 = ((Cn−1 /rn−1 )rn )n , 2 Cn2 = ((Cn−1 /rn−1 )rn )n ,
where C41 = (r3 r2 r4 r2 r3 r4 )2 and C42 = (r2 r3 r4 r3 r2 r4 )2 . Proof is based on the hierarchical structure of Pn and on the nonexistence 4–cycles in Pn .
Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
17 / 18
Thanks for attention!
Elena Konstantinova
Prefix-reversal Gray codes
Villanova–2014
18 / 18