GATE Computer ScienceVery hardGATE CSE · UGC NET

For the ambiguous grammar S → S S | a, how many distinct parse trees does the string aaaaaa (six a's) have?

  1. A. 30
  2. B. 56
  3. C. 42
  4. D. 14

Correct answer: C. 42

The number of parse trees of a^n is the Catalan number C(n−1); for n = 6 it is C(5) = 42.

More Compiler Design questions

Exams that ask this topic