(a) Find a recurrence relation for the number of ternary strings of length $n$ that do not contain two consecutive 0s or two consecutive 1s.

592 Views Asked by At

I tried this in a way like my assumption is that $${T_n}$$ be a string with no consecutive zeros and one's,and now calculating for starting bits in the sequence is as follows

01=$$T_{n-2}$$

02=$$T_{n-2}$$

2=$$T_{n-1}$$

so I got the answer as $${T_n}=2*T_{n-2}+T_{n-2}$$

But the given answer is $${T_n}=2*T_{n-1}+T_{n-2}$$.

1

There are 1 best solutions below

0
On

There might be easier ways to think about it (combinatorics is like that), but here is my idea.

Let's think about the $T_n$ sequences of length $n$. Clearly, $T_{n-1}$ of them end in 2. Of the rest, because of the $0-1$ symmetry in the problem, half of them end in $0$ and half in $1$, which is $\frac12(T_n-T_{n-1})$.

So how many sequences of length $n+1$ will there be? Of the sequences that end in $2$, there are three allowable ways to add a trit to the end. (A trit is a ternary digit.) Of the sequences that end in $0$ or $1$, there are two allowable trits that can continue the sequence since you cannot repeat that last trit. Therefore,

$$T_{n+1}=3T_{n-1}+2\left(\frac12(T_n-T_{n-1})\right)=3T_{n-1}+T_n-T_{n-1}=T_n+2T_{n-1}$$