GATE Computer ScienceHardGATE CS (PYQ pattern)

Which regular expression denotes exactly the set of strings over {a, b} with an EVEN number of a's (zero included)?

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

Correct answer: D. (b + ab*a)*

(b + ab*a)*: each factor has 0 or 2 a's, and any even-a string splits into b's and a…a pairs: correct. (b*ab*ab*)* misses b (zero a's but non-empty). b*(ab*a)*b* allows b's only outside the a…a pairs, so it misses aabaa (4 a's: aa, b, aa). (aa + bb + ab + ba)* is even LENGTH, e.g. it contains ab.

More Theory of Computation questions

Exams that ask this topic