Question

# 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. b) What are the initial conditions? c) How many ternary strings of length six do not contain two consecutive 0s or two consecutive 1s?

Solution

Verified
4.7 (5 ratings)
4.7 (5 ratings)
Step 1
1 of 4

(a) Let $a_n$ represent the number of ternary strings of length $n$ that do not contain a pair of consecutive 0's nor a pair of consecutive 1's.

$\textbf{First case }$ If the ternary string starts with a $2$, then the ternary string of length $n-1$ (ignore the first 2) can start with a 0, 1 or 2 and thus there are $a_{n-1}$ such strings starting with a 2 followed by strings of length $n-1$.

$\textbf{Second case }$ For each $k$ between 0 and $n-2$, there could be string of $n-1-k$ alternating 0's and 1's which is followed by a 2 and then followed by no pair of consecutive 0's nor 1's, while there are then $2a_{n-(n-k)}=2a_{k}$ such strings ($a_k$ for 0 and $a_k$ for 1).

$\textbf{Third case}$ The ternary string contains no 2's and thus contains only alternating 0's and 1's. There are 2 such possible strings (one starting with 0 and one starting with 1).

Adding the number of sequences of all three cases, we then obtain:

$a_n=a_{n-1}+2a_{n-2}+2a_{n-3}+...+2a_0+2$

Similarly, we also have for $n-1$:

$a_{n-1}=a_{n-2}+2a_{n-3}+2a_{n-4}+...+2a_0+2$

Subtract the previous two equations:

$a_n-a_{n-1}=a_{n-1}+a_{n-2}$

Add $a_{n-1}$ to each side of the previous equation:

$a_n=2a_{n-1}+a_{n-2}$

## Recommended textbook solutions

#### Discrete Mathematics and Its Applications

7th EditionISBN: 9780073383095 (9 more)Kenneth Rosen
4,283 solutions

#### Discrete Mathematics

8th EditionISBN: 9780321964687Richard Johnsonbaugh
4,246 solutions

#### Advanced Mathematics: Precalculus with Discrete Mathematics and Data Analysis

ISBN: 9780395551899Brown
4,887 solutions

#### Discrete Mathematics and Its Applications

8th EditionISBN: 9781259676512Kenneth Rosen
4,397 solutions