Data Structures and Algorithms
De Bruijn Sequences
executive summary
We present a card trick that is driven by the structure of De Bruijn sequences, which are circular bit sequences of length \(2^k\) where every bit string of length \(k\) appears as a subsequence.
We also show how we can use Euler Tours to create De Bruijn sequences.
link to companion notes
Any number of cut shuffles are done.
Five people pull out the top five cards in order.
A deck is given to someone in the audience.
The Reds Speak Up
The ones with red cards stand up.
All cards are identified.
The Card Identifier
X Y A B C
00 - ♣️ | 01 - ♠️ | 10 - ♦️ | 11 - ♥️
Five bits correspond to a card
A B C - value of the card (000 interpreted as 8)
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: 32 bits so that each location gives us a unique read.
00000100101100111110001101110101
The Sequence
Want: \(2^k\) bits so that each location gives us a unique read.
De Bruijn Sequences
Goal: build these sequences by taking an Euler Tour in a graph.
Vertices: one for each bit string of length \(k-1\).
Total # of vertices = \(2^{(k-1)}\).
00
11
01
10
\(a_1...a_{k-1}\)
\(b_1...b_{k-1}\)
When should you add this edge?
\(a_2...a_{k-1} = b_1...b_{k-2}\)
[Suffix-Prefix match.]
0
1
1
1
1
1
1
0
0
0
0
0
0
1
1
1
1
1
1
0
0
0
0
0
0
1
1
1
0
1
1
0
0
0
0
0
0
1
1
1
0
1
1
0
0
0
0
0
\(a_2\)
\(b_1\)
\(b_2\)
\(b_3\)
\(\cdots\)
\(b_{k-1}\)
\(a_1\)
\(a_3\)
\(\cdots\)
\(a_{k-2}\)
\(a_{k-1}\)
\(b_{k-1}\)
Any vertex has two out-neighbors.
\(a_2\)
\(b_1\)
\(b_2\)
\(b_3\)
\(\cdots\)
\(b_{k-1}\)
\(a_1\)
\(a_3\)
\(\cdots\)
\(a_{k-2}\)
\(a_{k-1}\)
\(b_{k-1}\)
Any vertex has two out-neighbors.
\(a_2\)
\(b_1\)
\(b_2\)
\(b_3\)
\(\cdots\)
\(b_{k-1}\)
\(a_1\)
\(a_3\)
\(\cdots\)
\(a_{k-2}\)
\(a_{k-1}\)
\(b_{k-1}\)
Any vertex has two in-neighbors.
\(a_2\)
\(b_1\)
\(b_2\)
\(b_3\)
\(\cdots\)
\(b_{k-1}\)
\(a_1\)
\(a_3\)
\(\cdots\)
\(a_{k-2}\)
\(a_{k-1}\)
\(b_{k-1}\)
Any vertex has two in-neighbors.
Vertices: one for each bit string of length \(k-1\).
Each vertex will have
two in-neighbors and two out-neighbors.
Total # of edges = \(2^{(k)}\).
Total # of vertices = \(2^{(k-1)}\).
00
11
01
10
00
11
01
10
00
11
01
10
0
0
00
11
01
10
0
0
1
00
11
01
10
0
0
1
0
00
11
01
10
0
0
1
0
1
00
11
01
10
0
0
1
0
1
1
00
11
01
10
0
0
1
0
1
1
1
00
11
01
10
0
0
1
0
1
1
1
0
00
11
01
10
0
0
1
0
1
1
1
0
00
11
01
10
0
0
1
0
1
1
1
0
00
11
01
10
0
0
1
0
1
1
1
0