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

Discussion

Consider the following context-free grammar \(G\), where \(S\), \(A\), and \(B\) are the variables (non-terminals), \(a\) and \(b\) are the terminal symbols, \(S\) is the start variable, and the rules of \(G\) are described as:

\(S \rightarrow aaB \mid Abb\)
\(A \rightarrow a \mid aA\)
\(B \rightarrow b \mid bB\)

Which ONE of the languages \(L(G)\) is accepted by \(G\)?

  • A.\(L(G) = \{a^{2}b^{n} \mid n \ge 1\} \cup \{a^{n}b^{2} \mid n \ge 1\}\)
  • B.\(L(G) = \{a^{n}b^{2n} \mid n \ge 1\} \cup \{a^{2n}b^{n} \mid n \ge 1\}\)
  • C.\(L(G) = \{a^{n}b^{n} \mid n \ge 1\}\)
  • D.\(L(G) = \{a^{2n}b^{2n} \mid n \ge 1\}\)

Answer: A

The language is \(\{a^{2}b^{n} \mid n \ge 1\} \cup \{a^{n}b^{2} \mid n \ge 1\}\).

B generates \(b^{n}\) for \(n \ge 1\) and A generates \(a^{n}\) for \(n \ge 1\). The first rule \(S \rightarrow aaB\) therefore gives exactly two a's followed by one or more b's, \(a^{2}b^{n}\). The second rule \(S \rightarrow Abb\) gives one or more a's followed by exactly two b's, \(a^{n}b^{2}\). The language is the union of the two.

The other options demand a link between the numbers of a's and b's (such as \(a^{n}b^{n}\) or \(a^{n}b^{2n}\)), but in this grammar the a's and b's are generated by separate rules with nothing tying the counts together. For example aabbb is in L(G) but has unequal counts.

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

Post your comment

Please log in or register to post a comment.