Post on 16-Apr-2017
De Bruijn Sequences for Fun and Profit
Aleksandar Bradic
CTO, Supplyframe
December 13 2016
(motivation)
(4-decimal digit combination lock)
k = 10(base); n = 4(length)Number of combinations: 104 = 10, 000 (kn)Total sequence length: 4 ∗ 104 = 40, 000 (nkn)
De Bruijn sequence
A cyclic sequence in which every possible length-n string occursexactly once as a substring.
B(k , n) - De Bruijn sequence of order n on a size-k alphabet.
B(2,12)
De Bruijn sequence
I B(k , n) has length kn - the number of distinct substrings oflength n on given alphabet A ⇒ is optimally short.
I B(k , n) is not unique. There are (k!)kn−1
kn distinct B(k , n)sequences.
I ⇒ linear speedup! (O(kn) vs O(nkn))
Generation
I Hamiltonian Path on De Bruijn graph
I Using Shift Registers
Hamiltonian Path on De Bruijn graph
De Bruijn graph on a set of m symbols S := S1, ....Sm, is adirected graph with mn vertices representing all possible length-nsequences of given symbols:
V = Sn = (s1, ..., s1, s1), (s1, ...., s1, s2), ....., (sm, ...., sm, sm)
and edges representing set of all possible expressions of vertices asanother vertex by shifting all its symbols by one place to the leftand adding a new symbol at the end of this vertex:
E = ((v1, v2, ...., vn), (v2, ...., vn, si )) : i = 1, ...,m
Hamiltonian Path on De Bruijn graph
I Each vertex in De Bruijn graph has exactly m incoming and moutgoing edges.
I Each n-dimensional De Bruijn graph is the line digraph of the(n-1)-dimensional De Bruijn graph with the same set ofsymbols.
I Each De Bruijn graph is Eulerian and Hamiltonian.
Hamiltonian Path on De Bruijn graphDe Bruijn sequences can be constructed by taking a Hamiltonianpath of an n-dimensional De Bruijn graph over k symbols (or aEulerian cycle of a (n − 1)-dimensional De Bruijn graph).
Generation using shift registers
I Generate one digit at the time, and repeatedly work with then most recently generated digits, passing from one tuple(x0, ..., xn−1) to another one (x1, ..., xn−1, xn) by shifting anappropriate new digit in at the right.
Generation using shift registers
Generation using shift registers
If we want to generate a single order n sequence on the letters(0, 1, . . . k − 1), where k is prime, we can pick an irreduciblepolynomial
xn − bnxn−1 − · · · − b2x − b1 ∈ Zk [x ]
and an initial string of n numbers s1 . . . sn which isn’t 00 . . . 0.The next term in the sequence is defined by:
sn+1 = b1s1 + b2s2 + · · ·+ bnsn ∈ Zk [x ]
Applications
I Magic!
I Indexing 1s in a Computer Word
I Fault Tolerant Systems
I Writing detection
Indexing 1s in a Computer Word
h(x) = (x ∗ deBruijn) >> (n − lgn)
I We assume that n is an exact power of 2. Multiplication isperformed modulo 2n
I deBruijn is a computer word whose bit pattern contains alength-n de Bruijn sequence beginning with lgn zeros.
Indexing 1s in a Computer Word
Fault Tolerant Systems
I In the binary De Bruijn graphthere will exist 22
n−1−n different Hamiltonian cycles
I De Bruijn graph B(2, n) with a single node failure has a cyclewith at least 2n − n − 1 nodes
Writing detection
Thanks!