Home › GATE CSE › computerscience › Theory of Computation › Context-free languages are CLOSED under which of…
Context-free languages are CLOSED under which of the following operations?
AUnion, concatenation, Kleene star
BIntersection and complement only
CSet difference
DNone of the above
Answer & Solution
Correct answer: A. Union, concatenation, Kleene star
1. CFL closure properties:
- UNION: yes. Given $G_1, G_2$, build $G = G_1 \cup G_2$ with new start $S \to S_1 \mid S_2$.
- CONCATENATION: yes. New rule $S \to S_1 S_2$.
- KLEENE STAR: yes. New rule $S \to S_1 S \mid \varepsilon$.
2. NOT closed:
- INTERSECTION: $L_1 = \{a^n b^n c^k\}$ and $L_2 = \{a^k b^n c^n\}$ are both CFL, but $L_1 \cap L_2 = \{a^n b^n c^n\}$ is NOT CFL.
- COMPLEMENT: a consequence of the above (since $A \cap B = \overline{\overline{A} \cup \overline{B}}$).
3. EXCEPTION: CFL intersected with a REGULAR language IS a CFL. This is useful for combining grammars with regex filters.
4. Options B, C, D misstate.
_Source: Jeff Erickson, "Models of Computation", §5.12 (Closure of CFLs)._
Related questions
Which class of grammars generates ALL recursively enumerable languages?What is a LEFTMOST DERIVATION?Which of the following languages is CONTEXT-FREE?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$. WIs the language $L = \{a^n b^n c^n \mid n \geq 0\}$ context-free?