GATE Computer ScienceHardGATE CS (PYQ pattern)
For the grammar E → E + E | E * E | a (no precedence or associativity rules), the string a+a*a+a*a has 14 parse trees. In how many of them is the operator at the ROOT a *?
- A. 4
- B. 5
- C. 10
- D. 7
Correct answer: D. 7
Choose the root operator and multiply the tree counts of the two sides (Catalan numbers by operand count). Root = 1st *: left a+a (1 tree) × right a+a*a (2 trees) = 2. Root = 2nd *: left a+a*a+a (4 operands, 5 trees) × right a (1) = 5. Total 7; the other 7 trees have a + at the root.
More Theory of Computation questions
- 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
- The grammar S → aSb | Sb | b generates { aⁿbᵐ : m > n ≥ 0 }. How many distinct parse trees does the string aabbbb have?