GATE Computer ScienceVery hardGATE CSE
Consider the grammar S → aSbS | bS | ε over {a, b}. How many strings of length exactly 9 does it generate?
- A. 136
- B. 114
- C. 126
- D. 252
Correct answer: C. 126
Enumerating the language by closure of the productions up to length 9 gives 126 strings of length 9 (every a is matched by a later b).
More Theory of Computation questions
- 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 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…