GATE Computer ScienceModerateGATE CS (PYQ pattern)
For the grammar S → SS | aSb | ab, how many distinct parse trees does the string ababab have?
- A. 3
- B. 2
- C. 1
- D. 6
Correct answer: B. 2
The string is three blocks ab. The rule aSb cannot wrap the middle part baba (it is not generated by S), so only SS splits count: the two bracketings (ab·ab)·ab and ab·(ab·ab), giving 2.
More Theory of Computation questions
- The grammar S → aSb | bSa | SS | ε generates how many strings of length exactly 8?
- The grammar S → aSbS | ε generates 42 strings of length 10. In how many of them does no prefix contain more than two a's in excess of b's…
- For the grammar S → aSbb | aaSb | ε, how many distinct parse trees does a⁶b⁶ have?
- The language generated by S → aSb | aSbb | ε is
- The grammar S → aSb | Sb | b generates { aⁿbᵐ : m > n ≥ 0 }. How many distinct parse trees does the string aabbbb have?
- The language generated by S → aSb | bSa | SS | ε is