GATE CS 2025 Set 1 | Question 19

MCQ · 1 mark · −0.33

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 \to aaB \mid Abb\)
\(A \to a \mid aA\)
\(B \to b \mid bB\)

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

  1. Option A: \(L(G) = \{a^{2}b^{n} \mid n \ge 1\} \cup \{a^{n}b^{2} \mid n \ge 1\}\) (correct)
  2. Option B: \(L(G) = \{a^{n}b^{2n} \mid n \ge 1\} \cup \{a^{2n}b^{n} \mid n \ge 1\}\)
  3. Option C: \(L(G) = \{a^{n}b^{n} \mid n \ge 1\}\)
  4. Option D: \(L(G) = \{a^{2n}b^{2n} \mid n \ge 1\}\)

Answer

(A)

Explanation

\(A \to a \mid aA\) generates \(a^{n}\) and \(B \to b \mid bB\) generates \(b^{n}\), for \(n \ge 1\).

So \(S \to aaB\) gives the strings \(a^{2}b^{n}\), and \(S \to Abb\) gives the strings \(a^{n}b^{2}\). Together, \(L(G) = \{a^{2}b^{n} \mid n \ge 1\} \cup \{a^{n}b^{2} \mid n \ge 1\}\).

The other options do not match: for example, \(aabbb \in L(G)\), but it belongs to none of (B), (C) and (D).

Answer: A