GATE Computer ScienceModerateGATE CS (PYQ pattern)

For the grammar S → SS | aSb | ab, how many distinct parse trees does the string ababab have?

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

Correct answer: B. 2

The string is three blocks ab. The rule aSb cannot wrap the middle part baba (it is not generated by S), so only SS splits count: the two bracketings (ab·ab)·ab and ab·(ab·ab), giving 2.

More Theory of Computation questions

Exams that ask this topic