On the Existence of Balanced Generalized de Bruijn Sequences

This paper establishes the necessary and sufficient conditions on the parameters nn, ll, and kk for the existence of a balanced generalized de Bruijn sequence, defined as a cyclic binary sequence with an equal number of 0s and 1s where every substring of length ll appears at most kk times.

Matthew Baker, Bhumika Mittal, Haran Mouli, Eric Tang

Published 2026-03-11
📖 5 min read🧠 Deep dive

Here is an explanation of the paper "On the Existence of Balanced Generalized de Bruijn Sequences," translated into everyday language with some creative analogies.

The Big Idea: The Perfect Playlist

Imagine you are a DJ trying to create the perfect playlist. You have a specific goal:

  1. Balance: You want exactly half the songs to be "Upbeat" (1s) and half to be "Chill" (0s).
  2. Variety: You want every possible 5-song combination (substring) to appear in the playlist, but you don't want any specific combination to get too repetitive. You set a rule: "No 5-song combo can play more than kk times."

The question the authors ask is: Is it possible to build such a playlist of length nn?

The paper answers this with a simple "Yes" or "No" based on three numbers:

  • nn: The total length of the playlist.
  • ll: The length of the "chunks" you are checking (e.g., 5 songs).
  • kk: The maximum number of times any chunk is allowed to repeat.

The Magic Rule (The Main Theorem)

The authors discovered a simple formula that tells you exactly when this is possible. You can build your perfect playlist if and only if:

  1. The playlist is even in length (You can't have 51 songs if you need an exact 50/50 split of Upbeat/Chill).
  2. The repetition limit (kk) is high enough. Specifically, kk must be at least the total length (nn) divided by the total number of possible chunks ($2^l$).

Think of it like this:
If you have a playlist of 100 songs (n=100n=100) and you are looking at chunks of 5 songs (l=5l=5), there are $2^5 = 32$ possible unique 5-song combos.
If you want to fit 100 songs into a loop where every 5-song combo appears, you have to repeat some combos.

  • $100 \div 32 \approx 3.125$.
  • So, you must allow some combos to appear at least 4 times (k4k \ge 4).
  • If you try to say "No combo can appear more than 3 times," the math says it's impossible. You simply don't have enough "slots" to fit all 100 songs without breaking the rule.

How Did They Prove It? (The Graph Detective)

To prove this, the authors didn't just write down numbers; they turned the problem into a map.

Imagine a city where every intersection is a specific sequence of bits (like "010"). The roads connecting these intersections represent adding a new bit to the sequence.

  • Red Roads: Represent adding a "0".
  • Blue Roads: Represent adding a "1".

The authors realized that creating a balanced sequence is like taking a walk through this city:

  • You must start and end at the same place (it's a loop).
  • You must walk down exactly the same number of Red roads as Blue roads (to keep the 0s and 1s balanced).
  • You must not walk down any road more than kk times.

They proved that as long as your "repetition limit" (kk) is high enough to cover the distance, you can always find a path that satisfies all these rules. If the limit is too low, the map simply doesn't have a path that works.

The Real-World Magic Trick

Why does anyone care about this? The authors explain that this math is the secret sauce behind a mind-reading card trick.

The Setup:
A magician asks five people to pick cards. They don't tell the magician what the cards are. Instead, they just signal if their card is Red or Black.

  • Red = 0
  • Black = 1

This creates a 5-bit code (e.g., "01001").

The Secret:
The magician has memorized a special "balanced sequence" of 52 cards (a generalized de Bruijn sequence). In this sequence, every possible 5-card color pattern appears exactly twice.

  • Because the pattern appears twice, the magician sees "01001" and knows it could be two specific cards (e.g., the 10 of Diamonds or the King of Hearts).
  • The magician then asks a simple question: "Is it a Heart?"
    • If the person says "Yes," the magician knows it's the Heart.
    • If "No," the magician knows it's the Diamond.

Because the sequence is "balanced" (equal reds and blacks) and follows the mathematical rules the paper proves, the magician can always narrow it down to one card and then predict the next four cards in the circle perfectly.

Summary

This paper is a mathematical "recipe book." It tells us exactly when we can arrange a string of 0s and 1s so that:

  1. It's perfectly balanced (equal 0s and 1s).
  2. No small pattern repeats too often.

If the numbers follow the rule (nn is even and kk is big enough), the recipe works. If not, no amount of magic can make it happen. This math isn't just abstract; it's the engine behind some of the most impressive mentalism tricks in the world.