I'm a bit stuck with this problem and I'm sorry if this sounds newbie, I havent had much practice with recurrence relations. My approach was to split the problem into two cases, we let $a_n$ denote all legal binary strings of length $n$
- Appending $1$ to the front of a string, this case is simple because no illegal strings can be made by appending $1$ in front of a legal string, so by appending $1$ to all legal strings of length $n-1$ we get $a_{n-1}$ legal strings.
- Appending $0$ to the front of a string, this is where I get stuck.
My idea was to split the second case into even further cases so that each case would deal with the following prefixes: $00$, $01$, $10$ and $11$
The problem is that I can not find any good way to determine how many of each prefix occurs in the set of legal strings of length $n-1$. Any advice on this problem (or this subject in general) would be greatly appreciated since there is clearly something that I'm misunderstanding.
Let $a_n$ be the number of n-length sequences ending with $1$, $b_n$ the number of n-length sequences ending with $0$, but not with $00$ and $c_n$ the number of n-length sequences ending with $00$, but not with $000$. Obviously the wanted number is $a_n+b_n+c_n$.
Now we can take any of the sequence of the valid sequences of length $n$ and add $1$ to it and it will be a valid sequence of length $(n+1)$. Hence:
$$a_{n+1} = a_n + b_n + c_n$$
Now the only way to "construct" a sequence ending in a single zero is to take any of the $a_n$ sequences and append $0$ to it. Similarly the only way to "construct" a sequence ending in two zeroes is to take any of the $b_n$ sequences and append $0$ to it. Hence:
$$b_{n+1} = a_n; \quad \quad c_{n+1} = b_n = a_{n-1}$$
Therefore finally we have that:
$$a_{n+1} = a_n + a_{n-1} + a_{n-2}$$
Solving this recurrence relation for $a_1 = 1, a_2 = 2, a_3=4$ we can easily find the wanted answer.