starting with length zero, form the integer sequence 1, 2, 1, 2, 3, 6, 9, 18, 30, 56, 99, 186, 335, ... Lyndon words correspond to aperiodic necklace class representatives and can thus be counted with Moreau's necklace-counting function. Generation provides an efficient algorithm for listing the Lyndon words of length at most with a given alphabet size in lexicographic order. If is one of the words in the sequence, then the next word after can be found by the following steps: Repeat the symbols from to form a new word of length exactly , where the th symbol of is the same as the symbol at position mod length() of . As long as the final symbol of is the last symbol in the sorted ordering of the alphabet, remove it, producing a shorter word. Replace the final remaining symbol of by its successor in the sorted ordering of the alphabet. The worst-case time to generate the successor of a word by this procedure is . However, if the words being generated are stored in an array of length , and the construction of from is performed by adding symbols onto the end of rather than by making a new copy of , then the average time to generate the successor of (assuming each word is equally likely) is constant. Therefore, the sequence of all Lyndon words of length at most can be generated in time proportional to the length of the sequence. A constant fraction of the words in this sequence have length exactly , so the same procedure can be used to efficiently generate words of length exactly or words whose length divides , by filtering out the generated words that do not fit these criteria. Standard factorization According to the Chen–Fox–Lyndon theorem, every string may be formed in a unique way by concatenating a sequence of Lyndon words, in such a way that the words in the sequence are nonincreasing lexicographically. The final Lyndon word in this sequence is the lexicographically smallest suffix of the given string. A factorization into a nonincreasing sequence of Lyndon words (the so-called Lyndon factorization) can be constructed in linear time. Lyndon factorizations may be used as part of a bijective variant of the Burrows–Wheeler transform for data compression, and in algorithms for digital geometry. Such factorizations can be written (uniquely) as finite binary trees, with the leaves labelled by the