GateAI
Context-Free Grammars and PDAs

GATE CSE 2017 Set 1 · Q37

MCQ2 marksMedium

Time

Consider the context-free grammars over the alphabet {a,b,c}\{a,b,c\} given below. SS and TT are non-terminals. G1:S→aSb∣T, T→cT∣ϵG_1: S \to aSb | T, \ T \to cT | \epsilon G2:S→bSa∣T, T→cT∣ϵG_2: S \to bSa | T, \ T \to cT | \epsilon The language L(G1)∩L(G2)L(G_1) \cap L(G_2) is

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) Not finite but regular.

Context-Free Grammars and PDAs

From the grammar G1G_1:

  • S→aSb∣TS \to aSb \mid T generates equal numbers of aa's at the beginning and bb's at the end surrounding TT.

  • T→cT∣ϵT \to cT \mid \epsilon generates any number of cc's (c∗c^*).

  • Thus, L(G1)={anckbn∣n≥0,k≥0}L(G_1) = \{ a^n c^k b^n \mid n \ge 0, k \ge 0 \}.

From the grammar G2G_2:

  • S→bSa∣TS \to bSa \mid T generates equal numbers of bb's at the beginning and aa's at the end surrounding TT.

  • T→cT∣ϵT \to cT \mid \epsilon generates c∗c^*.

  • Thus, L(G2)={bnckan∣n≥0,k≥0}L(G_2) = \{ b^n c^k a^n \mid n \ge 0, k \ge 0 \}.

To find the intersection L(G1)∩L(G2)L(G_1) \cap L(G_2):

  • For n>0n > 0, any non-empty string generated with n>0n > 0 in L(G1)L(G_1) starts with aa and ends with bb, whereas in L(G2)L(G_2) it starts with bb and ends with aa. They share no common strings for n>0n > 0.

  • For n=0n = 0, both grammars generate TT, which produces strings in {ck∣k≥0}=c∗\{ c^k \mid k \ge 0 \} = c^*.

Hence, L(G1)∩L(G2)=c∗L(G_1) \cap L(G_2) = c^*.

The language c∗c^* is infinite (not finite) and regular, which corresponds to option (B).

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 Q37 of the GATE CSE 2017 Set 1 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 2017 Set 1 has 3.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2017 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2017 Set 1 · Q37 · MCQ

Consider the context-free grammars over the alphabet {a,b,c} given below. S and T are non-terminals. G1: S → aSb | T, T → cT | G2: S → bSa | T, T → cT | The language L(G1) ∩ L(G2) is

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.