GATE Computer ScienceModerateGATE CS (PYQ pattern)

How many strings of length 8 over {a, b} begin with b and contain no aa as a substring?

  1. A. 21
  2. B. 55
  3. C. 34
  4. D. 64

Correct answer: C. 34

Let f(n) be the number of strings of length n with no aa: f(1) = 2, f(2) = 3, f(n) = f(n−1) + f(n−2), so f(7) = 34. A string starting with b is b followed by any aa-free string of length 7 (the leading b cannot create aa), giving f(7) = 34.

More Theory of Computation questions

Exams that ask this topic