Let T(n) be a number of ternary strings of length 'n'.
now, we have 3 choices- these strings can end with either 0 or 1 or 2.
case 1: Ending with 1
T(n) is the number of strings having an even number of zeroes and ending with 1 only if in rest (n-1) bits has even number of zeroes.
so we have T(n-1) such strings having an even number of zeroes and ending with 1.
case 2:: Ending with 2
T(n) is the number of strings having an even number of zeroes and ending with 2 only if in rest (n-1) bits has even number of zeroes.
so again we have T(n-1) such strings ending with 2 and having an even number of zeroes.
Case 3: Ending with 0.
Now, if last bit is 0, then to make it a string containing even numbered zeroes, we should have odd numbers of zeroes in rest n-1 bits.
T(n) is the number of n bit strings with even zeroes but now what we want is the number of strings of length n-1 having 'odd numbers of zeroes', which is nothing but the complement of our T(n)
we can calculate it as follows:
number of strings of length n-1 having odd zeroes= total strings possible with n-1 bits- strings of length n-1 with even zeroes
= 3(n-1) - T(n-1)
so T(n)= T(n-1) + T(n-1) + 3(n-1) - T(n-1)
T(n) = T(n-1) + 3(n-1)