GATE Computer ScienceModerateGATE CS (PYQ pattern)
How many strings of length at most 6 are generated by S → aSa | bSb | aa | b?
- A. 14
- B. 28
- C. 15
- D. 12
Correct answer: A. 14
Every string is a palindrome whose centre is b (odd lengths) or aa (even lengths), with free outer halves. Length 1: b; 2: aa; 3: 2; 4: 2; 5: 4; 6: 4. Total 1 + 1 + 2 + 2 + 4 + 4 = 14 (ε is not generated; 28 counts every non-empty palindrome up to length 6, ignoring the fixed centres).
More Theory of Computation questions
- The following grammars all generate subsets of {a, b}, with S as the start symbol. Exactly one of the four grammars is unambiguous; which…
- Parser generators reject ambiguous grammars. Consider these CFGs (start symbol S). Exactly one of the four grammars is ambiguous; which one?
- Each option is a CFG over {a, b} with start symbol S. Exactly one of the four grammars is ambiguous; which one?
- A PDA with start state q0, bottom symbol Z, input alphabet {a, b} and accepting state qf (acceptance by final state) has transitions…
- A PDA with start state q0 and bottom symbol Z accepts by EMPTY STACK. Its transitions (stack top written first) are: δ(q0, a, Z) = {(q0…
- A nondeterministic PDA (start q0, bottom symbol Z, final state qf, acceptance by final state) has the rules: in q0 it pushes A or B for…