GATE Computer ScienceVery hardGATE CSE · ISRO

Which regular expression (over {a, b}, + means union) generates exactly the strings with an even number of b's?

  1. A. (a*ba*b*)*
  2. B. (a + bb)*
  3. C. a*(ba*b)*
  4. D. (a*ba*b)*a*

Correct answer: D. (a*ba*b)*a*

(a*ba*b)*a* groups b's in pairs with arbitrary a's around them, so every even-b string is generated and no odd one is. (a*ba*b*)* equals Σ*, and (a + bb)* misses abab.

More Theory of Computation questions

Exams that ask this topic