---
title: 'De Bruijn Sequences: Constructions & Applications'
url: https://www.emergentmind.com/topics/de-bruijn-sequences
type: topic
---

# De Bruijn Sequences: Constructions & Applications

A De Bruijn sequence of order $n$ over a finite alphabet $[k]=\{0,1,\ldots,k-1\}$ is a cyclic string $(\sigma_1 \sigma_2 \cdots \sigma_{k^n})$ of length $k^n$ such that each possible length-$n$ word over $[k]$ appears exactly once as a contiguous block, considering wrap-around. De Bruijn sequences are fundamental objects in combinatorics, coding theory, and algorithm design due to their maximal overlap and coverage properties.

## 1. Fundamental Definition and Graph-Theoretic Characterization

For integers $k \geq 2$ and $n \geq 1$, a De Bruijn sequence $S$ of order $n$ over $[k]$ satisfies that every $n$-tuple in $[k]^n$ occurs exactly once as a substring under cyclic wrap-around. Formally, $S$ corresponds to a Hamiltonian cycle in the directed De Bruijn graph of order $n$ on $[k]$. This graph has vertex set $[k]^{n-1}$, and for every vertex $v$ and symbol $\sigma \in [k]$, an edge $v \to$ (suffix$(v)$ concatenated with $\sigma$) exists; every vertex has in-degree and out-degree $k$, and the graph is Eulerian and strongly connected [1805.02405].

| Property        | Value                | Description                               |
|-----------------|---------------------|-------------------------------------------|
| Sequence Length | $k^n$               | Number of substrings; also graph edges    |
| Vertex Count    | $k^{n-1}$           | For graph model (order-$n$)               |
| Substring Count | $k^n$               | Each $n$-tuple appears exactly once       |

The sequence can be equivalently described by its substrings: the cyclic multiset of substrings of length $n$ is precisely $[k]^n$, each appearing once.

## 2. Classical Constructions and Shift-Rule Frameworks

Two paradigmatic constructions are the "prefer-max" and "prefer-min" algorithms. In the prefer-max scheme, one starts with $w_0 = 0^{n-1}(k-1)$ and at each step chooses the maximal unused symbol that results in a novel $n$-block, extending the sequence greedily. Prefer-min is symmetric, starting at $(k-1)^{n-1}0$ and choosing the minimal unused symbol. Both yield Hamiltonian cycles in the De Bruijn graph and both can be implemented efficiently.

A key advance is the combinatorial "shift-game" [1805.02405], which models sequence generation as a two-player game whose unique tie outcome traces the prefer-max cycle in reverse. Given explicit active/passive strategies $(A^*, B^*)$ for the two players (Bob and Alice), one can algorithmically generate De Bruijn sequences both forwards and backwards, with O($n$) time complexity per shift. The optimality of these strategies is proven: Alice (resp. Bob) can force the cycle only by playing $A^*$ ($B^*$), and any deviation can be exploited.

Moreover, the transition rule
\[
\text{shift}(x\sigma) =
\begin{cases}
   (\sigma+1)x, & \text{if}~\sigma < k-1~\text{and}~A^*(x(\sigma+1))=1 \\
   0x, & \text{if}~A^*(x\sigma)=1 \\
   \sigma x, & \text{otherwise}
\end{cases}
\]
traces the prefer-max cycle backwards, and its inverse yields the forward shift. Prefer-min shifts are obtained by applying symbol-wise negation.

Efficient computation of $A^*$ is achieved via base-$k$ valuation of rotations:
\[
\text{val}(s) = \sum_{i=0}^{n-1} s_{n-1-i} k^i,\quad
\text{val}^*(s) = \max \{ \text{val}(r),\text{~for~rotations~}r~\text{of}~s \}
\]
This allows $A^*(s)$ to be computed in $O(n)$ time, thus yielding efficient generation schemes.

## 3. Combinatorial and Algorithmic Generalizations

### 3.1 Unoriented De Bruijn Sequences

The unoriented variant $uB(k,n)$ demands that every length-$n$ word or its reversal appears as a contiguous substring, read in either direction [1608.08480]. Optimal length sequences exist iff $k$ is 2 or odd and $n\leq3$. Construction utilizes alternating Eulerian paths in undirected “reflection” graphs, with edge types distinguished by prefix/suffix, and Eulerization (duplicate edges as necessary) to guarantee existence for arbitrary $k,n$.

| Sequence Type    | Required Coverage             | Optimal Length Condition                         |
|------------------|------------------------------|--------------------------------------------------|
| Oriented ($B(k,n)$) | Each $n$-word, forward        | Always                                      |
| Unoriented ($uB(k,n)$) | Each $n$-word or its reversal | $k$ odd or $k=2$, $n\leq 3$                 |

### 3.2 Cut-Down and Multi-Shift Sequences

Cut-down De Bruijn sequences are cyclic strings of length $L \leq k^n$ such that no $n$-word appears more than once; they generalize De Bruijn sequences to partial coverage [2205.02815]. Construction proceeds via modified cycle-joining and successor rules, and the k-ary algorithm runs in $O(n)$ per symbol after initialization.

Multi-shift sequences $\tau(m,n)$ require that every $n$-length word appears once, positioned at multiples of $m$ [1004.1216]. Enumeration and generation exploit block-permutation and word-graph Eulerian path methods.

### 3.3 Adjacency-Hopping, Balanced, and Orthogonal Variants

Adjacency-hopping De Bruijn sequences restrict adjacent symbols to differ, yielding codes of length $k(k-1)^{n-1}$ that enhance non-repetitive patterning in applications like structured light coding [2309.02841].

Balanced generalized variants impose constraints on symbol counts and substring multiplicity, with necessary and sufficient conditions for existence based on sequence length and substring frequency [2201.11863].

Orthogonal De Bruijn families require that no $(k+1)$-word appears more than once across the family and admit bounds on maximal family size, balancing, and fixed-weight restrictions, all governed by Eulerian subgraph packing arguments [2501.12921].

## 4. Advanced Generation: Cycle Joining and Algebraic Techniques

The cycle-joining method constructs de Bruijn sequences from the cycles generated by a linear feedback shift register (LFSR) with arbitrary characteristic polynomial. The state space $\Omega(f(x))$ is decomposed into cycles via the factorization of $f(x)$, and adjacency graphs are formed where cycles are connected via conjugate pairs (states $v$ and $v' = v$ with the first bit toggled). Spanning trees of these graphs, identified via the matrix-tree theorem, yield distinct de Bruijn sequences [1611.10088, 1604.04351].

Algebraic approaches utilize Zech’s logarithms in $\text{GF}(2^n)$ for precisely characterizing conjugate and cross-join pairs, enabling efficient adjacency computations and feedback function management. The cross-join pairing technique allows construction of new nonlinear feedback shift register (NLFSR) sequences by strategic modification of successor relations [1705.03150].

Rule-based and learning-assisted approaches use memory-$\mu$ rules, symmetry constraints, and neural network classifiers to drastically reduce search space and automate de Bruijn sequence generation, achieving high accuracy even for large $\mu$ [2507.09764].

## 5. Discrepancy: Extremal Constructions and Balancing

The discrepancy of a binary (or $k$-ary) de Bruijn sequence is the maximum absolute difference between the number of ones and zeros in any substring. Every sequence must contain a run of $n$ identical bits, establishing a lower bound of $n$. The sharp result is that there exists a binary de Bruijn sequence of order $n$ with discrepancy equal to $n$—the minimum possible [2407.17367]. This is achieved by carefully linking cycles in the De Bruijn graph while tracking substring histograms via depth assignment. For larger alphabets, the minimal discrepancy is at most $n+1$.

Classical greedy or cycle-joining constructions yield higher discrepancy (e.g., lex-least sequences with $\Theta(2^n \log n / n)$ discrepancy) while CCR-based and refined constructions attain discrepancies of order $n$ [2005.01638]. Conversely, maximal discrepancy can reach $\Theta(2^n/\sqrt{n})$.

| Construction Type    | Discrepancy Behavior                   |
|---------------------|----------------------------------------|
| Prefer-max/min, CCR | $\Theta(n)$ (minimum achieved)         |
| Lex-least/Ford      | $\Theta(2^n \log n / n)$               |
| Maximal-weight join | $\Theta(2^n/\sqrt{n})$ (upper bound)   |

## 6. Further Generalizations, Uniform Distribution, and Applications

Concatenation of smaller universal cycles can yield full de Bruijn sequences given suitable run-matching conditions [1803.09009]. These construction techniques encompass necklace-based, co-necklace, and rotation-based schemes and allow efficient sequence generation in $O(1)$ time per symbol for binary cases.

Random generation of de Bruijn sequences is enabled by sampling random arborescences of the underlying Eulerian graph, achieving uniformity and linear expected cover time in practice [2510.16545].

Completely uniformly distributed sequences in $[0,1)$ can be constructed by concatenating de Bruijn sequences of increasing order and alphabet size, guaranteeing equidistribution in all dimensions. Both elementary counting and Weyl's criterion can be used to certify uniformity [1909.11156].

Practical and theoretical applications span coding theory (error correction, data compression), cryptography (stream ciphers, key generation), pseudorandom number generation, experimental design (synthetic biology, DNA probe minimizing cross-hybridization), and robust structured-light coding.

## 7. Synthesis and Connections to Classical Results

The Fredricksen–Kessler–Maiorana theorem states that concatenation of Lyndon words of lengths dividing $n$ (in lex order) is exactly the prefer-min de Bruijn sequence of order $n$ [1805.02405]. Efficient shift rules for both prefer-max/min and Lyndon concatenations are given, and their equivalence is established via game-theoretic strategy analysis.

The landscape of De Bruijn sequence theory thus comprises combinatorial games, algorithmic shift-rules, algebraic (polynomial/LFSR) constructions, balancing/discrepancy optimization, orthogonal and adjacency-hopping constraints, and random generation. These facets demonstrate deep connections between combinatorial optimization, symbolic dynamics, graph theory, and coding practice.

Source: https://www.emergentmind.com/topics/de-bruijn-sequences