GATE Computer ScienceVery hardGATE CSE · UGC NET
The grammar S → SS | aS | a is used to parse the string a⁶ (six a's). How many different parse trees does a⁶ have?
- A. 42
- B. 394
- C. 364
- D. 494
Correct answer: B. 394
Let T(i,j) count trees for a substring: T = [length 1] + T(shorter by 1) + Σ_k T(i,k)·T(k,j). Evaluating for length 6 gives 394 (the Catalan number 42 counts only the S → SS shapes).
More Theory of Computation questions
- A Turing machine (blank B, halts when no rule applies or in state acc) has rules: q0: a→(q1,B,R), b→(q2,B,R), B→(acc,B,S); q1 and q2…
- Which regular expression (+ denotes union) denotes exactly the set of non-empty strings over {a, b} that start with a, end with a and…
- How many strings of length 10 over {a, b} belong to the language of (a+b)(aab + bba)(a+b), that is, contain aab or bba as a substring?
- Let L = { w ∈ {a, b} : (|w|a + 2·|w|b) mod 12 ∈ {1, 5, 9} }, where |w|a and |w|b count the a's and b's. What is the number of equivalence…
- Consider these problems: (a) Given a DFA M, is L(M) empty? (b) Given two CFGs G₁, G₂, is L(G₁) ∩ L(G₂) = ∅? (c) Given a TM M and input w…
- How many of the following statements are true? (i) DCFLs are closed under complement. (ii) CFLs are closed under intersection with a…