GATE Computer ScienceHardGATE CS (PYQ pattern)

The language generated by S → aSbS | ε is

  1. A. { w : n_a(w) = n_b(w) }
  2. B. { aⁿbⁿ : n ≥ 0 }
  3. C. { w : every prefix has n_a ≥ n_b }
  4. 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

Exams that ask this topic