English

Necklaces and Lyndon words in colexicographic order

Combinatorics 2026-07-06 v1 Data Structures and Algorithms

Abstract

We present the first constant-amortized-time algorithms for generating all length-nn necklaces and Lyndon words over a kk-letter alphabet in colexicographic order, for arbitrary k2k\geq 2. Our approach introduces a novel class of words called \emph{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)Q_k(n) of length-nn quasinecklaces and show that Qk(n)Q_k(n) is proportional to the number of length-nn 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.

Keywords

Cite

@article{arxiv.2607.05324,
  title  = {Necklaces and Lyndon words in colexicographic order},
  author = {Daniel Gabric and Joe Sawada},
  journal= {arXiv preprint arXiv:2607.05324},
  year   = {2026}
}