Question

Consider the following context-free grammar GG, where SS, AA, and BB are the variables (non-terminals), aa and bb are the terminal symbols, SS is the start variable, and the rules of GG are described as:

S→aaB∣AbbS \to aaB \mid Abb
A→a∣aAA \to a \mid aA
B→b∣bBB \to b \mid bB

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

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2025 answer key

Solution

Find the languages generated by non-terminals AA and BB and take the union of the two productions of SS.

  • Non-terminal A→a∣aAA \to a \mid aA generates all non-empty strings of aa's: L(A)={an∣n≥1}L(A) = \{a^n \mid n \ge 1\}.
  • Non-terminal B→b∣bBB \to b \mid bB generates all non-empty strings of bb's: L(B)={bn∣n≥1}L(B) = \{b^n \mid n \ge 1\}.
  • Substituting into S→aaB∣AbbS \to aaB \mid Abb gives:
L(G)={a2bn∣n≥1}∪{anb2∣n≥1}L(G) = \{a^2 b^n \mid n \ge 1\} \cup \{a^n b^2 \mid n \ge 1\}
Final answer

Option (A)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2025 Computer Science and Information Technology - Session 1 (CS1)
Question
19 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.