How many words of length $n$ over the alphabet $\{0,1, 2\}$ contain an even number of zeros?

1.2k Views Asked by At

How many words of length $n$ over the alphabet $\{0,1, 2\}$ contain an even number of zeros?

I can't understand why it isn't $3^{n-1} \cdot 2$.

For $n-1$ letters, we have $3$ options. That means $3^{n-1}$.

And then for the last letter ($n$), we have two cases:

first - if there were odd zeros the last letter will be $0$ ($1$ option)

second - if there were even zeros, the last letter will be $1$ or $2$ ($2$ options)

means $3^{n-1} \cdot 2$

Why am I wrong?

THX

2

There are 2 best solutions below

0
On

OP's solution is wrong, because it is not always 2 choices for the last digit -- it can be either 1 choice or 2 choices. All that OP's solution proves is that the answer is in the interval $$[1\cdot 3^{n-1},2\cdot 3^{n-1}]$$

0
On

vadim123 explains why what you have doesn't give an exact formula: you don't know how often there is $1$ choice for the final place and how often there are $2$.

However, these depend on whether there are an odd or even number of 0s in the first $n-1$ places. Write $a_{n-1}$ for the number of sequences of length $n-1$ with an even number of places. There are $3^{n-1}$ possible sequences of length $n-1$. In $a_{n-1}$ of these, you have $2$ choices for the final place to make the total number of 0s even, and in the remaining $3^{n-1}-a_{n-1}$ times you only have $1$ choice. Can you deduce and solve a recurrence relation based on this?