GATE Computer ScienceModerateGATE CS (PYQ pattern)
The language generated by S → aSb | bSa | SS | ε is
- A. { w : n_a(w) = n_b(w) and every prefix has n_a ≥ n_b }
- B. { w w' : w' is w with a and b swapped }
- C. { aⁿbⁿ : n ≥ 0 }*
- D. { w : n_a(w) = n_b(w) }
Correct answer: D. { w : n_a(w) = n_b(w) }
Any string with equally many a's and b's can be decomposed by splitting at the first point where the counts balance, so the grammar generates all of them; it is not limited to prefix-balanced strings.
More Theory of Computation questions
- The language generated by S → aSbS | ε is
- 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?