GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Balance a third block against earlier counts

3 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

For a^n b^m c^(n+m), push for either first block and pop on c. Extra equalities among the first blocks change the class and must be checked rather than assumed harmless.

2 marks · MCQ
Report issue

Comparing two three-block context-free languages

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

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 43, GATE 2016: L1={a^n b^m c^(n+m):m,n≥1}; L2={a^n b^n c^(2n):n≥1}. A both context-free; B only L1; C only L2; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

L1 is generated by S→aSc|aBc and B→bBc|bc: each a or b adds one trailing c, with positive counts of both. Thus L1 is context-free. If L2 were context-free, its inverse image under h(a)=a, h(b)=b, h(c)=cc would be {an bn cn: n≥1}, which is not context-free by the pumping lemma. CFL closure under inverse homomorphism therefore proves L2 non-context-free. Answer B.

A pushdown intuition for L1 pushes one marker per a or b and pops one per c, with finite control enforcing the a-then-b-then-c phases. L2 must enforce three linked quantities. Under h(c)=cc, an input an bn cn maps exactly to an bn c2n, transferring the known non-CFL obstruction through inverse homomorphism.

Original paper, page 37 · Answer key

2 marks · MCQ
Report issue

Classify a language with additive block counts

Context-Free Grammars & Languages

Question 87, GATE 2004: Classify L={a^m b^n c^(m+n):m,n≥1}.
Options:
(A) Regular
(B) Context-free but not regular
(C) Context-sensitive but not context-free
(D) Type-0 but not context-sensitive
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. For L={am bn cm+n:m,n≥1}, a context-free grammar is S→aSc | aTc and T→bTc | bc. The outer recursion supplies matching a/c pairs and the inner recursion matching b/c pairs, so it generates exactly L.

2. It is not regular: for a putative pumping length p, use ap b cp+1. Any pumpable segment within the first p symbols consists only of a characters; pumping changes the a count without changing the c count, violating the defining equality.

3. Therefore context-free but not regular, B.

4. Teaching check: A pushdown automaton can push one marker for each a and b, then pop one for each c, while tracking the required block order and nonempty a,b blocks. A finite automaton cannot maintain the unbounded count equality; the pumping argument makes this limitation rigorous.

Original paper, page 12