• edited by
4,170 views
22 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 ?

1 Answer

1 1 vote

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.

Position:
Show:

Related questions

1 1 vote
2 2 answers
1.8k
1.8k views
aditi19 asked May 14, 2019
1,811 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 0 votes
0 0 answers
927
927 views
aditi19 asked May 14, 2019
927 views
What is the general form of the particular solution guaranteed to exist of the linear nonhomogeneous recurrence relation$a_n$=$6a_{n-1}$-$12a_{n-2}$+$8a_{n-3}$+F(n) ifF(n...
0 0 votes
0 0 answers
1.2k
1.2k views
aditi19 asked May 13, 2019
1,163 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}$
0 0 votes
1 1 answer
1.3k
1.3k views
aditi19 asked Apr 29, 2019
1,287 views
How many bit sequences of length seven contain an even number of 0s?I’m trying to solve this using recurrence relationIs my approach correct?Let T(n) be the string having...