GATE Computer ScienceVery hardGATE CSE

Consider the grammar S → aSbS | bS | ε over {a, b}. How many strings of length exactly 9 does it generate?

  1. A. 136
  2. B. 114
  3. C. 126
  4. D. 252

Correct answer: C. 126

Enumerating the language by closure of the productions up to length 9 gives 126 strings of length 9 (every a is matched by a later b).

More Theory of Computation questions

Exams that ask this topic