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??