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

Discussion

Consider the context-free grammar \(G\) below

\(S \to aSb \mid X\)
\(X \to aX \mid Xb \mid a \mid b\),

where \(S\) and \(X\) are non-terminals, and \(a\) and \(b\) are terminal symbols. The starting non-terminal is \(S\).

Which one of the following statements is CORRECT?

  • A.The language generated by \(G\) is \((a+b)^{*}\)
  • B.The language generated by \(G\) is \(a^{*}(a+b)b^{*}\)
  • C.The language generated by \(G\) is \(a^{*}b^{*}(a+b)\)
  • D.The language generated by \(G\) is not a regular language

Answer: B

The language is \(a^{*}(a+b)b^{*}\).

Start with X. The rules X \(\to\) aX and X \(\to\) Xb add any number of a's on the left and b's on the right, and the derivation ends with a single a or b in the middle. So X generates \(a^{*}(a+b)b^{*}\): some a's, then one a or b, then some b's.

S \(\to\) aSb wraps that in n further a's and n further b's, giving \(a^{n}a^{*}(a+b)b^{*}b^{n}\), which is still \(a^{*}(a+b)b^{*}\). The matching counts add nothing, because X can already produce any numbers of a's and b's on its own.

\((a+b)^{*}\) includes the empty string and strings like ba, which G cannot produce, since every b comes after every a. \(a^{*}b^{*}(a+b)\) contains bba, which G cannot generate. And since the language is given by a regular expression, it is regular.

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

Post your comment

Please log in or register to post a comment.