Given the production rules of a grammar
2013
Given the production rules of a grammar

- A.
G₁ is ambiguous and G₂ is not ambiguous
- B.
G₁ is ambiguous and G₂ is ambiguous
- C.
G₁ is not ambiguous and G₂ is ambiguous
- D.
G₁ is not ambiguous and G₂ is not ambiguous
Attempted by 65 students.
Show answer & explanation
Correct answer: B
Grammar G1 is ambiguous because the string "aab" has two distinct leftmost derivations. One derivation uses S1 → aaB directly, while the other uses S1 → AB where A derives "aa".
Grammar G2 is also ambiguous, as it generates strings with equal numbers of 'a's and 'b's in multiple ways. For example, the string "ab" can be derived via S2 → aS2bS2 where the inner S2 becomes empty, but other structures exist.
Since both grammars allow multiple parse trees for specific strings, the correct classification is that both are ambiguous.
A video solution is available for this question — log in and enroll to watch it.