GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 31

Nested versus crossing language constraints

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2019 paper

GATE 2019, Q31 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 31, GATE 2019: Over {a,b}, choose the language that is not context-free: A {ww^R}; B {wa^n b^n w^R}; C {wa^n w^R b^n}; D {a^n b^i : i is n, 3n, or 5n}. Here w ranges over all finite binary-alphabet strings, n≥0, and w^R is reversal.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. To distinguish these languages, separate nested matching, which a stack supports, from overlapping matching constraints. A is generated by S→aSa|bSb|ε, so it is context-free.
2. B is also nested: use S→aSa|bSb|T and T→aTb|ε. The S rules build w and its reversal around the central equal-length a/b runs. D is a union of three context-free languages; for each r in {1,3,5}, Sr→aS_r br|ε generates its fixed-ratio component. CFLs are closed under finite union.
3. For C, intersect with the regular language a+ b a+ b a+ b+. CFLs are closed under intersection with regular languages. In this pattern the two isolated b symbols force w=ai b at, and n=k, giving precisely K={ai b aj b ai bk : i,k≥1, j≥k, j−k even}, with j=2t+k.
4. Suppose K were context-free with pumping length p. Choose s=ap b ap b ap bp. In any CFL pumping decomposition s=uvxyz, |vxy|≤p and |vy|>0. The window cannot touch both the first and third a-runs, nor both the middle a-run and final b-run.
5. If v or y contains a separator b, pumping down removes a required separator and destroys the regular pattern. Otherwise, pumping any first/third-run a changes one side of their required equality without changing the other. This also leaves K.
6. The remaining possibility pumps only middle-run a's or only final-run b's. Pumping down middle a's makes j<k; pumping up final b's makes k>j. Thus every decomposition fails for some pump count, contradicting the pumping lemma. K, and hence C, is not context-free. Answer C.

Original paper, page 10 · Answer key