GateAI
Context-Free Grammars and PDAs

GATE CSE 2023 · Q39

MCQ2 marksMedium

Time

Consider the context-free grammar GG below S→aSb∣XX→aX∣Xb∣a∣b , \begin{aligned} S &\to aSb \mid X X &\to aX \mid Xb \mid a \mid b\text{ ,} \end{aligned} where SS and XX are non-terminals, and aa and bb are terminal symbols. The starting non-terminal is SS. Which one of the following statements is CORRECT?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) The language generated by G is a*(a + b)b*

Context-Free Grammars and PDAs

To determine the language generated by the context-free grammar GG, let us analyze the productions step by step:

  1. Language generated by XX:

    • The non-terminal XX can add any number of leading aa's using X→aXX \to aX and any number of trailing bb's using X→XbX \to Xb.

    • The base productions are X→aX \to a and X→bX \to b.

    • Thus, every derivation from XX yields a string of the form:

      ai(a∣b)bjwhere i,j≥0a^i (a \mid b) b^j \quad \text{where } i, j \ge 0
    • This gives the regular language:

      L(X)=a∗(a+b)b∗L(X) = a^* (a + b) b^*
  2. Language generated by SS:

    • The production S→aSb∣XS \to aSb \mid X allows wrapping the string produced by XX with an equal number of aa's and bb's:

      S⇒∗anXbnfor n≥0S \Rightarrow^* a^n X b^n \quad \text{for } n \ge 0
    • Substituting the language generated by XX:

      L(G)={an(ai(a∣b)bj)bn∣n,i,j≥0}={an+i(a∣b)bn+j∣n,i,j≥0}L(G) = \{ a^n (a^i (a \mid b) b^j) b^n \mid n, i, j \ge 0 \} = \{ a^{n+i} (a \mid b) b^{n+j} \mid n, i, j \ge 0 \}
    • Since k=n+i≥0k = n + i \ge 0 and m=n+j≥0m = n + j \ge 0 can independently take any non-negative integer values, this simplifies to:

      L(G)={ak(a∣b)bm∣k,m≥0}=a∗(a+b)b∗L(G) = \{ a^k (a \mid b) b^m \mid k, m \ge 0 \} = a^*(a + b)b^*

Hence, the language generated by GG is regular and equal to a∗(a+b)b∗a^*(a + b)b^*, making (B) the correct statement.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Context-Free Grammars and PDAs previous year question is Q39 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Context-Free Grammars and PDAs in Theory of Computation, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Context-Free Grammars and PDAs PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Context-Free Grammars and PDAs in GATE CSE

Context-Free Grammars and PDAs has 26 GATE CSE PYQs across 17 papers from 2011 to 2026. 9 of them are 2-mark MCQs like this one, and GATE CSE 2023 has 2.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q39 · MCQ

Consider the context-free grammar G below S &→ aSb X X &→ aX Xb a 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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.