Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following languages is generated by the given grammar?

\[ S \rightarrow aS \mid bS \mid \varepsilon \]

  • A.\(\{a^{n}b^{m} \mid n,m \ge 0\}\)
  • B.\(\{w \in \{a,b\}^{*} \mid w\) has equal number of a’s and b’s \(\}\)
  • C.\(\{a^{n} \mid n \ge 0\}\) \(\cup\) \(\{b^{n} \mid n \ge 0\}\) \(\cup\) \(\{a^{n}b^{n} \mid n \ge 0\}\)
  • D.\(\{a,b\}^{*}\)

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.