GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 40

Context-free linear counting constraints

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

GATE 2010, Q40 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 40, GATE 2010: For nonnegative integers i,j, let L₁={0^i1^j:i≠j}, L₂={0^i1^j:i=j}, L₃={0^i1^j:i=2j+1}, L₄={0^i1^j:i≠2j}. Which statement is true?
Options: (A) Only L₂ is context-free; (B) Only L₂ and L₃ are context-free; (C) Only L₁ and L₂ are context-free; (D) All are context-free.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

All four languages are context free, D. L₂ has grammar S→0S1|ε. L₃ has S→00S1|0. For L₁, split into i>j and i<j: matched pairs 0j1j can have a nonempty zero prefix or nonempty one suffix, respectively, and CFLs are closed under concatenation with regular languages and finite union. For L₄, let E={02j1j}, generated by S→00S1|ε. The part i>2j is 0⁺E. For i<2j, even i gives E1⁺, while odd i gives 0E1⁺. These are all CFLs by the same closure properties, proving the claim without incorrectly invoking closure of CFLs under complement.

For the strict-inequality cases, the closure argument is constructive. L₁=0⁺{0j1j} ∪ {0i1i}1⁺. For L₄, write E={02j1j}; the cases i>2j, i<2j with i even, and i<2j with i odd are respectively 0⁺E, E1⁺ and 0E1⁺. This separates the arithmetic conditions without relying on the generally false statement that context-free languages are closed under complement.

Original paper, page 10