GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length 6 over {a, b} match the regular expression (a + ab)*(b + ba)*?

  1. A. 46
  2. B. 34
  3. C. 41
  4. D. 32

Correct answer: C. 41

Enumerating all 64 strings of length 6 and testing each against the expression (the regex is ambiguous, so count strings, not matches) gives 41.

More Theory of Computation questions

Exams that ask this topic