All mock tests are FREE till 31 December — register to save your progress
Unit 8 · Theory of Computation and Compilers Paper 2 CS · November 2020

Which of the following grammars is (are) ambiguous? (A) S → SS | aSb | bSa | λ (B) S → aSbS | bSaS | λ (C) S → aAB, A → bBb, B → A | λ, where λ denotes the empty string

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. (A) and (C) only

Explanation

In A, S → SS can split a string in several ways. In C, abbbb can be derived with the inner B or the outer B producing the second bb, giving two parse trees.

Note: no option is fully correct; the official key (A) is shown. Grammar B is also ambiguous (abab has two parse trees), so strictly all three are ambiguous; no option says so. The official key is A.

More Theory of Computation and Compilers questions