Computer Science EngineeringHardISRO SC

With the ambiguous grammar E -> E + E | E * E | id, how many distinct parse trees does the string id + id * id + id * id + id * id have?

  1. A. 132
  2. B. 134
  3. C. 131
  4. D. 36

Correct answer: A. 132

With n=6 binary operators, the number of full binary bracketings is the Catalan number C_6 = 132; precedence is not encoded in the grammar.

More Theory of Computation, Compilers & Digital Logic (ISRO CS) questions

Exams that ask this topic