GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The grammar S → aSb | SS | ab generates 14 strings of length 8. How many of these strings have MORE than one parse tree?
- A. 5
- B. 1
- C. 4
- D. 9
Correct answer: A. 5
The rule S → SS makes a string with k ≥ 3 top-level blocks ambiguous (Catalan(k−1) ways to bracket them). Length 8: abababab (4 blocks, 5 trees); aabbabab, abaabbab, ababaabb (3 blocks, 2 trees each); and one single block whose inside has 3 blocks, aabababb (2 trees). Total 5.
More Theory of Computation questions
- How many strings of length 6 over {a, b} match the regular expression (a + ab)(b + ba)?
- An NFA over {a, b} has states 0, 1, 2, 3, start state 0 and accepting set {2,3}. Transitions: δ(0): a→{2}, b→{0,2,3}; δ(1): a→{0,1,2}…
- An NFA over {a, b} has states 0, 1, 2, 3, start state 0 and accepting set {1}. Transitions: δ(0): a→{0,1}, b→{1}; δ(1): a→{0,1,2,3}, b→∅…
- An ε-NFA over {a, b} has states 0, 1, 2, 3, start state 0 and accepting set {0,3}. Transitions: δ(0): a→{1,2}, b→{3}, ε→∅; δ(1): a→{2}…
- How many states does the minimal complete DFA have for the set of strings over {a, b} that begin with ab OR end with ab?
- How many states does the minimal complete DFA for the set of strings over {a, b} that end with abb have?