StreakPeaked· Practice

ExamsGATETechnical

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?

  1. The language generated by G is (a + b)*
  2. The language generated by G is a*(a + b)b*
  3. The language generated by G is a*b*(a + b)
  4. The language generated by G is not a regular language

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

Solution

S -> aSb gives a^n ... b^n wrapping X, and X -> aX | Xb | a | b generates a*(a+b)b*; the a^n/b^n wrappers are absorbed, so L(G) = a*(a+b)b*, which IS regular. Hence the correct statement is option index 1, not 'not regular'.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →