Skip to content
Official PYQ · 2025

GATE CS 2025 Set 1 Q9 — Context-free Grammars and Push-down Automata

Explain with AI

Consider the following context-free grammar GG, where S,AS, A, 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∣AbbA→a∣aAB→b∣bB\begin{array}{l} S \rightarrow a a B \mid A b b \\ A \rightarrow a \mid a A \\ B \rightarrow b \mid b B \end{array}
Which ONE of the languages L(G)L(G) is accepted by GG ?

Choose one option
View worked solution

Answer: A

To find the language L(G)L(G) accepted by the context-free grammar GG, we can analyze the production rules step-by-step.

Step 1: Analyze the variables AA and BB

  • The production rule for AA is:
    A→a∣aAA \rightarrow a \mid aA
    This generates any sequence of one or more aa's. Thus, the language generated by AA is:
    L(A)={an∣n≥1}L(A) = \{a^n \mid n \geq 1\}
  • The production rule for BB is:
    B→b∣bBB \rightarrow b \mid bB
    This generates any sequence of one or more bb's. Thus, the language generated by BB is:
    L(B)={bn∣n≥1}L(B) = \{b^n \mid n \geq 1\}

Step 2: Analyze the start variable SS

The production rule for SS has two alternative branches: S→aaBS \rightarrow aaB and S→AbbS \rightarrow Abb. We evaluate each branch separately:

  1. First branch (S→aaBS \rightarrow aaB):

    Substituting the language of BB, we get:

    aa⋅L(B)={a2bn∣n≥1}aa \cdot L(B) = \{a^2 b^n \mid n \geq 1\}
  2. Second branch (S→AbbS \rightarrow Abb):

    Substituting the language of AA, we get:

    L(A)⋅bb={anb2∣n≥1}L(A) \cdot bb = \{a^n b^2 \mid n \geq 1\}

Step 3: Combine the branches

Since SS can derive either of the two branches, the language L(G)L(G) is the union of the languages generated by both branches:

L(G)={a2bn∣n≥1}∪{anb2∣n≥1}L(G) = \{a^2 b^n \mid n \geq 1\} \cup \{a^n b^2 \mid n \geq 1\}

This matches Option A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions