Consider ternary strings (consisting of only numbers $0,1,2$).
For $n\geq 1$, let $a_n$ be the number of ternary strings of length $n$, where there are no consecutive $1$'s or $2$'s.
Find a relation for $a_n$.
This is my attempt:
Call a ternary string "good" if if does not contain consecutive $1$'s or $2$'s.
Case 1: The first digit is a $0$.
So we can then form a good string in $a_{n-1}$ ways.
Case 2: The first two digits start with $10$ or $20$.
Then we can form a good string in $2 \times a_{n-2}$ ways.
Case 3: First two digits are $12$.
We do not want the third digit to be a $2$. So we count the number of ways to form a good string of length $n-2$ less the number of ways to form a string of length $n-3$, given the first three digits are $122$.
This is done in $a_{n-2} - a_{n-3}$ ways.
Case 4: First two digits are $21$. This is similarly done in $a_{n-2}-a_{n-3}$ ways.
So the total is $a_n = a_{n-1} + 4a_{n-2} - 2a_{n-3}$.
However, the solution says that it is
$a_n = 2a_{n-1}+a_{n-2}$.
Why is my answer incorrect?
Sorry if I wasn't clear. Which part does it seem like I'm adding digits at the end? I only looked at the first three digits. – Natash1 Oct 29 '17 at 02:27