Which of the following languages is generated by the given grammar?
\[ S \rightarrow aS \mid bS \mid \varepsilon \]
GATE CS - 2016,
Answer: D
The grammar generates \(\{a,b\}^{*}\).
\(S \rightarrow aS \mid bS \mid \varepsilon\) lets each step add either an a or a b at the front and continue, or stop. Any string of a's and b's in any order, including the empty string, can be built letter by letter, so the language is all strings over \(\{a, b\}\).
\(\{a^{n}b^{m}\}\) forces all a's before the b's, but the grammar also gives ba. Nothing in the grammar counts letters, so the 'equal number' and \(a^{n}b^{n}\) options are far too narrow, and the grammar also produces strings like aab.
Please log in or register to report this question.