find the number of sequences of length n above {0,1,2} that start and end with 0 and without 2 successive digits that are equal (00,11,22). Find and solve a recursice equation.
I would be thankful for a clue or an approach to this.
find the number of sequences of length n above {0,1,2} that start and end with 0 and without 2 successive digits that are equal (00,11,22). Find and solve a recursice equation.
I would be thankful for a clue or an approach to this.
On
It's the number of closed walks on the graph $K_3$. So if we define $$ A= \begin{bmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \\ \end{bmatrix} $$ then it's the number in cell $(1,1)$ of $A^n$.
Computing this gives $$ 0, 2, 2, 6, 10, 22, 42, 86, 170, 342, 682, \ldots $$ when $n \geq 1$, which is OEIS's A078008.
There's a linear recurrence given there $$ a(n) = 3a(n-2) + 2a(n-3) $$ which follows directly from the identity $$ A^4 = 3A^2+2A. $$ And if we use the usual methods for solving linear recurrences, we'd get the closed form solution at OEIS: $$ a(n) = \frac{1}{3}(2^n + 2(-1)^n). $$
Since valid strings start with $0$ we have \begin{align*} a_1=1\qquad b_1=0\qquad c_1=0\tag{1} \end{align*}
Valid strings do not have equal consecutive characters. The recurrence relation for $2\leq k\leq n-1$ is \begin{align*} a_k&=b_{k-1}+c_{k-1}\\ b_k&=a_{k-1}+c_{k-1}\tag{2}\\ c_k&=a_{k-1}+b_{k-1} \end{align*} and since the $n$-th character of a valid string is $0$, we have for $n\geq 2$: \begin{align*} a_n=b_{n-1}+c_{n-1}\tag{3} \end{align*}
The last line was calculated with some help of Wolfram Alpha.