Inside the Binary Reflected Gray Code: Flip-Swap Languages in 2-Gray Code Order

A flip-swap language is a set S of binary strings of length n such that S∪{0} is closed under two operations (when applicable): (1) Flip the leftmost 1; and (2) Swap the leftmost 1 with the bit to its right. Flip-swap languages model many combinatorial objects including necklaces, Lyndon words, prefix normal words, left factors of k-ary Dyck words, and feasible solutions to 0-1 knapsack problems. We prove that any flip-swap language forms a cyclic 2-Gray code when listed in binary reflected Gray code (BRGC) order. Furthermore, a generic successor rule computes the next string when provided with a membership tester. The rule generates each string in the aforementioned flip-swap languages in O(n)amortized per string, except for prefix normal words of length n which require O(n)-amortized per string. Our work generalizes results on necklaces and Lyndon words by Vajnovski [Inf. Process. Lett. 106(3):96−99, 2008].

[1]  David Thomas,et al.  The Art in Computer Programming , 2001 .

[2]  Frank Ruskey,et al.  Generating Balanced Parentheses and Binary Trees by Prefix Shifts , 2008, CATS.

[3]  Timothy Walsh,et al.  A loop-free two-close Gray-code algorithm for listing k-ary Dyck words , 2006, J. Discrete Algorithms.

[4]  Joe Sawada,et al.  Necklaces and Lyndon words in colexicographic and binary reflected Gray code order , 2017, J. Discrete Algorithms.

[5]  Gideon Ehrlich,et al.  Loopless Algorithms for Generating Permutations, Combinations, and Other Combinatorial Configurations , 1973, JACM.

[6]  Carla Savage,et al.  A Survey of Combinatorial Gray Codes , 1997, SIAM Rev..

[7]  Kellogg S. Booth,et al.  Lexicographically Least Circular Substrings , 1980, Inf. Process. Lett..

[8]  Elena Barcucci,et al.  Exhaustive generation of combinatorial objects by ECO , 2004, Acta Informatica.

[9]  Joe Sawada,et al.  A Gray code for fixed-density necklaces and Lyndon words in constant amortized time , 2013, Theor. Comput. Sci..

[10]  Jrg Arndt,et al.  Matters Computational: Ideas, Algorithms, Source Code , 2010 .

[11]  Albert Nijenhuis,et al.  Combinatorial Algorithms for Computers and Calculators , 1978 .

[12]  Torsten Mütze,et al.  Combinatorial generation via permutation languages , 2020, SODA.

[13]  Jean Pierre Duval,et al.  Factorizing Words over an Ordered Alphabet , 1983, J. Algorithms.

[14]  Vincent Vajnovszki More restrictive Gray codes for necklaces and Lyndon words , 2008, Inf. Process. Lett..

[15]  Frank Ruskey,et al.  An Eades-McKay Algorithm for Well-Formed Parentheses Strings , 1998, Information Processing Letters.

[16]  Aaron Williams The Greedy Gray Code Algorithm , 2013, WADS.

[17]  Timothy Walsh,et al.  Generating Gray Codes in O(1) Worst-Case Time per Word , 2003, DMTCS.

[18]  Ronald L. Graham,et al.  Concrete mathematics - a foundation for computer science , 1991 .

[19]  Torsten Mutze Proof of the middle levels conjecture , 2014 .

[20]  Moshe Lewenstein,et al.  Clustered Integer 3SUM via Additive Combinatorics , 2015, STOC.

[21]  Frank Ruskey,et al.  Generating Binary Trees by Transpositions , 1988, J. Algorithms.

[22]  Frank Ruskey,et al.  Binary bubble languages and cool-lex order , 2012, J. Comb. Theory, Ser. A.

[23]  Tadao Takaoka,et al.  An O(1) Time Algorithm for Generating Multiset Permutations , 1999, ISAAC.

[24]  H. Wilf A unified setting for sequencing, ranking, and selection algorithms for combinatorial objects , 1977 .

[25]  Yue Li,et al.  Gray codes for reflectable languages , 2009, Inf. Process. Lett..