GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length 8 over {a, b} contain aba as a substring but do NOT contain bab?

  1. A. 46
  2. B. 72
  3. C. 128
  4. D. 40

Correct answer: A. 46

Complementary counting: strings of length 8 with no bab number 114 (DFA/recurrence on the suffix state ε, b, ba); those avoiding both aba and bab are the strings whose internal runs all have length ≥ 2 — 68 of them. 114 − 68 = 46.

More Theory of Computation questions

Exams that ask this topic