CanaDAM 2013

A Hot Potato for Xi Sisi Shen and Aaron Wi!iams McGi! University

Tuesday, June 18, 2013 Outline

Background

Adjacent Transpositions

Star Transpositions

Hot Potato Transpositions

Construction

Concluding Remarks

Tuesday, June 18, 2013 Background

Tuesday, June 18, 2013 Permutations

We will be discussing the n! permutations of {1,2,...,n} in one-line notation.

Permutations of {1,2,3}

Tuesday, June 18, 2013 Transpositions

Unlike the case for binary strings, two permutations cannot differ by a single position. A transposition is an operation that swaps the values in two positions.

(i j) 1 2 3 4 5 swaps the values in position i (2 6) and position j

Tuesday, June 18, 2013 Transposition Graph

A set of transpositions T can be represented as a graph as follows: Vertices: 1, 2,..., n Edges: ij for each (i j) in T

If T’s graph is disconnected, then you cannot make a Gray code using T. T is a basis if its graph is a spanning tree.

Tuesday, June 18, 2013 Transposition Types

1st Adjacent: (i i+1) Circular-adjacent: (i i+1), (1 n)

2nd Star: (i n) Semi-adjacent: Circular-semi-adjacent: (i i+1), (i i+2) (i i+1), (i i+2), (1 n)

Tuesday, June 18, 2013 Basis Theorems

Theorem (Kompel’makher, Liskovets) : ∃ Gray code for any basis of transpositions.

SEQUENTIAL GENERATION OF ARRANGEMENTS BY MEANS OF A BASIS OF TRANSPOSITIONS

V. L. Kompel'makher and V. A. Liskovets UDC 519.1+519.4

It is welI known ([1], p. 28) that all n! arrangements of n symbols can be ordered without repetition so that each can be obtained from the previous one by a single transposition. This assertion is used to generate arrangements and in certain theoretical and applied investigations. On the other hand, to generate the symmetric group of permutations of degree n a basis of n - 1 transpositions is sufficient. There naturally arises this question: is it possible to order all arrangements of a given degree so that each can be obtained from the previous one by a single transposition from an arbitrary fixed basis? In this paper we give an affirmative answer to this question. Moreover, for an arbitrary basis of transpositions the arrangements can be ordered so that the first can also be obtained from the last by a single basic transposition. A key role in the proof is played by Proof does not translate to an efficient .

Theorem (Ruskey, Savage) : ∃ Gray code for any basis of transpositions where a given t in T is used every second operation. In both proofs, adjacent and star transpositions are fundamental.

Tuesday, June 18, 2013 Inverses The inverse of a switches the roles of the positions and values, i.e. position 1 with value 6 becomes position 6 with value 1 1 2 3 4 5 6 1 2 3 4 5 6 inverse

A pair of permutations differ by a transposition (i j) iff their inverses differ by changing values i and j. 1 2 3 4 5 6 1 2 3 4 5 6 inverse

(2 6)

inverse positions 2 and 6 values 2 and 6

Tuesday, June 18, 2013 Adjacent Transpositions

Adjacent: (i i+1)

Tuesday, June 18, 2013 Permutohedron

Hamiltonian cycles are (cyclic) adjacent transposition Gray codes.

Tuesday, June 18, 2013 Plain Changes

The pattern uses local .

The symbol n is transposed left, then right through each permutation of {1,2,...,n-1}.

Originally discovered by bell ringers in the 17th century.

There exists an efficient loopless generation algorithm.

Tuesday, June 18, 2013 Inverse Plain Changes

Adjacent position value With adjacent-position transpositions, adjacent positions are always transposed.

With adjacent-value transpositions, adjacent values are always transposed.

Tuesday, June 18, 2013 Doubly-Adjacent

In a doubly-adjacent Gray code, the transpositions must be adjacent in two ways.

Each transposition is an adjacent transposition.

Consecutive transpositions must be adjacent. This means that the transposition (i i+1) must be followed by either (i-1 i) or (i+1 i+2).

Theorem (Compton and Williamson) : ∃ a doubly adjacent Gray code for all n.

The construction is very difficult and there is no efficient algorithm known.

The first (1 2 ... n) (1 2) Gray code was a corollary of this theorem.

Tuesday, June 18, 2013 ti si Representations

A doubly adjacent order can be represented by a sequence of transpositions or by a sequence of signs.

The transposition sequence, ti , is defined as follows: If the ith transposition is given by (a b), then ti=min(a,b).

The sign sequence, si , is defined as follows:

If ti > ti+1, then si = +, else si = -

Tuesday, June 18, 2013 Star Transpositions

Star: (i n)

Tuesday, June 18, 2013 Star Network

Hamiltonian cycles are (cyclic) star transposition Gray codes.

Tuesday, June 18, 2013 Motivating Challenge

Let B(n,w) be the set of binary strings of length n and w ones. Middle Levels Conjecture: There exists a cyclic Gray code for B(2k+1,k) ∪ B(2k+1,k+1). Append 0/1 to the strings in B(2k+1,k+1)/B(2k+1,k).

Restatement: There exists a cyclic Gray code for B (2k+2,k+1) using star-transpositions.

Let M(d,f) be the permutations of the uniform-frequency multiset with f copies of each distinct symbol 1,2,...,d. Generalized Conjecture: There exists a cyclic Gray code for M(d,f) using star-transpositions. Middle levels when d=2. Permutations when f=1. k=2

Tuesday, June 18, 2013 Ehrlich’s Order

Ehrlich’s order can be efficiently generated by a constant amortized time (CAT) algorithm.

Not usually cyclic.

Currently unpublished.

Discussed in Knuth’s The Art of Computer Programming

Knuth also created a related non-cyclic order.

Tuesday, June 18, 2013 Inverse Ehrlich

Star position value With star-position transpositions, the position n is always transposed.

With star-value transpositions, the value n is always transposed.

Tuesday, June 18, 2013 Consecutive Star

In a consecutive star Gray code the star transpositions are constrained in two ways.

Each transposition is a star transposition.

Consecutive transpositions must be off by one. This means that the transposition (i n) must be followed by either (i-1 n) or (i+1 n).

Question (Shen and Williams) : Does ∃ a consecutive star transposition Gray code for all n?

Tuesday, June 18, 2013 Hot Potato Transpositions

Tuesday, June 18, 2013 New Idea

A transposition can be restricted by position and value, simultaneously.

For example, a star-value and adjacent-position transposition transposes the value n to the left or right one position.

Question: Does ∃ a transposition Gray code with simultaneous position-restrictions and value-restrictions?

Tuesday, June 18, 2013 Observation 1

There does not exist a Gray code with adjacent-position and star-value transpositions. Position Value adjacent star

We refer to these paths as plain paths in reference to the plain change order.

Tuesday, June 18, 2013 Plain Paths

Each of the plain paths is represented by a permutation of n-1.

Tuesday, June 18, 2013 Observation 2

There does not exist a Gray code with circularly-adjacent-position and star- value transpositions. Position Value circular-adjacent star

We refer to these as plain cycles. These cycles always have length n(n-1) and will be used in our main result.

Tuesday, June 18, 2013 Plain Cycles

Each of the plain cycles is represented by a permutation of n-2.

Tuesday, June 18, 2013 Question

Does there exist a Gray code with the following transpositions?

Position Value circular-semi-adjacent star

From the earlier observations, such a Gray code could be difficult to construct.

We’ll call such a Gray code a Hot Potato Gray code.

Tuesday, June 18, 2013 Modified Hot Potato Game

Each player holds a distinct potato.

Potato n is the HOT potato.

The holder of the HOT potato trades potatoes with a player one or two positions away.

Tuesday, June 18, 2013 1-left 1-right

2-left 2-right

Tuesday, June 18, 2013 Construction

Tuesday, June 18, 2013 Outline of Construction

To construct a Hot Potato Gray code for n, we will require the ordering of a doubly-adjacent Gray code, G, for n-2.

1. Start with the plain cycles (qi) for each permutation qi in G. 2. Define an entry and an exit permutation on each plain cycle. 3. Glue all plain cycles together.

The idea also works for partial Gray codes, that is, doubly- adjacent orders with fewer than (n-2)! permutations.

Tuesday, June 18, 2013 1. Plain Cycles

For each permutation qi in G, the doubly-adjacent Gray code for n-2,

1. append n-1 n to the end of qi 2. circularly transpose the value n

creating each plain cycle, C(qi), i=1,2,.., (n-2)!

The plain cycle for 1234

Tuesday, June 18, 2013 2. Entry & Exit

Using the transposition and sign sequences, ti and si, for the doubly-adjacent Gray code, G, we define the entry permutation,

ai, and exit permutation, bi, as follows:

ai will the first permutation in C(qi) such that the value n is in

the (ti+2) position.

If si is negative, bi is the resultant permutation of a 1-right on ai.

If si is positive, bi is the resultant permutation of a 1-left on ai.

Tuesday, June 18, 2013 q1 = 4321 t1 = 3 q s 2 1 = - = 4312 4231 = 2 p1 = 654321! 12 = t2 q t12 = + p s 2 = 564321! 2 = 2 s12 ! 654312= 546321! - ! 564312 ! = 654231 543621! p12 ! a 546312 564231 2 ! ! a1 = 543261! b = 543612 = 546231 2 = ! b12 ! b1 = 543216! 543162 = 542631 ! q a 12 ! 543126 3 542361 643215! ! p = 1 b 3 4132 ! 643125 = 2431 = + 542316 463215! ! a 3 t ! = 654132 3 = t 11 = 463125 3 s = ! ! = 564132 3 11 11 642315 ! 1 q s ! 436215! = ! 436125 546132 + ! 462315 ! 541632 ! !! 652431 541362 ! = ! 426315 ! ! 562431 ! 154326 541326 ! 11 = ! ! 254316! p 526431 641325 ! 11 = ! b 524631 461325 ! 11 ! a 524361 154236 416325 ! 524316 ! 624315 254136 ! ! ! 264315 ! ! 246315 ! ! b p a 4 4 152436 4 = = = q ! ! ! ! ! ! ! ! ! 4 251436 146325 164325 614325 514326 514362 514632 516432 561432 651432 = - 2 ! ! 1432 s = = t 4 4 10 10 = = 2341 ! t s ! - 2 = 652341 562341 526341 523641 523461 523416 623415 263415 236415 152346 ! ! ! ! ! ! ! ! ! 10

= = = q 251346 10 10 10

a p b !

136425 !

!

!

163425

!

!

! 153246 613425

!

513426 253146

!

326415 a

513462

!

5

!

b 362415

513642

! =

!

! 153426 5

!

p 253416 632415

516342

!

=

!

316425

! ! 5

!

532416 561342

= !

! !

!

532461 651342 361425 ! !

!

346215 532641

!

+

! 346125 631425

536241 !

!

q

= !

1 s

364215

563241 = 5

5

9

!

=

= 9 = 531426

s

t !

! 364125

653241 = 5

9

!

!

a

634215

+

1342

= t 9

=

531462 b 1 ! 9

3241

! 634125

! a

534216

p 6 =

=

531642 9 !

! !

534126

b 534261 = 7

q b

6

= =

536142

8 !

b ! 534621

! 534162

= 7 a

=

563142 ! 8

p a !

536421

6 ! 534612

=

653142 !

! 563421

! 536412

-

!

653421

s = 6

=

= 8 ! 563412 8

s +

p 2

t

= 6

q

= 8

6

t 2 ! 653412 =

= 7 p

3142

3421

- = = 7 s 8

q

3 = 7 t

3412 = 7 q

Tuesday, June 18, 2013 Tuesday, June 18, 2013 Concluding Remarks

Tuesday, June 18, 2013 Comments & Questions

This is the first known Gray code to have simultaneous position and value restrictions.

Question 1: Is there a different construction that can be generated by an efficient algorithm?

Question 2: Other applications of doubly adjacent Gray codes?

Question 3: Is the transposition (1 n) necessary? That is, does a Gray code with the following types of transpositions exist? Position Value semi-adjacent star

Tuesday, June 18, 2013 Thank You!

Tuesday, June 18, 2013