GATE Computer ScienceVery hardGATE CSE

How many strings of length 10 over {a, b} belong to the language of (a+b)*(aab + bba)(a+b)*, that is, contain aab or bba as a substring?

  1. A. 20
  2. B. 1040
  3. C. 1004
  4. D. 956

Correct answer: C. 1004

Counting the strings that avoid both aab and bba (there are 20 of them, via a small suffix-tracking automaton or direct enumeration) leaves 1024 − 20 = 1004 that contain one of them.

More Theory of Computation questions

Exams that ask this topic