Arbitrary-length analogs to de Bruijn sequences
Let α be a length-L cyclic sequence of characters from a size-K alphabet 𝒜 such that the number of occurrences of any length-m string on 𝒜 as a substring of α is ⌊ L / K^m ⌋ or ⌈ L / K^m ⌉. When L = K^N for any positive integer N, α is a de Bruijn sequence of order N, and when L ≠ K^N, α shares many properties with de Bruijn sequences. We describe an algorithm that outputs some α for any combination of K ≥ 2 and L ≥ 1 in O(L) time using O(L log K) space. This algorithm extends Lempel's recursive construction of a binary de Bruijn sequence. An implementation written in Python is available at https://github.com/nelloreward/pkl.
READ FULL TEXT