[Math] Combinatorics, Ternary strings

combinatorics

A ternary string is a sequence of 0s, 1s, and 2s. How many ternary strings of
length 15 are there? How many of those strings contain exactly seven 0s, five
1s, and three 2s? How many ternary strings of length 15 have even weight, i.e.,
contain an even number of 1s?

(1) there are 3^(15) of length 15.
The second two parts I'm not sure about
I know for a binary string (n choose w) will give you the number of strings
of length n and weight w but I'm not sure how to apply this to ternary strings.
Any help would be appreciated

Best Answer

For the balanced strings, it may be worthwhile to experiment, and find how many balanced strings have length $1$, length $2$, and length $3$. You should get $2$, $5$, $14$.

Let $a_n$ be the number of balanced strings of length $n$. We find a recurrence for the $a_n$.

There are two types of balanced string of length $n+1$: (i) the ones that end with $0$ or $3$ and (ii) the ones that end in $1$.

The Type (i) strings are obtained by appending a $0$ or $3$ to a balanced string of length $n$. So there are $2a_n$ of these.

The Type (ii) strings are obtained by appending a $0$ or $3$ to an unbalanced string of length $n$. So there are $3^n-a_n$ of these. Thus $$a_{n+1}=2a_n+3^n-a_n=a_n+3^n.$$ Now we can rapidly find $a_{15}$. We can even get a nice general formula for $a_n$.