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)._
Keep practising Theory of Computation
Browse all Theory of Computation questions for GATE CSE, or explore more Computer Science topics.
Related questions
Which class of grammars generates ALL recursively enumerable languages?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$ isContext-free languages are RECOGNISED by which type of machine?A CFG is AMBIGUOUS ifConsider the CFG with rule $S \to aSb \mid \varepsilon$. The language generated isWhich of these is an example of an IRREGULAR (non-regular) language?