How this calculation works
A De Bruijn sequence places every fixed-length word over a finite alphabet into one cyclic sequence without repeating any window. This calculator constructs a deterministic cycle in the entered alphabet order and verifies every wraparound window. The complete cycle is previewed, while copy and download append the initial prefix needed to scan the same windows in a linear text file.
A De Bruijn cycle B(k,n) has k^n tokens and exactly one cyclic occurrence of every length-n word over k symbols.A worked example
For the binary alphabet 0,1 and order three, one cycle is 00010111. Its eight cyclic windows are 000,001,010,101,011,111,110 and 100. The last two cross the printed endpoint and wrap back to the first zeros. Appending the first two tokens gives 0001011100, whose eight ordinary length-three windows match those cyclic words.
Good to know
Use two to eight distinct alphabet tokens, each at most eight characters, and order one through twelve. The cycle length alphabetSize^order must not exceed 8,192. Tokens are separated by whitespace or commas. The window table shows only its first hundred rows, while all cyclic windows are verified. Rotations and other valid cycles are possible; this is not an enumeration of every De Bruijn cycle.
Reference: SageMath — De Bruijn sequences (opens in a new tab) ↗
The cyclic interpretation accounts for the shortest length
There are k^n different length-n words. A cyclic sequence with L tokens has exactly L starting positions for such windows, counting wraparound. Covering each word once therefore requires L=k^n. A valid De Bruijn cycle reaches that bound by assigning a different word to every cyclic start position.
The printed endpoint is not a special break in the cycle. If the same tokens are treated as an ordinary finite string without wraparound, only L−n+1 full windows remain. The downloadable linearization adds n−1 initial tokens to the end so that all L cyclic windows can be recovered by normal substring scanning. It is longer than the cycle because the display convention changed.
The Necklace colorings up to rotation calculator counts cyclic color classes, while this page constructs one cycle covering every fixed-length word.
Alphabet tokens and printed characters are separate units
A token can be a short label rather than a single character. For alphabet red,blue, a length-three word contains three tokens, not three letters. The sequence display uses spaces so token boundaries remain recoverable. Removing all separators from multi-character labels would make a different and potentially ambiguous string.
The entered alphabet order determines the deterministic construction. Changing that order can change the displayed cycle, although the coverage requirement is unchanged. A rotated valid cycle is still valid. Comparing exact printed strings is therefore a weaker correctness test than verifying length, alphabet membership and the uniqueness of every cyclic window.
Verify the construction independently of its generation rule
The construction concatenates selected Lyndon words through a standard recursive generation scheme. The resulting sequence is then scanned independently: every length-n cyclic window is encoded by token indices, inserted into a set, and the set size is checked against k^n. A failed certificate is an error, not a warning attached to an unchecked result.
A small overlap graph gives another interpretation. Vertices are length-(n−1) words and edges are length-n words; traversing each edge once creates a De Bruijn cycle. This explains the connection to Eulerian graph algorithms without making this page another generic Euler-path calculator. Its input, output and verification are the structured universal-word problem.
A few questions, answered
Why is the download longer than the cycle?
It appends the first order−1 tokens so every cyclic window appears as an ordinary linear substring. The cycle itself still has alphabetSize^order tokens.
Must my valid sequence match the example exactly?
No. Rotations and different Eulerian constructions can produce different valid cycles. Window coverage and uniqueness establish validity.