Generating a Gray code for prefix normal words in amortized polylogarithmic time per word
Péter Burcsi, Gabriele Fici, Zsuzsanna Lipták, Rajeev Raman, Joe Sawada
TL;DR
This work addresses the efficient exhaustive generation of prefix normal words of length $n$ and the associated membership problem. By showing that prefix normal words form a bubble language, the authors apply a generic bubble-language generation framework to produce a cool-lex Gray code, first giving a $O(n^2)$-based approach and then achieving an improved amortized time of $O(\log^2 n)$ per word through a refined, $(s,t)$-structured membership test and an efficient update of run-based prefix-maxima. Key contributions include a novel bubble-language characterization via the computation tree, a practical two-phase membership tester, and concrete Gray-code generation for PN words across all weights, with an explicit example for $n=7$. The results advance combinatorial generation for a nontrivial language and connect to jumbled pattern matching, providing both theoretical and practical improvements over prior $O(n)$-per-word generation and offering several open problems for closed-form enumeration, constant-amortized generation, and faster worst-case testing.
Abstract
A prefix normal word is a binary word with the property that no substring has more $1$s than the prefix of the same length. By proving that the set of prefix normal words is a bubble language, we can exhaustively list all prefix normal words of length $n$ as a combinatorial Gray code, where successive strings differ by at most two swaps or bit flips. This Gray code can be generated in $\Oh(\log^2 n)$ amortized time per word, while the best generation algorithm hitherto has $\Oh(n)$ running time per word. We also present a membership tester for prefix normal words, as well as a novel characterization of bubble languages.
