Recall warm-up
- Which derivation does the grammar-built PDA simulate?
Stuck? Peek at 3.3.4 CFG ↔ PDA equivalence
- CFG → PDA: push S; expand (q, ε, A) → (q, α); match (q, a, a) → (q, ε); accept on Z₀. Simulates leftmost derivations; nondeterministic.
- PDA → CFG: variables [p X q] (net pop of X from p to q).
- CFG = NPDA (final state) = NPDA (empty stack). One working state suffices.
- Are regular languages closed under intersection?
Stuck? Peek at 2.4.1 Closure properties of regular languages
- Closed: ∪ ∩ − complement, concat, *, ⁺, reversal, homomorphism, inverse homomorphism, quotient (by any language), prefix, suffix, substring, substitution, finite ∪/∩.
- Not guaranteed: infinite ∪/∩, subset, superset.
- Prove non-regular: L ∩ R non-regular (R regular) ⇒ L non-regular.
- Product DFA accepting set for intersection?
Stuck? Peek at 1.1.4 Product construction and complement
- Product: states Q₁×Q₂, δ((p,q),a) = (δ₁(p,a), δ₂(q,a)), start (s₁,s₂).
- ∩: F₁×F₂. ∪: F₁×Q₂ ∪ Q₁×F₂. −: F₁×(Q₂−F₂). ≤ |Q₁|·|Q₂| states.
- Complement: complete the DFA (add dead state), swap F ↔ Q−F; same state count.
- Regular languages closed under ∪, ∩, −, complement.
The Hook
Regular languages were closed under everything. Context-free languages are not — and the failures are exactly what GATE tests. The key reason: two stacks can’t be merged into one. Learn the table with its reasons and every closure question becomes a lookup.
Predict First
L₁ = { aⁿbⁿcᵐ } and L₂ = { aᵐbⁿcⁿ } are both CFLs. What is L₁ ∩ L₂?
Core Concept
Prediction check
L₁ ∩ L₂ = { aⁿbⁿcⁿ } — which is not a CFL (3.4.3). So CFLs are not closed under intersection.
CFLs are closed under…
Union (S → S₁ | S₂), concatenation (S → S₁S₂), Kleene star (S → S₁S | ε), reversal (reverse every body), homomorphism and substitution (replace terminals), inverse homomorphism (PDA construction), and intersection with a regular language (run a PDA and a DFA in parallel: product states, one stack).
CFLs are NOT closed under…
- Intersection: aⁿbⁿcᵐ ∩ aᵐbⁿcⁿ = aⁿbⁿcⁿ.
- Complement: if CFLs were closed under complement, then L₁ ∩ L₂ = (L̅₁ ∪ L̅₂)̅ would be a CFL — contradiction.
- Difference L₁ − L₂: Σ* − L would give complement.
But L − R (R regular) = L ∩ R̅ is a CFL.
DCFLs
Closed under: complement (swap accepting states after making the DPDA always read its whole input), intersection with regular, union with regular, difference with regular, inverse homomorphism.
Not closed under: union, intersection, concatenation, Kleene star, reversal, homomorphism.
Example: {aⁿbⁿcᵐ} and {aᵐbⁿcⁿ} are DCFLs; their intersection is not even a CFL. Their union {aⁱbʲcᵏ : i = j or j = k} is a CFL but not a DCFL.
| operation | Regular | DCFL | CFL |
|---|---|---|---|
| union | ✓ | ✗ | ✓ |
| intersection | ✓ | ✗ | ✗ |
| complement | ✓ | ✓ | ✗ |
| concatenation | ✓ | ✗ | ✓ |
| Kleene star | ✓ | ✗ | ✓ |
| reversal | ✓ | ✗ | ✓ |
| homomorphism | ✓ | ✗ | ✓ |
| inverse homomorphism | ✓ | ✓ | ✓ |
| ∩ regular | ✓ | ✓ | ✓ |
| difference with regular (L − R) | ✓ | ✓ | ✓ |
Using closure to prove non-CFL
If L ∩ R (R regular) is not a CFL, L is not a CFL. Example: L = { w ∈ {a,b,c}* : #a = #b = #c }. L ∩ a*b*c* = aⁿbⁿcⁿ, not a CFL ⇒ L is not a CFL.
Putting it together
- CFLs keep union, concatenation, star, reversal, homomorphisms and ∩ regular — not ∩ or complement.
- DCFLs keep complement and ∩ regular — not union, ∩, concatenation, star, reversal.
- Prove non-CFL by intersecting with a regular shape.
Visual
memory hook for the table:
CFL : "U C S R H" — Union, Concatenation, Star, Reversal, Homomorphism (+ ∩R, h⁻¹)
NOT ∩, NOT complement
DCFL: complement ✓, ∩R ✓, h⁻¹ ✓ — everything else ✗ (union, ∩, concat, star, reversal, h)Worked Examples
L is a CFL, R is regular. Is L − R a CFL?
Show the full solution
Yes: L − R = L ∩ R̅, and R̅ is regular.
L₁, L₂ DCFLs. Is L₁ ∪ L₂ necessarily a DCFL? A CFL?
Show the full solution
Not necessarily a DCFL (aⁿbⁿcᵐ ∪ aᵐbⁿcⁿ is not). Always a CFL (both are CFLs).
L₁ CFL, L₂ DCFL, R regular. Which are always CFLs? (i) L₁ ∩ R (ii) L̅₂ (iii) L₁ ∩ L₂ (iv) L̅₁
Show the full solution
(i) ✓. (ii) ✓ — complement of a DCFL is a DCFL, hence a CFL. (iii) ✗ — intersection of two CFLs can fail. (iv) ✗. Answer: (i) and (ii).
GATE Traps
- CFL ∩ CFL is not guaranteed; CFL ∩ regular is.
- Complement: DCFL yes, CFL no.
- DCFL union is not closed; CFL union is.
- The intersection of two CFLs might still happen to be a CFL — “not closed” means “not guaranteed”.
Memory Hook
One stack can’t do two jobs at once: that is why CFLs lose intersection. A deterministic stack can be flipped (complement); a guessing one can’t.
Connect the Dots
Next: which questions about CFLs have algorithms — and the efficient membership test (CYK) that every parser descends from.
Self-Test
- MSQ
CFLs are closed under:
- union
- intersection
- Kleene star
- intersection with a regular language
- MSQ
DCFLs are closed under:
- complement
- union
- intersection with a regular language
- concatenation
- MCQ
Why are CFLs not closed under complement?
- PDAs cannot be complemented
- Closure under ∪ and complement would give closure under ∩, which fails
- CFLs are infinite
- Grammars have no complement
- MCQ
{ w ∈ {a,b,c}* : #a = #b = #c } is:
- regular
- DCFL
- CFL but not DCFL
- not a CFL
Rule Card
- CFL closed: ∪, concat, *, reversal, h, h⁻¹, substitution, ∩R, −R. Not: ∩, complement, difference.
- DCFL closed: complement, ∩R, ∪R, −R, h⁻¹. Not: ∪, ∩, concat, *, reversal, h.
- Counterexample: aⁿbⁿcᵐ ∩ aᵐbⁿcⁿ = aⁿbⁿcⁿ. Non-CFL proof: L ∩ R non-CFL ⇒ L non-CFL.
Concept Ledger
- closure of CFLs
- closure of DCFLs
- CFL ∩ regular construction
- non-closure under ∩ and complement
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- Leftmost.
- Yes (product construction).
- F₁ × F₂.
Self-test answers
- ACD — See the table.
- B: aⁿbⁿcⁿ counterexample.
- AC — See the table.
- B: Not closed.
- D: Not closed.
- B — De Morgan argument.
- A: Not a proof.
- C: Irrelevant.
- D: Not a proof.
- D — Intersect with a*b*c*.
- A: No.
- B: No.
- C: Not even a CFL.
Flashcards
- Are CFLs closed under intersection? Counterexample?
Reveal answer
No: aⁿbⁿcᵐ ∩ aᵐbⁿcⁿ = aⁿbⁿcⁿ. - Are DCFLs closed under complement?
Reveal answer
Yes. - Are DCFLs closed under union?
Reveal answer
No. - Is CFL ∩ regular a CFL?
Reveal answer
Yes.