How many bit string of length n has no consecutive ones except the last two bits

binarycombinatoricsprobability distributions

I'm looking for the number of an n-bits long bit string having no consecutive ones except the last two bits. Let me clarify the question by making some examples. Let say $n=5$, then:

$$\text{String 1: } \color{red}{00011} \text{ Good}$$
$$\text{String 2: } \color{red}{01011} \text{ Good}$$
$$\text{String 3: } \color{red}{11011} \text{ No (two consecutive ones before the end)}$$
$$\text{String 4: } \color{red}{10111} \text{ No (two consecutive ones before the end)}$$
$$\text{String 5: } \color{red}{10010} \text{ No (one of the last two bits isn't 1)}$$

I'm looking for the number of "Good" strings. Although finding the number of strings with all zero except the last two bits is easy, I'm stuck with dealing with the case of alternating one's and zero's in the strings. I appreciate any help or tips :D.

Best Answer

Any such binary number is a $n-3$ digits binary numbers with no consecutive ones followed by $011$. Therefore you just need to find out how many $n-3$ digits binary numbers with no consecutive ones exist.

Any $m$ digits binary number with no consecutive ones is either a $m-1$ digits binary number with no consecutive ones followed by $0$ or a $m-2$ digits binary number with no consecutive ones followed by $01$. Therefore, if $k_{m}$ is the number of $m$ digits binary numbers with no consecutive ones, we have the following recursive relation

$$ k_{m}=k_{m-1}+k_{m-2} $$

I suggest to read more about recursive relation and how to solve them. I cannot write the full answer because I am working :)

The solution is $k_{m}=\frac{3+\sqrt{5}}{2\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^{m}+\frac{-3+\sqrt{5}}{2\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^{m}$

Now the answer to your original question is $k_{n-3}$

Related Question