GATE Computer ScienceHardGATE CS (PYQ pattern)
The language generated by S → aSbS | ε is
- A. { w : n_a(w) = n_b(w) }
- B. { aⁿbⁿ : n ≥ 0 }
- C. { w : every prefix has n_a ≥ n_b }
- D. { w : n_a = n_b and every prefix has n_a ≥ n_b }
Correct answer: D. { w : n_a = n_b and every prefix has n_a ≥ n_b }
Treat a as an opening and b as a closing bracket: the rule a S b S generates exactly the balanced strings. The prefix condition alone does not force equal totals.
More Theory of Computation questions
- The language generated by S → TT, T → aTb | ε is
- How many strings of length at most 6 are generated by S → aSa | bSb | aa | b?
- 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…