GATE Computer ScienceVery hardGATE CSE · UGC NET

Which regular expression (+ denotes union) denotes exactly the set of non-empty strings over {a, b} that start with a, end with a and contain no two consecutive b's?

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

Correct answer: A. a(a + ba)*

Every string in a(a+ba)* starts with a, each b is followed by a (so no bb, and it ends with a); a(a+ba)*a misses "a", a(a+b)*a allows bb, (ab+a)* allows ending in b. Verified by exhaustive comparison up to length 11.

More Theory of Computation questions

Exams that ask this topic