← All tools

De Bruijn Sequence Generator

A De Bruijn sequence B(k, n) is a cyclic sequence over an alphabet of k symbols in which every possible length-n word appears exactly once as a substring (wrapping around). It has length kn. The classic example B(2, 3) = 00010111 contains all eight 3-bit strings. This tool builds the lexicographically smallest De Bruijn sequence via the Fredricksen–Maiorana–Kessler (FKM) algorithm — concatenating the Lyndon words whose length divides n — and verifies that every kn word occurs exactly once. Runs locally in your browser.

Input

Alphabet size k
Word length n
Symbol style

Sequence

B(k, n) is a cyclic De Bruijn sequence: length kn, where every length-n word over k symbols appears exactly once as a cyclic substring. It is generated with the FKM algorithm: enumerate the Lyndon words (aperiodic necklaces) over {0…k−1} up to length n in lexicographic order, and concatenate those whose length divides n. This yields the lexicographically smallest such sequence. The classic binary cases: B(2,3) = 00010111, B(2,4) = 0000100110101111, B(3,2) = 001021122. The tool verifies that all kn words occur exactly once (cyclically). De Bruijn sequences power card-dealing tricks and compact indexing of every n-gram. Pairs with the Lyndon-word / Run-Length tools. Everything runs locally — nothing leaves your browser.