GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For the grammar S → aS | Sb | aSb | c, how many distinct parse trees does the string aacbb have?

  1. A. 6
  2. B. 10
  3. C. 8
  4. D. 13

Correct answer: D. 13

Each tree is a single spine of rule applications; an a-step (aS), a b-step (Sb) or a combined step (aSb) peels off an outer a, b or both, ending in c. With 2 a's and 2 b's: k combined steps (k = 0, 1, 2) leave 2 − k a-steps and 2 − k b-steps, ordered in (4 − k)!/(k!(2−k)!(2−k)!) ways: 6 + 6 + 1 = 13 (a Delannoy number; 6 forgets aSb).

More Theory of Computation questions

Exams that ask this topic