GATE Computer ScienceHardGATE CS (PYQ pattern)

Each option is a CFG over {a, b} with start symbol S. Exactly one of the four grammars is ambiguous; which one?

  1. A. S → aSb | bS | ε
  2. B. S → aS | aSb | ε
  3. C. S → aSb | A; A → aA | ε
  4. D. S → aSa | bSb | a | b | ε

Correct answer: B. S → aS | aSb | ε

The string "aab" has 2 distinct parse trees under it. In each of the other grammars every string of length ≤ 8 has exactly one parse tree (and each is a standard unambiguous pattern).

More Theory of Computation questions

Exams that ask this topic