GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For the grammar S → aS | Sb | aSb | c, how many distinct parse trees does the string aacbb have?
- A. 6
- B. 10
- C. 8
- D. 13
Correct answer: D. 13
Each tree is a single spine of rule applications; an a-step (aS), a b-step (Sb) or a combined step (aSb) peels off an outer a, b or both, ending in c. With 2 a's and 2 b's: k combined steps (k = 0, 1, 2) leave 2 − k a-steps and 2 − k b-steps, ordered in (4 − k)!/(k!(2−k)!(2−k)!) ways: 6 + 6 + 1 = 13 (a Delannoy number; 6 forgets aSb).
More Theory of Computation questions
- For the grammar S → SaS | SS | b, how many distinct parse trees does the string bbabb have?
- 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?