GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For the grammar S → SaS | SS | b, how many distinct parse trees does the string bbabb have?
- A. 2
- B. 5
- C. 3
- D. 6
Correct answer: B. 5
If the root uses S → SaS, the single a splits bbabb into bb and bb, each with exactly 1 tree (S → SS): 1 tree. If the root uses S → SS, split into nonempty parts both derivable: b | babb (1 × 2) and bbab | b (2 × 1); bb | abb and bba | bb fail since a part cannot start or end with a. babb has 2 trees (b·abb impossible, so SaS with b|bb, or SS with bab|b). Total 1 + 2 + 2 = 5.
More Theory of Computation questions
- For the grammar E → E + E | E E | a (no precedence or associativity rules), the string a+aa+aa has 14 parse trees. In how many of them is…
- For the grammar S → SS | aSb | ab, how many distinct parse trees does the string ababab have?
- 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