How many $n$ bit strings are there that contain 3 consecutive 0's?
I found a recursion formula to get to the answer of the above question. $$a(n)=2a(n-1) + 2^{n-4} - a(n-4)$$ where $a(n)$ is the number of $n$ bit strings containing 3 consecutive 0's. Why is this so?
Please forgive me if this is a stupid question, I am a newbie!
Let $b(n)$ denote the number of bad strings of length $n$ (that is, those strings of length $n$ which do not contain $000$)
It is easier to get a recursion on the bad strings. To see that, divide $b(n)$ into three types according to the last character. Specifically:
Let $r(n)$ denote the number of bad strings of length $n$ that end in $1$
Let $s(n)$ denote the number of bad strings of length $n$ that end in $10$
Let $t(n)$ denote the number of bad strings of length $n$ that end in $100$
Then $b(n)=r(n)+s(n)+t(n)$. Recursively we get: $$r(n)=b(n-1)\quad s(n)=r(n-1)=b(n-2)\quad t(n)=s(n-2)=b(n-2)$$ whence $b(n)=b(n-1)+b(n-2)+b(n-3)$
to connect this to your recursion, we remark that we can write this as $$b(n-1)+b(n-2)=b(n)-b(n-3)\implies b(n-2)+b(n-3)=b(n-1)-b(n-4)$$ Thus we get $$b(n)=b(n-1)+\left(b(n-1)-b(n-4)\right)=2b(n-1)-b(n-4)$$
Now $a(n)=2^n-b(n)$ so we get $$a(n)=2^n-2\times(2^{n-1}-a(n-1))+(2^{n-4}-a(n-4))=2a(n-1)+2^{n-4}-a(n-4)$$ as desired.