Home › GATE CSE › computerscience › Theory of Computation › Which of the following languages is CONTEXT-FREE?
Which of the following languages is CONTEXT-FREE?
A$\{a^n b^n c^n \mid n \geq 0\}$
B$\{ww \mid w \in \{a,b\}^*\}$
C$\{a^i b^j c^k \mid i = j \text{ OR } j = k\}$
D$\{w \mid w \text{ has equal a's and b's and c's}\}$
Answer & Solution
Correct answer: C. $\{a^i b^j c^k \mid i = j \text{ OR } j = k\}$
1. Option C: $\{a^i b^j c^k \mid i = j \text{ OR } j = k\}$ is the UNION of two simpler languages:
- $L_1 = \{a^n b^n c^k\}$ — CFL (PDA matches a's and b's, ignores c's)
- $L_2 = \{a^k b^n c^n\}$ — CFL (PDA matches b's and c's, ignores a's)
2. CFLs are CLOSED under union: a PDA recognises $L_1 \cup L_2$ by nondeterministically picking which sub-language to verify.
3. So option C is CFL ✓.
4. Options A, B, D require matching THREE quantities simultaneously — beyond a single stack's capacity. All three are NOT context-free.
5. Notably: option C ($\text{i=j OR j=k}$, NON-intersection) IS context-free but $L_1 \cap L_2$ would NOT BE (matches both, requires all three equal).
_Source: Jeff Erickson, "Models of Computation", §5.12 (CFL closure properties)._
Related questions
Which class of grammars generates ALL recursively enumerable languages?What is a LEFTMOST DERIVATION?Consider the grammar $S \to (S) \mid SS \mid \varepsilon$. The language generated isEvery regular language is also context-free. The PROOF construction isThe CYK algorithm parses a CFG in CNF. Its time complexity for a string of length $n$ isA LEFT-RECURSIVE rule in a CFG has the form $A \to A\alpha$ for some non-empty $\alpha$. WContext-free languages are CLOSED under which of the following operations?Is the language $L = \{a^n b^n c^n \mid n \geq 0\}$ context-free?