CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 2 · Regular Expressions & Regular Languages

Lesson 2.4.1 · Item 40 of 91

Closure properties of regular languages

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. Which grammar shapes generate exactly the regular languages?
    Stuck? Peek at 2.3.2 Right-linear and left-linear grammars
    • Right-linear: A → wB | w. Left-linear: A → Bw | w. Regular grammar = one of the two (not mixed).
    • DFA → grammar: δ(A,a)=B ⇒ A → aB; A accepting ⇒ A → ε.
    • Grammar → NFA: A → aB is an arrow; A → a goes to a new accepting state.
    • Mixed linear can give aⁿbⁿ. Non-regular grammar does not imply non-regular language.

    Read lesson 2.3.2

  2. Product construction: accepting set for L₁ − L₂?
    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.

    Read lesson 1.1.4

  3. Thompson: how is r* built?
    Stuck? Peek at 2.2.1 Regex → ε-NFA (Thompson construction)
    • Invariant: one start (no in-moves), one accept (no out-moves).
    • ∅, ε, a: 2 states. r+s: +2 states, 4 ε. rs: ε from accept(r) to start(s). r*: +2 states, 4 ε (enter, skip, loop back, exit).
    • States ≤ 2 × (symbols + operators). Regex → ε-NFA → DFA proves regex ⇒ regular.

    Read lesson 2.2.1

The Hook

You know L₁ is regular and L₂ is regular. Is “strings in L₁ that are not in L₂, reversed” regular? Instead of designing a DFA each time, mathematicians proved once and for all which operations keep a language regular. In GATE, closure questions are free marks — if you know the table and the classic traps.

Predict First

Each of L₁ = {aⁿbⁿ} and its complement are not regular. Can the union of two non-regular languages be regular?

Core Concept

Prediction check

Yes. {aⁿbⁿ} ∪ complement({aⁿbⁿ}) = Σ*, which is regular. Closure only promises: regular in ⇒ regular out. It says nothing when inputs are non-regular.

L = {aⁿbⁿ}
not regular
L̅
not regular
L ∪ L̅ = Σ*
regular!
Closure promises nothing when the inputs are not regular.

Closed: the full list

OperationWhy it stays regular
Union, intersection, differenceproduct construction (1.1.4)
Complementswap F in a complete DFA
Concatenation, Kleene star, plusregex operations / Thompson
Reversal Lᴿreverse every arrow, new start with ε to old accepting states, old start becomes accepting
Homomorphism h(L)substitute h(a) for a in the regex
Inverse homomorphism h⁻¹(L)DFA reads a, simulates the original DFA on the string h(a)
Quotient L/M (L regular, M any language)same DFA, new accepting set: states from which some string of M reaches F
Prefix(L), Suffix(L), Substring(L)prefix: make accepting every state that can reach F
Substitution by regular languages, finite union/intersectionregex substitution / repeated product
steps illustration
Closure under reversal, as a construction.

Homomorphism

A homomorphism h : Σ → Δ* replaces each symbol by a string; h(w) = h(w₁)h(w₂)…; h(L) = { h(w) | w ∈ L }. Inverse homomorphism: h⁻¹(L) = { w ∈ Σ* | h(w) ∈ L }.

Example: h(a) = 01, h(b) = ε. h(a*b) = (01)*. For L = (01)*, h⁻¹(L) = {w : h(w) ∈ (01)*} = all strings over {a, b} (every h(w) is (01)ᵏ).

wh(w)
a01
bε
ab01
aab0101
Homomorphism h(a) = 01, h(b) = ε: substitute each symbol.

Quotient and prefix

Right quotient L₁/L₂ = { x | xy ∈ L₁ for some y ∈ L₂ }. Prefix(L) = L/Σ*.

Example: L₁ = a*b, L₂ = b ⇒ L₁/L₂ = a*. If L₁ is regular, L₁/L₂ is regular for any L₂, even a non-regular one.

aaabx ∈ L₁/L₂ = a*y ∈ L₂ = {b}
Quotient: keep the x’s that can be completed by some y from L₂. a*b / b = a*.

NOT guaranteed (classic traps)

  • Infinite union: each {aⁿbⁿ} for a single n is finite (regular), but their union over all n is not regular.
  • Subset: {aⁿbⁿ} ⊆ Σ*, yet Σ* is regular and the subset is not. A subset of a regular language need not be regular.
  • Superset: similarly no guarantee.
  • Infinite intersection: no guarantee.
Σ* regular
{aⁿbⁿ} not regular — yet a subset of Σ*
Taking a subset can leave the regular family.

Using closure to prove NON-regularity

If L were regular, then L ∩ R (R regular) would be regular. So if L ∩ R is known non-regular, L is non-regular. Example: L = { w : |w|ₐ = |w|_b }. L ∩ a*b* = { aⁿbⁿ } — not regular — so L is not regular.

flowplay illustration
Proving non-regularity with closure.

Putting it together

  • Regular languages are closed under every finite operation in the syllabus, including reversal, (inverse) homomorphism and quotient.
  • No guarantee for infinite unions or subsets.
  • Intersect with a regular “shape” to expose a non-regular core.

Visual

reversal of a DFA for "starts with ab"
 original:  →q0 —a→ q1 —b→ (q2) ⟲a,b
 reversed:  new start s —ε→ q2 ⟲a,b —b→ q1 —a→ (q0)       language: ends with ba ✓

closure cheat-grid for regular languages
 ∪ ∩ − ¬ · * ⁺ ᴿ  h  h⁻¹  /  prefix  suffix  substitution     ✔ all closed
 infinite ∪, infinite ∩, ⊆ (subset), ⊇ (superset)            ✘ no guarantee

Worked Examples

Easy

L = (a + b)*abb. Describe Lᴿ.

Show the full solution

Lᴿ = bba(a + b)*: strings starting with bba. Reverse the regex (and the order inside concatenations).

Medium

h(0) = aa, h(1) = b. L = { w ∈ {a,b}* : w has an even number of a’s }. What is h⁻¹(L)?

Show the full solution

For any w ∈ {0,1}*, h(w) has 2·|w|₀ a’s — always even. So h⁻¹(L) = {0,1}*.

GATE-level

L₁ regular, L₂ not regular. Which must be regular? (i) L₁ ∪ L₂ (ii) L₁ / L₂ (iii) L₁ ∩ L₂ (iv) Prefix(L₁)

Show the full solution

(ii) quotient by any language is regular ✓; (iv) ✓. (i) and (iii) are not guaranteed: L₁ = ∅ gives L₂ (non-regular); L₁ = Σ* gives L₁ ∪ L₂ = Σ* (regular). Answer: (ii) and (iv).

GATE Traps

  • Closure is one-way: it says nothing when an input is non-regular.
  • A subset of a regular language need not be regular ({aⁿbⁿ} ⊆ Σ*).
  • Finite unions keep regularity; infinite unions don’t.
  • L₁/L₂ is regular whenever L₁ is regular — L₂ can be anything.

Memory Hook

The regular club has a strict door policy for members (any combination of members stays in the club) but no policy at all for outsiders.

Connect the Dots

Closure tells us when new languages stay regular. Next: what we can compute about a regular language given its DFA — is it empty? finite? equal to another one? Every one of these questions has an algorithm.

Self-Test

  1. MSQ

    Regular languages are closed under:

    1. reversal
    2. inverse homomorphism
    3. infinite union
    4. quotient with an arbitrary language
  2. MCQ

    L ∩ a*b* = {aⁿbⁿ}. What follows?

    1. L is regular
    2. L is not regular
    3. a*b* is not regular
    4. nothing
  3. MCQ

    h(a) = 0, h(b) = 0. h({ aⁿbⁿ : n ≥ 0 }) is:

    1. {0ⁿ1ⁿ}
    2. (00)*
    3. 0*
    4. not regular
  4. NAT

    L = a*b. How many strings of length 3 are in Prefix(L)?

    Write your answer before opening the key.

  5. MCQ

    Which is NOT guaranteed to be regular when L is regular?

    1. Lᴿ
    2. L*
    3. a subset of L
    4. Σ* − L

Rule Card

  • 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.

Concept Ledger

  • homomorphism h(L)
  • inverse homomorphism h⁻¹(L)
  • right quotient L₁/L₂
  • Prefix(L), Suffix(L)
  • substitution
  • closure-based non-regularity argument

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. Right-linear or left-linear (not mixed).
  2. F₁ × (Q₂ − F₂).
  3. New start and accept, ε into r, skip ε, loop ε from r’s accept to r’s start, exit ε.

Self-test answers

  1. ABD — Standard closure list.
    • C: Union of the finite sets {aⁿbⁿ} is not regular.
  2. B — If L were regular, the intersection with a regular language would be regular.
    • A: Contradiction.
    • C: a*b* is regular.
    • D: Closure gives a conclusion.
  3. B — Each string maps to 0²ⁿ.
    • A: b maps to 0, not 1.
    • C: Odd lengths missing.
    • D: Homomorphic images of non-regular languages can be regular.
  4. 2 — Prefixes of a*b of length 3: aaa (prefix of aaab) and aab.
  5. C — Subsets can be anything.
    • A: Closed.
    • B: Closed.
    • D: Closed.

Flashcards

  1. Is a subset of a regular language regular?
    Reveal answerNot necessarily ({aⁿbⁿ} ⊆ Σ*).
  2. Regular L₁, arbitrary L₂: is L₁/L₂ regular?
    Reveal answerYes, always.
  3. Closed under infinite union?
    Reveal answerNo.
  4. How do you reverse a DFA?
    Reveal answerReverse arrows, new start with ε to old accepting states, old start becomes accepting.

Exam shortcuts

  • To show L non-regular fast: intersect with a regular “shape” like a*b* to expose aⁿbⁿ.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.