GATE Computer ScienceModerateGATE CS (PYQ pattern)

Which one of the following context-free grammars (start symbol S, terminals a, b) is ambiguous?

  1. A. S → aSbS | bSaS | ε
  2. B. S → aSbS | ε
  3. C. S → AB; A → aA | a; B → bB | b
  4. D. S → aSb | bSa | ε

Correct answer: A. S → aSbS | bSaS | ε

The string "abab" 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