GATE Computer ScienceVery hardGATE CSE

Consider the grammar S → a S | a S b S | ε. How many distinct parse trees does the string aaabb have?

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

Counting derivations with the recurrence over positions (the 'a S' or 'a S b S' choice at each a, matching b's to a's) gives 3 trees.

More Compiler Design questions

Exams that ask this topic