Binary sequences of length $N$ including all numbers upto $N$

105 Views Asked by At

Consider numbers $n$ and $N = 2^n$ and define a binary sequence $b = [b_0,\dots,b_{N-1}]$, $b_i \in \{0,1\}$, to be complete or to include all numbers upto $N$ when for each number $0 \leq i < N$ there is a number $0 \leq j < N$ such that

$$i = \sum_{k=0}^{n-1} b_{(j+k)\,\text{mod}\, N}\cdot 2^k$$

The easiest thing to do is to go through all binary sequences of length $N$ and check if they are complete.

Examples:

n = 2: [1,1,0,0] => [3,1,0,2]
n = 3: [1,0,1,1,1,0,0,0] => [5,6,7,3,1,0,4,2]
n = 4: [1,1,1,1,0,1,0,1,1,0,0,1,0,0,0,0] => [15,7,11,5,10,13,6,3,9,4,2,1,0,8,12,14]
       [1,1,0,1,0,1,1,1,1,0,0,1,0,0,0,0] => [11,5,10,13,14,15,7,3,9,4,2,1,0,8,12,6]

For $n=2$ there are $2^{2^2} = 16$ sequences, $4= 2^2$ being complete.

For $n=3$ there are $2^{2^3} = 256$ sequences, $16 = 2^4$ being complete.

For $n = 4$ there are $2^{2^4} = 65,536$ sequences, $256 = 2^8$ being complete.

Question 1: Is it true that the number of complete sequences for given $n$ is $2^{2^{n-1}}$ or – equivalently – the square root of the number of all sequences? How to prove it?

Question 2: Which properties must complete sequences have, except for (i) containing the same number of 0s and 1s, (ii) containing exactly two runs of length $n$, and (iii) not containing runs longer than $n$?

Question 3: Which properties must the coded number sequences have? Must they be "random" in a way?

Question 4: Since already for $n=5$ with $2^{2^5} = 4,294,967,296$ binary sequences a brut force search for complete sequences is not opportune: How do I compute a complete sequence for any given $n$? What's the runtime $\mathcal{O}(f(n))$ of the algorithm?