GATE Computer ScienceHardGATE CSE

The grammar S → SS | a | b is ambiguous. How many distinct parse trees does it give for the string ababa?

  1. A. 5
  2. B. 10
  3. C. 24
  4. D. 14

Correct answer: D. 14

Parse trees correspond to full binary bracketings of 5 leaves: Catalan(4) = 14.

More Theory of Computation questions

Exams that ask this topic