Closure Properties of Formal Languages: Worked Examples and Exam Traps
Learn what closure means at the language-class level. Build a product DFA, disprove CFL intersection closure, and use known results without falling into common traps.
KnowledgeGate Team
Exam prep & CS education

Students often memorise a closure table, then lose the answer when a question changes the language class, operation, or alphabet. A safer method is to define closure precisely, prove one positive result by construction, disprove one claim by counterexample, and turn those ideas into a decision process.
Related reading: regular language closure and context-free languages.
Closure property: what "closed" actually means
A language class is closed under a binary operation when
always implies . For a unary operation such as complement or reversal, must imply that the resulting language is also in .
The word always carries the definition. One selected language may produce a regular-looking result, and one selected pair may survive an operation, but neither proves closure of the class. One counterexample disproves closure. A positive closure claim needs a general construction or theorem.
The operations used here are union, intersection, complement relative to a fixed alphabet , difference, concatenation, Kleene star, reversal, homomorphism, and inverse homomorphism. Place these within the wider subject through this Theory of Computation guide.
The exam-safe closure map
For the six core operations below, regular and recursive languages are closed in every column. CFLs are not closed under arbitrary intersection or complement. Recursively enumerable languages are not closed under complement.
Class | Union | Intersection | Complement | Concatenation | Kleene star | Reversal |
|---|---|---|---|---|---|---|
Regular | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Context-free (CFL) | ✓ | ✗ | ✗ | ✓ | ✓ | ✓ |
Recursive/decidable | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Recursively enumerable/recognisable | ✓ | ✓ | ✗ | ✓ | ✓ | ✓ |
Keep the qualifications beside the table. A CFL intersected with a regular language is a CFL. Deterministic CFLs are closed under complement and under intersection with a regular language, but not under arbitrary union or intersection. Context-sensitive languages require care around erasing homomorphisms, so do not copy an unqualified rule into that class.
Regular languages and CFLs are closed under both homomorphism and inverse homomorphism. For stronger classes, check the theorem's exact conditions, especially whether erasing is allowed.
Worked example 1: construct closure with a product DFA
Let . Language contains strings with an even number of 1s. Its DFA has states and , starts and accepts at , keeps its state on 0, and toggles on 1. Language contains strings ending in 0. Its states are and , with start state , accept state , every 0 moving to , and every 1 moving to .
The reachable product states and all transitions are:
Product state | On 0 | On 1 |
|---|---|---|
The start state is . For , only accepts. For , the accepting states are .
Trace 1010:
\[
(E,N)\xrightarrow{1}(O,N)\xrightarrow{0}(O,Z)\xrightarrow{1}(E,N)\xrightarrow{0}(E,Z).
\]
It has two 1s and ends in 0, so the intersection DFA accepts it. By contrast, 10 finishes at . It ends in 0 but has one 1, so the union accepts it and the intersection rejects it.

Worked example 2: disprove CFL closure with one intersection
Define
. The grammar , , generates it, so is context-free.
Define
. The grammar , , establishes that is also context-free.
Membership in forces the number of a's to equal the number of b's. Membership in forces the number of b's to equal the number of c's. Therefore
\[
L_1\cap L_2=\{a^n b^n c^n\mid n\geq0\}.
\]
The string aabbcc is in the intersection for . The string aaabbbcc is only in , while aabbbccc is only in . The language is not context-free. Thus, two CFL inputs have produced a non-CFL intersection, which disproves closure under arbitrary intersection. Review the machine connection in Context-Free Grammars and Pushdown Automata.

Turn known closures into new answers
Suppose CFLs were closed under complement. They are already closed under union, so De Morgan's law would give
\[
L_1\cap L_2=\overline{\overline{L_1}\cup\overline{L_2}}
\]
as another CFL. The counterexample above contradicts that result. Therefore CFLs cannot be closed under complement.
Now let be regular and be context-free. Then is context-free: is regular, and intersecting a CFL with a regular language preserves context-freeness. Swapping the roles does not support the same reasoning. For , the needed CFL complement closure is unavailable.
Two boundary checks prevent easy mistakes. Complement is taken over a stated alphabet. If \(L=\{w\in\{0,1\}^:w\text{ ends in }0\}\), then contains and every binary string ending in 1. Also, \(L^\) always contains , even when does not.
How questions disguise the operation
Consider this four-statement mini-question:
(a) Regular languages are closed under difference.
(b) CFLs are closed under arbitrary intersection.
(c) The intersection of a CFL and a regular language is a CFL.
(d) Recursively enumerable languages are closed under complement.
Statement (a) is true because . Statement (b) is false by the counterexample above. Statement (c) is true, and statement (d) is false. The answer is (a) and (c) only.
Use three passes. First, identify the exact input classes. Second, rewrite difference or symmetric difference using primitive operations. Third, check that every step uses an available closure property. For a "not closed" claim, seek one counterexample pair. For a "closed" claim, seek a general machine, grammar, or theorem. Common forms include direct table recall, product-automaton construction, a counterexample, and a De Morgan deduction.
Traps, recall card, and the next study step
Do not fall for these shortcuts:
"Not closed" does not mean every pair fails.
Closure belongs to a class, not to one language.
CFL intersection failure does not cancel CFL-with-regular closure.
DCFL complement closure must not be copied to all CFLs.
Complement needs a fixed universe .
A homomorphism theorem may require an erasing or non-erasing condition.
Keep this six-line recall card:
Regular is closed under every core operation in the table.
CFL is closed under union, concatenation, star, and reversal, but not arbitrary intersection or complement.
CFL intersected with regular stays context-free.
Recursive languages are closed under complement.
Recursively enumerable languages are not closed under complement.
A product construction proves positive regular closure; supplies the standard negative CFL-intersection witness.
Reconstruct both worked examples without looking. Then use the Theory of Computation / Automata Theory course for a focused subject pass. The ZERO TO HERO complete CS course is the broader multi-subject route, while the CS Fundamentals category is the comparison page.
Keep learning

Linear Bounded Automata: Tape Limits, a Worked LBA Trace and Exam Traps
See exactly what an LBA bounds, where it sits in the language hierarchy, and how a six-cell marking machine accepts aabbcc while rejecting three near misses.

Decision Properties in Theory of Computation: DFA Tests, CFG Boundaries and Turing Machine Undecidability
Learn an algorithm-first way to classify membership, emptiness, finiteness, inclusion, equivalence and universality for DFAs, CFGs and Turing machines.

FA to Regex Conversion: State Elimination with a Fully Worked Example
Learn a mechanical state-elimination method for converting a finite automaton to a regular expression, then verify the result with a second order and short strings.

Epsilon NFA Conversion: Epsilon-Closure, Worked DFA Table and Exam Traps
Learn a mechanical epsilon-NFA conversion method through one four-state machine, complete set traces, a reachable-subset DFA table, and epsilon elimination.