Let and let .
Which of the following constraints ensure(s) that the language is context-free?
- (A)
- (B)
and
- (C)
and
- (D)
Let and let .
Which of the following constraints ensure(s) that the language is context-free?
and
and
ANSWER
Options (A), (C) and (D) make context-free. Only (B), , is not context-free.
Official answer: A, C, DSource: Official answer key, GATE 2026 CS2 (IIT Guwahati)
Each option adds one constraint to . Check each restricted language for context-freeness separately.
(A) . Split on whether . If with , then gives , so the word is . If with , then gives , so the word is .
Both cases have context-free grammars. First case: , , , which gives exactly . Second case: with the same and and . With the grammar generates the whole language (check: , , are generated; has and is not). So (A) is context-free.
(B) and , i.e. : the 's are matched with the 's and the 's with the 's, so the two dependencies cross. Pumping lemma: take , where is the pumping length. Any split with and puts inside at most two neighbouring blocks. If or holds two different letters, pumping up breaks the order . Otherwise pumping changes the count of or (but not or ), or of or , or of or . In every case some pair or loses its balance, so . (B) is not context-free.
(C) and , i.e. : the dependencies are nested. , generates exactly this language, so (C) is context-free.
(D) . Split on whether . If with , then gives , so the word is . If with , then gives , so the word is .
Both cases are nested, so one grammar covers them: gives , then gives , the first case. gives , then gives , the second case. Check on short strings: (), , and are generated; has and is not. A PDA sees it too: push one symbol for every and , pop one for every and , let the finite control enforce the order , and accept on an empty stack. So (D) is context-free.
Correct options: (A), (C) and (D).
KEY IDEA
A one-stack machine can check a constraint when the matched counts are nested: the symbols counted first are matched in reverse order by the symbols counted last. In (D), every and is pushed and every and pops, so the constraint is a single stack balance. In (A) and (C) the constraint splits into a union of nested patterns. (B) needs two crossing matches ( with and with ), and a single stack cannot do both.
WATCH OUT FOR
Calling (D) non-context-free because it involves all four letters. is one count balanced against another, the shape of with and , and a PDA checks it with one stack. An Ogden or pumping argument against (D) breaks down because the pumped window can be a block of 's together with a block of 's, with all the 's and 's between them, and pumping both blocks keeps the sums equal. Another slip is putting the inner nonterminal in the wrong place in a grammar for (A), for example with , which produces instead of .
From the GATE 2026 CS2 paper. Every question of this paper · Download the full paper · All 8 Context-free languages questions, with notes