paper

Necklaces and Lyndon words in colexicographic order

arXiv:2607.05324

Abstract

We present the first constant-amortized-time algorithms for generating all length- necklaces and Lyndon words over a -letter alphabet in colexicographic order, for arbitrary . 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 of length- quasinecklaces and show that is proportional to the number of length- 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.