GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length exactly 9 are generated by the grammar S → aSbb | bSaa | SS | ε?

  1. A. 8
  2. B. 40
  3. C. 48
  4. D. 32

Correct answer: B. 40

Every string factors uniquely into 'irreducible' blocks a X bb or b X aa (X generated by S). Irreducible counts: length 3: 2 (abb, baa); length 6: 2 × 2 = 4; length 9: 2 × N(6). All strings: N(3) = 2, N(6) = 4 + 2·2 = 8, N(9) = 2·8 + 2·(2·4) + 2³ = 16 + 16 + 8 = 40. (8 is the count without S → SS.)

More Theory of Computation questions

Exams that ask this topic