Skip to main content

GATE CSE 2023Theory of Computation › Context-Free Languages & Pushdown AutomataVerified

GATE CSE 2023 PYQ: Consider the context-free grammar G G G below S → a S b ∣ X X → a X ∣ X b ∣ a ∣ b , \begin{array}{l} S…

Consider the context-free grammar GG below
S→aSb∣XX→aX∣Xb∣a∣b, \begin{array}{l} S \rightarrow a S b \mid X \\ X \rightarrow a X \mid X b \mid a \mid b, \end{array}
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?\text{CORRECT}?

  1. A
    The language generated by GG is (a+b)∗(a+b)^{\ast}
  2. B
    The language generated by GG is a∗(a+b)b∗a^{\ast}(a+b) b^{\ast}
    Correct answer
  3. C
    The language generated by GG is a∗b∗(a+b)a^{\ast} b^{\ast}(a+b)
  4. D
    The language generated by GG is not a regular language

Answer

(B) The language generated by G G G is a ∗ ( a + b ) b ∗ a^{\ast}(a+b) b^{\ast} a ∗ ( a + b ) b ∗

Approach

Determine the language generated by X first, then substitute it into S's recursive production S -> aSb | X. X generates any nonempty string of the form $a^m b^n$. Wrapping such a string with k layers of a...b from S yields all nonempty strings of the form $a^*b^*$, which matches option B.

The grammar generates exactly the nonempty strings consisting of zero or more a's followed by zero or more b's. This is the regular expression $a^*(a+b)b^*$, so option B is correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.