TITLE: Find the recurrence relation for the number of bit strings that contain the string $01$.
QUESTION [7 upvotes]: Question:Find the recurrence relation for the number of bit strings that contain the string $01$.
Attempt:
Since $01$ can appear in a lot of places, I focused on instances without $01$ first.
Bit strings without $01$ in a bit string of length $n$. Let $XX\dots X$ be bit string without $01$:

$XX\dots X0$
$1XX\dots X$

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$$
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,
$$P_n = 2^n - a_n = 2^n - 2a_{n-1}, a_2 = 1$$
Since $P_n = 2^n - a_n$, then, $a_n = 2^n - P_n$, thus
$$P_n = 2^n - 2*(2^{n-1} - P_{n-1})$$
$$\iff P_n = 2^n - 2^n + 2P_{n-1}$$
$$P_n = 2P_{n-1}, P_2 = 1$$
Problem:
I've also played around with the n-combination to solve this. The format of a bit string without $01$ is the following,
$$1\dots10\dots0$$
Adding $0$ or $1$ to either side adds a $01$, thus we can only add either $1$ on the left and $0$ on the right. Another way to view this is,
$1^p0^q, p, q \geq 1$
The number of bit strings without $01$ is for a bit string of length $n$,
$${2 + n - 2 - 1\choose n-2} = \\
{n-1 \choose 1} = \\
n-1$$
The inverse of this is,
$$2^n - n+1$$
Which is the number of bit string with $01$ at length $n$.
If we solve the recurrence relation above for $P_n$,
$$P_3 = 2P_2 = 2$$
$$P_4 = 2*2\\
\vdots\\
P_n = 2^{n-2}$$
Which is inconsistent with the $n$-combination solution to solve this. Where did I get it wrong??

REPLY [4 votes]: 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$$