To solve this problem, we need to derive a recurrence relation for ai, where ai represents the number of sequences of length i composed of the symbols 0, 1, and 2, such that 1 is never immediately to the right of 2.
Step 1: Understand the constraints
- Each sequence can consist of the symbols 0, 1, or 2.
- The restriction is that 1 cannot appear immediately after 2. For example:
- Valid sequences:
Step 2: Define the recurrence relation
Let us break down the problem by considering how a valid sequence of length i can be constructed from shorter sequences:
Case 1: The sequence ends with 0
If the sequence ends with 0, then the first i−1 symbols can form any valid sequence of length i−1. Thus, there are a such sequences.
Case 2: The sequence ends with 1
If the sequence ends with 1, then the first i−1 symbols can form any valid sequence of length i−1. Again, there are a such sequences.
Case 3: The sequence ends with 2
If the sequence ends with 2, then the symbol immediately before 2 (if it exists) cannot be 1. This means the first i−1 symbols must form a valid sequence of length i−1, but we must exclude cases where the last symbol of the -length sequence is .
To handle this, let us define:
- bi: The number of valid sequences of length i that end with 1.
- ci: The number of valid sequences of length .
From the above definitions:
ai=(number of sequences ending with 0)+(number of sequences ending with 1)+(number of sequences ending with 2).
Thus:
ai=ai−1+b
Step 3: Recurrence relations for bi and ci
For bi (sequences ending with 1):
A sequence of length i that ends with 1 can be formed by appending 1 to any valid sequence of length i−1. Hence:
bi=ai−1.
For ci (sequences ending with 2):
A sequence of length i that ends with 2 can be formed by appending 2 to any valid sequence of length i−1, provided the last symbol of the i−1-length sequence is not . Thus:
ci=ai−1−b
Step 4: Combine the results
Substituting bi−1=ai−2 and into the expression for , we get:
ai=ai−1+b
Using bi−1=ai−2 and , we substitute further:
ai=ai−1+
Simplify:
ai=ai−1+2a
Finally, since bi−2=ai−3, we have:
ai=ai−1+2a
Step 5: Initial conditions
To compute ai, we need initial values:
- a1=3: The sequences are 0,1,2.
- a: The sequences are (but not ).
Final Answer
The recurrence relation is:
ai=ai−1
with initial conditions:
a1=3,a2=8,a