Find the recurrence relation for the number of bit strings that contain the string $01$.

Where did I get it wrong??

The number of bit-strings of length $n$ without 01 is: $n+1$. (Not $n-1$.)

You have the pattern $\underbrace{1\cdots 1}_{k}\underbrace{0\cdots 0}_{n-k}$, where the number of 1 bits, $k$, can range from $0$ to $n$.

Thus the number of $n$ length bit-strings with at least 1 substring of 01 is: $2^n-n-1$.


Thus we know we acquire twice more bit string without 01 from length of $n−1$ to $n$.

Let $a_n$ be the count of bit strings without 01 at length n , recurrence relation of this is the following:

$$a_n =2a_{n−1} ,a_2 =1$$

You are over counting. Adding 0 to the end of 110 gives the same result as adding 1 to the start of 100: namely 1100. Just count the ways to add 0 or 1 to the end of the strings and remain valid. You can viably add 0 to every valid $n-1$ length string; but there is only one viable target to which you can add 1 (the one with all 1s).

Also there are three string of length 2 which do not contain 01: namely 00, 10, 11.

$$a_n = a_{n-1}+1, a_2=3$$

Thus the valid 3-length strings are: 000, 100, 110, and 111. $a_n=4$ as expected.

(Always test your logic on the simplest examples. )

The inverse of this is then the recurrence relation with 01 . Let $P_n$ be the recurrence relationship of the number of bit string with length $n$ with 01 , thus,

Applying the correct formula: $$\begin{align} P_n & = 2^n - a_{n} \\ & = 2\cdot 2^{n-1} - (a_{n-1} + 1) \\ & = P_{n-1} + 2^{n-1} - 1 \\[2ex] P_2 & = 1 & 2^2-3 \\P_3 & = 1+4-1 = 4 & 2^3-4 \\P_4 & = 4+8-1 = 11 & 2^4 - 5 \\ \text{et cetera} \end{align}$$


Every following "form" is a $n$ bit string.

Bit strings of the form ....$\_$ $\_$$0$ contributes $a_{n-1}$ to the total count.

Bit strings of the form ....$\_$ $\_$$01$ contributes $2^{n-2}$ to the total count.

Bit strings of the form ....$\_$ $\_$$011$ contributes $2^{n-3}$ to the total count.

$\vdots$

Bit strings of the form $011...1$ contributes $2^{n-n}$ to the total count.

Bit strings of the form $111...1$ contributes nothing to the total count.

All the bit strings of length $n$ have been considered.


Therefore, $a_{n}= a_{n-1}+2^{n-2}+2^{n-3}+...+2^{n-n}$

applying sum of G.P,we get,

$$a_{n}= a_{n-1}+2^{n-1}-1$$