A new combinatorial Gray code for balanced combinations Torsten Mütze joint work with Christoph Standke, Veit Wiechert (TU Berlin) Balanced combinations • balanced combination := a -element subset of • Example: • bitstring representation: • Dyck path representation: flaws = 3 Balanced combinations flaws = 0 Balanced combinations flaws = Balanced combinations total number = flaws the k-th Catalan number The Chung-Feller theorem := set of all Dyck paths with 2k steps and e flaws Theorem [Chung, Feller 49]: For any we have . Various alternative proofs (combinatorial, analytic, …) and generalizations appeared over the years: [Hodges 55], [Narayana 67], [Woan 01], [Eu, Fu, Yeh 05], [Chen 08], [Ma, Yeh 09], [Ruckavicka 11], … Proving Chung-Feller Establish a bijection [Hodges 55], [Chen 08] (#flaws increases by 1) Note: and may differ in many positions Is there a simpler proof? Our results Theorem: There is a bijection such that and differ in only two positions. Our results Theorem: There is a bijection such that and differ in only two positions. flaws Our results ‚simple and explicit‘ Theorem: There is a bijection such that and differ in only two positions. ‚simple‘ Theorem: There is an algorithm which for given computes each Dyck path in in time . Applications • Hamilton cycles in certain vertex-transitive graphs: the odd graph and the middle levels graph • More generally: For which values of do they have a -factor? • Only one general positive answer known: ‚middle levels conjecture‘ [M. 14] • This work: two more positive answers Theorem: The odd graph has a -factor. Theorem: The middle levels graph has a -factor. # cycles = (Catalan number) Combinatorial Gray codes • Goal: Generate all objects in a combinatorial class (permutations, subsets, strings, trees, Dyck paths, etc.) such that consecutive objects differ only ‚a little bit‘ • Ideally: Generate each new object in time • Fundamental task in combinatorial algorithms [Nijenhuis, Wilf 75] [Knuth TAOCP Vol. 4, 11] Combinatorial Gray codes • Examples: • Generate all permutations of such that consecutive permutations differ only in one transposition [Johnson 63], [Trotter 62], [Sedgewick 77] • Generate all subsets of such that consecutive sets differ in adding/removing one element [Gray 53], [Tootill 56], [Bitner, Ehrlich, Reingold 76], [Wagner, West 91], [Savage, Winkler 95], [Bhat, Savage 96] • Generate all many -element subsets of s.t. consecutive sets differ in exchanging one element [Tang, Liu 73], [Bitner, Ehrlich, Reingold 76], [Eades, Hickey, Read 84], [Eades, McKay 84], [Ruskey 88], [Chase 89], [Jenkyns, McCarthy 95], [Ruskey, Williams 09] Combinatorial Gray codes • Examples: Special case : balanced combinations {1, 4,5 } (1,0,0,1,1,0) • Constant-time Generate all generation many -element [Ehrlich 73], subsets [Bitner,ofEhrlich, Reingold 76] 1,0,0,0,0,0 s.t. consecutive sets differ in exchanging one element • Only swaps of the form [Eades, McKay 84] 0,0,0,0,0,1 1,0,0 1,0 • Only distance-≤2 swaps [Chase 89], [Jenkyns, McCarthy 95] 0,0,1 0,1 • Only distance-1 swaps [Eades, Hickey, Read 84], [Ruskey 88] (possible iff even and odd, or ) Combinatorial Gray codes • Examples: • Only distance-1 swaps [Eades, Hickey, Read 84], [Ruskey 88] (possible iff even and odd, or ) 1,0 0,1 Combinatorial Gray codes • Examples: • Generate only i ((())) (=parenthesis expressions, rooted trees, triangulations, binary trees… see [Stanley 15]) iii ii (()()) (())() v iv ()()() ()(()) • Constant-time generation [Ruskey, Proskurowski 90], [Walsh 98] • Only distance-1 swaps [Bultena, Ruskey 98] (possible iff even or less than 5) Combinatorial Gray codes i ii iii iv v Combinatorial Gray codes • Our minimum-change bijection f is ‚orthogonal‘ to Gray codes from before (01-20 and i-v) i ii iii iv v Definition of • Count downsteps starting at → • Flip -th downstep touching the line • Flip first upstep to the left of d touching the line 2 1 4 3 5 u d Definition of • Count downsteps starting at → • Flip -th downstep touching the line • Flip first upstep to the left of d touching the line u d Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u u d d Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u d Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u u dd Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u d Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u d Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u d Definition of • Count downsteps starting at → • Flip -th downstep touching the line • Flip first upstep to the left of d touching the line Definition of • Count downsteps starting at → • Flip -th downstep touching the line • Flip first upstep to the right of d touching the line Definition of Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line Definition of Repeat: • Flip first downstep to the left of u touching the line • Flip first upstep to the right of d touching the line Efficient computation Repeat: • Flip first downstep to the right of u touching the line • Flip first upstep to the left of d touching the line u d Idea: bidirectional pointers below hills and above valleys Fast navigation along Dyck path to reposition u and d Compute each application of in time Thank you!