Graph Theory37 sections · 1633 units
Open in Course

Problem - De Bruijn Sequence

CSES 1692 - Construct the sequence.

Problem: Given nn, construct a minimum-length bit string that contains every nn-bit string as a substring.

Link: CSES 1692

Constraints: 1n151 \leq n \leq 15

Output: A bit string of length 2n+n12^n + n - 1 (the De Bruijn sequence).

Example: For n=2n = 2, output "0011000110" (length 5=4+215 = 4 + 2 - 1). Build a directed graph where nodes are (n1)(n-1)-bit strings and edges represent nn-bit strings. Find an Euler circuit on this graph.