Longest sequence where n consecutive bits are always unique

76 Views Asked by At

The problem is the following: Find a longest sequence of bits (0,1) in which $n$ consecutive bits always form a unique string.

For $n=2$, you could take the sequence 01100, in which every pair of two bits appears exactly once.

Is there an algorithm to solve this? Or at least sensible upper and/or lower bounds of the lengths of the sequence (the trivial upper bound is $2^n+n-1$)?

The problem is motivated from a reading device moving on magnetic tape, trying to determine its absolute position from the bits it reads locally.

1

There are 1 best solutions below

0
On BEST ANSWER

De Bruijn sequences solve your problem. The Wikipedia page talks about some of the generation mechanisms. If your $n$ is large then a method not illustrated in detail there is the most efficient.

You can use a primitive Linear Feedback Shift Register: Linear-feedback_shift_register.

Choose a primitive binary polynomial of degree $n$. Define the state of the sequence generator as $[s_0,\ldots,s_{n-1}].$ Load the state with any nonzero binary string pattern. If the polynomial is $f(x)=f_0+f_1 x+\cdots+x^n,$ then apply the modulo 2 recurrence $$ s_n=f_1s_{n-1}+f_2s_{n-2}+\cdots+s_0 $$ and update the state to $[s_1,\ldots,s_n]$ by a shift.

This gives you a Maximum_length_sequence with period $2^n-1.$ When you come to the state $$ [s_0,\ldots,s_{n-1}]=[1,0,\ldots,0] $$ with $n-1$ consecutive zeroes you can insert a zero to convert the m-sequence to a DeBruijn sequence.

Note: For the position determination question you mention, if $n$ is so large that table lookup is not possible to obtain "the phase" of the sequence from the state you need to consider the finite field discrete logarithm problem, which is hard and cryptosystems are based on this problem. There are some shortcuts you can use for moderately large $n$ like baby step giant step.