GATE Computer ScienceHardGATE CS (PYQ pattern)
The grammar S → aSb | Sb | b generates { aⁿbᵐ : m > n ≥ 0 }. How many distinct parse trees does the string aabbbb have?
- A. 1
- B. 2
- C. 3
- D. 6
Correct answer: C. 3
Every tree is a spine of 2 aSb steps and 1 Sb step (4 b's = 2 from aSb + 1 from Sb + the final b) ending in b. Since the Sb step adds its b at the right end of whatever lies below, the three steps can be ordered arbitrarily: C(3, 1) = 3 trees, so the grammar is ambiguous.
More Theory of Computation questions
- The language generated by S → aSb | bSa | SS | ε is
- The language generated by S → aSbS | ε is
- The language generated by S → TT, T → aTb | ε is
- How many strings of length at most 6 are generated by S → aSa | bSb | aa | b?
- The following grammars all generate subsets of {a, b}, with S as the start symbol. Exactly one of the four grammars is unambiguous; which…
- Parser generators reject ambiguous grammars. Consider these CFGs (start symbol S). Exactly one of the four grammars is ambiguous; which one?