[Math] Recurrence relation for the number of ternary strings of length $ n$ with an even number of $0’$s

recurrence-relations

Recurrence relation for the number of ternary strings of length $ n$ with an even number of $0'$s

My try:

Case 1: We have an $n $ digit sequence with an even number of $0$'s and an even number of $1'$s.

Case 2: We have an even number of $0$'s, but an odd number of $ 1$'s.

For Case 1: for 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}$

Best Answer

Assuming you mean ternary:

There are $3^n$ strings with no constraints. Let $E_n$ be the number of strings of length $n$ with evenly many $0's$ and $O_n$ the number with oddly many. Then, of course, $E_n+O_n=3^n$.

To get an even string of length $n$ we take an arbitrary string of length $n-1$ and append $0$ if your choice is odd, and $1$ or $2$ if your choice is even. Thus we obtain the recursion $$E_n=O_{n-1}+2E_{n-1}=3^{n-1}+E_{n-1}$$

Of course we have $E_1=2$, namely $\{1,2\}$.

This is easily resolved, to see that $$E_n=\frac {3^n+1}2$$