GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 45

Comparing two three-block context-free languages

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q45 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 45, GATE 2025: For m,n≥1, L1={a^m b^m c^(m+n)} and L2={a^m b^n c^(m+n)}. Which is true? A both context-free; B only L1 context-free; C only L2 context-free; D neither context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Approach: Give a constructive grammar for L2 and a pumping-lemma contradiction for L1.
L2 is generated by S→aSc | aTc and T→bTc | bc. Each use of S adds one a and one trailing c, with at least one a forced before moving to T. Each T production similarly pairs a b with a c and forces at least one b. The derived words are exactly am bn cm+n, so L2 is context-free.
Suppose L1 were context-free with pumping length p. Choose w=ap bp cp+1, which is in L1 with m=p,n=1. In a pumping decomposition w=uvxyz, |vxy|≤p and |vy|>0. The window cannot touch both the a and c blocks, because it would have to span all p b’s between them.
Let Δa,Δb,Δc count those symbols in the pumped parts v and y. If pumping disrupts block order, it already leaves L1. Otherwise, if Δa≠Δb, pumping down or up breaks equality of a and b counts. If Δa=Δb>0, then Δc=0; pumping up makes the common count at least p+1 while c remains p+1, violating the strict requirement c>m. Finally if Δa=Δb=0, then Δc>0; pumping down leaves at most p c’s while a=b=p, again violating c>m.
All possibilities fail. Thus L1 is not context-free, giving C. The unrestricted extra c’s in L1 do not eliminate the need to enforce both equality and a strict count comparison.

Original paper, page 45 · Answer key