edited by
1,636 views
22 votes
22 votes
What is the recurrence relation for the  ternary strings of length $n$ which can be constructed using 0,1 or 2 only such that the  number of 0’s and number of 1's is odd ?
edited by

1 Answer

1 votes
1 votes

Let T(n) be the number of ternary strings of length n in which the number of 0's and the number of 1's is odd.

Consider the last digit of a ternary string of length n:

  • If the last digit is 0, then the remaining n-1 digits must have an even number of 0's and an odd number of 1's.
  • If the last digit is 1, then the remaining n-1 digits must have an odd number of 0's and an even number of 1's.
  • If the last digit is 2, then the remaining n-1 digits can have any combination of 0's and 1's.

Therefore, we can write the recurrence relation as follows: T(n) = 2T(n-2) + 3^(n-1)

The first term in the recurrence relation corresponds to the cases where the last digit is either 0 or 1, and the remaining n-1 digits satisfy the conditions of the problem. There are 2 ways to choose whether the last digit is 0 or 1, and the number of valid strings of length n-2 is T(n-2).

The second term corresponds to the case where the last digit is 2, and the remaining n-1 digits can have any combination of 0's and 1's. There are 3 possible digits that can be used for each of the n-1 positions, so the total number of valid strings of length n with a last digit of 2 is 3^(n-1).

The initial conditions for the recurrence relation are: T(0) = 0 T(1) = 0 T(2) = 2 (the two valid strings are "01" and "10")

Using the recurrence relation and the initial conditions, we can compute T(n) for any positive integer n.

Related questions

1 votes
1 votes
2 answers
1
aditi19 asked May 14, 2019
872 views
What will be solution of recurrence relation if roots are like this: r1=-2, r2=2, r3=-2, r4=2is this the case of repetitive roots?
0 votes
0 votes
0 answers
2
0 votes
0 votes
0 answers
3
aditi19 asked May 13, 2019
668 views
Consider the nonhomogeneous linear recurrence relation $a_n$=$3a_{n-1}$+$2^n$in the book solution is given $a_n$=$-2^{n+1}$but I’m getting $a_n$=$3^{n+1}-2^{n+1}$