TITLE: The number of length-n ternary sequences with even ones and even zeroes
QUESTION [7 upvotes]: Just starting to appreciate recurrence relations
Let $T_n = $ number of length-n ternary sequences with an even number of ones and an even number of zeroes.
$T_0 = 1$, because $0$ is an even number, and there are zero $1$s and zero $0$s.
$T_1 = 1$, because the sequence $\{2\}$ has zero $1$s and zero $0$s
How to find $T_n$?
Possibility: split into cases.
Case 1: We have an $n$ digit sequence with an even number of $0$s and an even number of $1$s.
To get to length $n$, we have all of the length $n-1$ sequences with an even number of $0$s and $1$s, which is $T_{n-1}$
Case 2: We have an $n$ digit sequence with an odd number of $0$s and an odd number of $1$s.
Here, we basically need the total amount of length-$n$ sequences with an odd number of $0$s and an odd number of $1$. This should be $3^n - T_{n-1}$.
Case 3: We have an even number of 0s, but an odd number of 1s.
Case 4: We have an odd number of 0s, but an even number of 1s.
How to account for cases 3 and 4?

REPLY [2 votes]: Consider the string  $\underbrace{0\cdots0}_{2i}\underbrace{1\cdots 1}_{2j}\underbrace{2\cdots 2}_{k}$, and $2i+2j+k=n$, $i,j,k\in\Bbb N_0$. Then you're looking for $$v_n=\sum_{2i+2j+k=n}\binom{n}{2i,2j,k}$$
Note $v_0=1,v_1=1,v_2=3,v_3=7,v_4=21,v_5=81,\ldots$. This can be tackled as follows. 
We have $$w_n=\frac{v_n}{n!}=\sum_{2i+2j+k=n}\frac 1{(2i)!}\frac 1{(2j)!}\frac 1{k!}$$
Now we may write $$w_n=\sum_{k=0}^n\frac{1}{k!}\sum_{2i+2j=n-k}\frac{1}{(2i)!}\frac{1}{(2j)!}$$
that is $$w_n=\sum_{k=0}^n \frac{1}{k!}u_{n-k}$$ with $$u_n=\sum_{2i+2j=n}\frac{1}{(2i)!}\frac{1}{(2j)!}$$
It is evident that $u_{2n+1}=0$, $u_0=1$ and $(2n)!{u_{2n}}=\displaystyle\sum_{i=0}^n\binom{2n}{2i}=2^{2n-1},n\geqslant 1$ (this can be seen by expanding $2^{2n}$ as $(1+1)^{2n}$ and $0$ as $(1-1)^{2n}$ and killiog odd numbers by adding), so that for $n\geqslant 1$ $${v_n} = 1+\frac{1}{2}\sum\limits_{k\;\rm even>0}^n\binom nk2^{k} $$
This matches Andre's recurrence.