GATE Computer ScienceHardGATE CS (PYQ pattern)

How many strings of length 20 over {a, b} do not contain aaa as a substring?

  1. A. 917504
  2. B. 223317
  3. C. 13530
  4. D. 224317

Correct answer: B. 223317

Classify by the trailing block of 0, 1 or 2 a's: t(n) = t(n−1) + t(n−2) + t(n−3) (tribonacci-type recurrence with t(0) = 1, t(1) = 2, t(2) = 4). For n = 20 this is 223317.

More Theory of Computation questions

Exams that ask this topic