Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

  • GATE CS
  • 2026–27 pattern practice
  • Theory of Computation
  • Context-free grammars
  • Easy

Which language is generated by the grammar S→aSb∣εS \to aSb \mid \varepsilon?

Context-Free Languages

Pick an option to check your answer.

Each use of S→aSbS \to aSb adds one aa on the left and one bb on the right, and ε\varepsilon stops. So the strings are ε,ab,aabb,…\varepsilon, ab, aabb, \ldots — exactly anbna^n b^n with n≥0n \ge 0.

Why not the others

  • {ambn}\{a^m b^n\} allows unequal counts.
  • (ab)∗(ab)^* gives abababab, which this grammar cannot derive.
  • n≥1n \ge 1 excludes ε\varepsilon, which the grammar generates.

Report an error

GATE CS · Theory of Computation · Context-Free Languages