Computer Science EngineeringHardISRO SC

The grammar S -> aS | Sa | a is ambiguous. How many parse trees does a^5 have?

  1. A. 17
  2. B. 15
  3. C. 16
  4. D. 5

Correct answer: C. 16

Counting by whether the root uses aS, Sa, or (for n=1) a: T(1)=1, T(n)=2T(n-1) giving 16.

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

Exams that ask this topic