Let Sn be the number of ternary strings of length n in which every 1 is followed immediately by a 2 (these strings cannot end with a 1). Find an expression for Sn+1 in terms of Sn and Sn-1 which holds for all n >= 2.
I have no idea how to solve this. I got the base cases S1 = 2 and S2 = 5 but I don't know how to proceed from here
Take a ternary string of length $n + 1$, and break it down into cases: does it end in $2$ or $0$?
If it ends in $0$, then removing that $0$ will result in a string counted by $S_n$. Moreover, any string counted by $S_n$ can have a $0$ tacked on the end and become a string counted by $S_{n+1}$ (since, of course, no such string can end in $1$).
If it ends in $2$, then we must be more careful. Removing the $2$ could expose a $1$ at the end of the string. So, we have two sub-cases. Either the string ends in $12$, or it ends in $02$ or $22$. If it ends in $12$, then removing these two terms will result in a string counted by $S_{n - 1}$, and conversely, any such string can have $12$ added to the end in order to make a string counted by $S_{n + 1}$.
Otherwise, if it ends in $02$ or $22$, then removing the last $2$ will produce a string counted by $S_n$ (and the converse holds too).
So, the first case, when the string ends in $0$, produces exactly $S_n$ strings.
The second case had two subcases: when the string ends in $12$, there are exactly $S_{n - 1}$ such strings. When the string ends in $02$ or $22$, there are exactly $S_n$ strings.
Putting it together, we get $$S_{n + 1} = 2S_n + S_{n - 1}.$$