Skip to content

Language and Closure Properties

Basic of Formal Language

Examples:

Ques: Total no. of substrings possible for w = GATE

length: 0 1 2 3 4
substrings: ϵ G,A,T,E GA,AT,TE GAT,ATE GATE
no. of subs: 1 + 4 + 3 + 2 + 1 = 4(4+1)/2 + 1

ϵ = null

Total no. of Substrings Formula : n(n+1)/2+1 , n=size of string Total no. of Non-trivial (not include ϵ) substring : n(n+1)/2

Ques : Find the no. of prefix and suffix possible in GATE, where |w|=n prefix:- { ϵ, G, GA, GAT, GATE} No. of Prefixes -> n+1 suffix:- { ϵ, E, TE, ATE, GATE} No. of Suffixes -> n+1

  • Closure under an operation means: If you apply that operation to languages of a particular class, the result will still belong to the same class. OR

  • A language class is closed under an operation if applying that operation to languages in the class always yields a language that is also in the class.

Which Language Not Closed Under Which Operation ⭐⭐⭐

1. Recursive Language -> Closed under all operations ✅
2. Context Free Language -> Intersection ❌, Complement ❌
3. Context Sensitive Language -> Homomorphism ❌
4. Recursive Language -> Closed under all operations ✅
5. Recursive Enumerable Language -> Complement ❌, Difference ❌

1. Regular languages (RL) -> closed under all operations: ⭐

OperationMeaningClosed?Notes ⭐
UnionL₁ ∪ L₂ = strings in L₁ or L₂✅ YesConstructed using NFA or regex: R₁ + R₂
ConcatenationL₁L₂ = strings formed by concatenating strings from L₁ and L₂✅ YesDFA/NFA can simulate
Kleene StarL* = zero or more repetitions of strings in L✅ YesDefined using NFA with ε-transitions
IntersectionL₁ ∩ L₂✅ YesDFA can be built using product construction
ComplementΣ* − L✅ YesFlip final/non-final states in DFA
DifferenceL₁ − L₂✅ YesUse: L₁ − L₂ = L₁ ∩ (¬L₂)
ReversalLᴿ = reverse of all strings in L✅ YesNFA with reversed transitions
SubstitutionReplace symbols by regular languages✅ YesPreserves regularity
Homomorphismh(L) : map each symbol to a string✅ YesStill regular
Inverse Homomorphismh⁻¹(L): pull back by symbol mappings✅ YesStill regular
Right QuotientL₁ / L₂ = { x | ∃ y ∈ L₂ such that xy ∈ L₁ }✅ Yes

Removes suffix from strings in L₁.

Checks if adding some string from L₂ to x results in a string in L₁.

Left QuotientL₂ \ L₁ = { y | ∃ x ∈ L₂ such that xy ∈ L₁ }✅ Yes

Removes prefix from strings in L₁.

Checks if adding some string from L₂ before y results in a string in L₁.

2. Context-Free Languages (CFL): -> Closed Under following Operations ⭐

OperationCFL (Non-Det.) Closed? ⭐ For ExamDCFL Closed?Reason / Explanation
Union✅ Yes❌ NoCFLs can be unioned by using nondeterminism in PDA. DCFLs can’t use nondeterminism, so union may lead to ambiguity.
==Intersection==❌ ==No==❌ NoCFL ∩ CFL may not be CFL (e.g., {aⁿbⁿcⁿ} ∉ CFL). DCFL also not closed because deterministic machines can’t track multiple conditions simultaneously.
==Complement==❌ ==No==✅ ==Yes==CFL not closed: If it were, then CFL would also be closed under intersection (contradiction via De Morgan’s Law). DCFL is closed due to deterministic nature.

Regular ∩ CFL
(Intersection with regular language)

✅ Yes✅ ==Yes====Intersection with a regular language is always CFL or DCFL==, since regular part can be simulated without increasing complexity.
Concatenation✅ Yes❌ NoCFL is closed using nondeterminism. DCFL is not closed as deterministic PDA can’t deterministically concatenate in general.
Kleene Star✅ Yes❌ NoCFL supports repetition via ε-transitions in NPDA. DCFL does not handle unbounded nondeterminism.
Reversal✅ Yes❌ NoCFLs can be reversed by modifying the PDA. For DCFL, reversal may introduce nondeterminism, hence not closed.
Substitution✅ Yes❌ NoCFL supports substitution (using PDA construction). DCFL does not, due to deterministic restrictions.
Homomorphism✅ Yes❌ NoCFLs are closed, but DCFLs are not—homomorphism may break determinism.
==Inverse Homomorphism==✅ Yes✅ ==Yes==Both closed; input symbol pre-image mapping preserves structure.

For Remember:

  • CFL not Follow → Complement and Intersection
  • DCFL only Follow → Complement , Intersection with Regular language, Inverse Homomorphism

Note:

  • Unlike other language classes, Deterministic Context-Free Languages (DCFL) form a strict subset of Context-Free Languages (CFL). i.e. DCFL ⊂ CFL
  • Therefore, DCFLs do not share all closure properties of CFLs, and must be treated separately.

3. Context-Sensitive Languages (CSL) → Closed under most operations ⭐

OperationClosed?Reason / Explanation
Union✅ YesTwo LBA computations can be simulated sequentially.
Intersection✅ YesLBA can check both conditions using linear space.
Complement✅ YesBy Immerman–Szelepcsényi Theorem (NSPACE(n) closed under complement).
Concatenation✅ YesSplit input nondeterministically; linear space preserved.
Kleene Star✅ YesFinite repetitions; space remains linear.
Reversal✅ YesInput can be scanned backward with linear space.
Substitution✅ YesCSL substituted into CSL preserves linear boundedness.
==Homomorphism==❌ ==No==Can shrink strings and break length constraints.
Inverse Homomorphism✅ YesPre-image mapping does not increase space.

For Remember:

  • CSL not Follow → Homomorphism

Note:

  • CSL = NSPACE(n)
  • Key highlight → Complement is closed (unlike CFL)

4. Recursive (Decidable) Languages → Closed under all standard operations ⭐⭐

OperationClosed?Reason / Explanation
Union✅ YesRun both deciders and OR results.
Intersection✅ YesRun both deciders and AND results.
Complement✅ YesFlip accept/reject since TM always halts.
Difference✅ YesA − B = A ∩ ¬B.
Concatenation✅ YesEnumerate splits; both machines halt.
Kleene Star✅ YesFinite decomposition + halting guarantee.
Reversal✅ YesReverse input then decide.
Homomorphism✅ YesTransform input, then decide.
Inverse Homomorphism✅ YesDecide on all mapped strings.

Note:

  • Recursive languages = Total Turing Machines
  • Best closure behavior after Regular languages

5. Recursive Enumerable (RE / Semi-Decidable) Languages → Closed under many but NOT complement ❗

OperationClosed?Reason / Explanation
Union✅ YesDovetailing simulations of two TMs.
Intersection✅ YesAccept only if both machines accept.
==Complement==❌ ==No==Halting problem: TM may loop forever.
==Difference==❌ ==No==Requires complement.
Concatenation✅ YesEnumerate all splits nondeterministically.
Kleene Star✅ YesEnumerate repetitions.
Reversal✅ YesReverse then enumerate.
Homomorphism✅ YesMap then enumerate.
Inverse Homomorphism✅ YesPre-image enumeration.

For Remember:

  • CSL not Follow → Complement and Difference

Note:

  • RE = TM that may not halt
  • Biggest class before Undecidable

Closure Summary ⭐⭐⭐

RL ⊂ DCFL ⊂ CFL ⊂ CSL ⊂ Recursive ⊂ RE

  1. RL → ( Closed under all )

  2. DCFL → (Closed under only ) → Complement , Intersection with RL , Inverse Homomorphism

  3. CFL → (Not== closed under) ==Complement and Intersection

  4. CSL → (Not closed under) → Homomorphism

  5. Recursive → ( closed under all )

  6. RE → (Not== closed under)→ ==Complement and Difference


Deterministic vs Non-Deterministic ⭐

Language ClassNon-Deterministic FormDeterministic FormRelationship
Regular Languages (RL)NFA (Non-Deterministic FA)DFA (Deterministic FA)

==Deterministic = Non-
Deterministic==

both define same RL set

Context-Free Languages (CFL)NPDA (Non-Deterministic PDA)DPDA (Deterministic PDA)

==Deterministic ⊂ Non-Deterministic== ⭐

(strict subset)

Context-Sensitive LanguagesNon-deterministic LBADeterministic LBA (rarely used)

Unclear
(generally assumed equal)

Recursive Languages
(⭐ Extra )

Non-deterministic TM ~ (Linear Bound Automata)Deterministic TM

==Deterministic = Non-Deterministic==

Both accept same class (decidable languages)

Recursively Enumerable (RE)Non-deterministic TM ~ (Linear Bound Automata)Deterministic TM

==Deterministic = Non-Deterministic==

Equivalent in power (semi-decidable)

Important Notes:

  • Regular Languages:
    Always deterministic → NFA ≡ DFA.
  • Context-Free Languages (CFL):
    • Recognized by NPDA
    • Subset of CFL can be recognized by DPDA → called DCFL (Deterministic CFL)
    • Example:
      • { aⁿbⁿ | n ≥ 0 } → in DCFL
      • { aⁿbⁿcⁿ | n ≥ 0 }not in CFL at all
      • { ww | w ∈ Σ* } → CFL but not DCFL

  • Context-Sensitive Languages:
    Typically handled by Linear Bounded Automaton (LBA). Deterministic vs non-deterministic distinction exists, but is not widely explored.
  • Recursive and Recursively Enumerable (RE) languages:Both can be defined using Turing Machines. Every recursive language is decidable==, and ==RE languages are semi-decidable.

Regular ⊆ DCFL ⊆ CFL ⊂ CSL ⊂ RE
⬑ ⬑
DFA DPDA
↑ ↑
NFA NPDA

Decidable vs Recognizable Language ⭐

  • Recursive -> Turing-decidable languages

  • Recursive Enumerable -> Turing-recognizable language

Feature==Turing Decidable (Recursive)====Turing Recognizable (RE)==
Machine typeTotal Turing Machine -> Stronger GuaranteePartial Turing Machine -> Weaker Guarantee
DecideabilityDecideableSemi-Decideable
TM halts onEvery inputOnly on inputs in L
AcceptanceAccepts strings in LAccepts strings in L
RejectionRejects strings not in LMay loop forever on strings not in L
Halting guaranteeAlways halts (accept/reject)No halting guarantee for non-members
ComplementL and ¬L are both RE¬L may not be recognizable
Closure under complement✅ Yes❌ No
Language powerLess powerfulMore expressive
RelationshipDecidable ⊂ RESuperset of Decidable
Classic exampleRegular, CFL, CSLHalting Problem language

Key Relations

  • Decidable ⊂ Recognizable
  • Some recognizable languages are not decidable (e.g., Halting Problem)

One-line exam difference

Decidable ⇒ TM halts on all inputs
Recognizable ⇒ TM halts only on accepted inputs