Ranking and unranking fixed-density necklaces and Lyndon words

Abstract We present the first polynomial-time ranking and unranking algorithms for fixed-density necklaces and Lyndon words. Using the unit-cost RAM model, the ranking algorithm runs in O ( n 3 ) time and the unranking algorithm runs in O ( n 4 ) time. By applying the ranking algorithms, the number of fixed-density necklaces and Lyndon words with a given prefix can also be computed in O ( n 3 ) time.