GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The grammar S → aSb | SS | ab generates 14 strings of length 8. How many of these strings have MORE than one parse tree?

  1. A. 5
  2. B. 1
  3. C. 4
  4. D. 9

Correct answer: A. 5

The rule S → SS makes a string with k ≥ 3 top-level blocks ambiguous (Catalan(k−1) ways to bracket them). Length 8: abababab (4 blocks, 5 trees); aabbabab, abaabbab, ababaabb (3 blocks, 2 trees each); and one single block whose inside has 3 blocks, aabababb (2 trees). Total 5.

More Theory of Computation questions

Exams that ask this topic