Necklaces and Lyndon words in colexicographic order
Abstract
We present the first constant-amortized-time algorithms for generating all length-n necklaces and Lyndon words over a k-letter alphabet in colexicographic order, for arbitrary k≥ 2. Our approach introduces a novel class of words called quasinecklaces, which serve as an easily generated superset of necklaces through which all necklaces can be efficiently identified. We derive a formula for the number Qk(n) of length-n quasinecklaces and show that Qk(n) is proportional to the number of length-n necklaces, which is the key property needed to achieve constant amortized time. We also apply our results to efficiently generate a well-known de Bruijn sequence and efficiently generate necklaces and Lyndon words subject to a weight constraint.
Turn this paper into a full lesson
ArcXiv compiles a staged curriculum from this paper: 8-12 lessons across beginner → advanced, synthesised section guides, visuals, flashcards, a quiz, exercises, and on-demand deep dives per section. Grounded in the abstract, never invented.