G27
Self-checkedTier 1 11 min readtoc.regular-closure-properties

Closure properties of regular languages

The operations under which regular languages stay regular (union, intersection, complement, difference, concatenation, star, reversal, homomorphism, inverse homomorphism, quotients, prefixes, suffixes, half) with the construction and the state-count bound of each, the operations that are not closed (infinite union, arbitrary subsets), and how closure is used to prove that a language is not regular.

Why it exists

A class of languages is closed under an operation if applying the operation to members of the class gives a member of the class. For regular languages, closure means we can build a new automaton for the result. Closure is the main tool for two kinds of GATE questions: "is this combined language regular?" and "prove that LL is not regular" (if LL were regular, then some regular combination of LL with a regular language would be a language already known to be non-regular).

Prerequisites

You need DFAs and their minimal sizes (DFA minimisation), the subset construction (subset construction) and the translation between expressions and automata (regex and automata).

Precise definitions

For regular languages L,L1,L2L, L_1, L_2 over Σ\Sigma the following are all regular:

operationdefinition
unionL1∪L2L_1 \cup L_2
intersectionL1∩L2L_1 \cap L_2
complementL‾=Σ∗∖L\overline{L} = \Sigma^* \setminus L
differenceL1∖L2=L1∩L2‾L_1 \setminus L_2 = L_1 \cap \overline{L_2}
symmetric difference(L1∖L2)∪(L2∖L1)(L_1 \setminus L_2) \cup (L_2 \setminus L_1)
concatenationL1L2L_1 L_2
star, plusL∗L^*, L+=LL∗L^+ = L L^*
reversalLR={wR:w∈L}L^R = \{w^R : w \in L\}
homomorphismh(L)h(L) where h:Σ→Γ∗h : \Sigma \to \Gamma^* extended to strings
inverse homomorphismh−1(L)={w:h(w)∈L}h^{-1}(L) = \{w : h(w) \in L\}
right quotientL1/L2={w:∃z∈L2, wz∈L1}L_1 / L_2 = \{w : \exists z \in L_2,\ wz \in L_1\}, for any language L2L_2
left quotientL2\L1={w:∃z∈L2, zw∈L1}L_2 \backslash L_1 = \{w : \exists z \in L_2,\ zw \in L_1\}
prefixes{x:∃y, xy∈L}\{x : \exists y,\ xy \in L\}
suffixes{y:∃x, xy∈L}\{y : \exists x,\ xy \in L\}
half{x:∃y, ∣y∣=∣x∣, xy∈L}\{x : \exists y,\ \lvert y \rvert = \lvert x \rvert,\ xy \in L\}

Not closed. Infinite union and infinite intersection (every finite language is regular, but {anbn:n≥0}=⋃n{anbn}\{a^n b^n : n \ge 0\} = \bigcup_n \{a^n b^n\} is not); and subsets: a subset of a regular language need not be regular ({anbn}⊆a∗b∗\{a^n b^n\} \subseteq a^* b^*).

How it works

The constructions

Let D1,D2D_1, D_2 be complete DFAs with mm and nn states.

  • Complement. Swap accepting and non-accepting states of the complete DFA. mm states. (If the DFA is not complete, add the dead state first, otherwise strings that get stuck would be lost.)
  • Product (union, intersection, difference). States are pairs (p,q)(p, q), moves go in parallel; accept if "pp accepts or qq accepts" (union), "and" (intersection), "pp accepts and qq does not" (difference). At most mnm n states. The bound mnm n is reached by two independent counters (the number of aa's modulo mm and the number of bb's modulo nn; checked for four pairs).
  • Concatenation. NFA: the two machines side by side, ε\varepsilon edges from the accepting states of the first to the start of the second. m+nm + n states. The equivalent DFA can have exponentially more (standard result, quoted).
  • Star. NFA: a new accepting start state, ε\varepsilon edges from the accepting states back to the old start. m+1m + 1 states.
  • Reversal. NFA: reverse every edge, make the old start the only accepting state, add a new start with ε\varepsilon edges to the old accepting states. m+1m + 1 states; the minimal DFA of the reversal can need 2m2^m states.
  • Homomorphism. Replace each edge labelled aa by a path spelling h(a)h(a) (an ε\varepsilon edge if h(a)=εh(a) = \varepsilon).
  • Inverse homomorphism. Same states: δ′(q,a)=δ∗(q,h(a))\delta'(q, a) = \delta^*(q, h(a)). At most mm states, a DFA directly.
  • Quotients and prefixes. Same DFA with a changed accepting set: for L1/L2L_1 / L_2 accept the states from which some string of L2L_2 leads to acceptance (this is a property of the DFA, so L2L_2 can be non-regular); for the prefixes accept all states from which an accepting state is reachable.
  • Half. The DFA keeps a pair: the current state pp and the set SkS_k of states from which some string of the length read so far leads to acceptance; accept if p∈Skp \in S_k. Finite, so regular.

Sizes on a small example

L1L_1 = binary strings that end in 0101 (33 states), L2L_2 = binary strings with an even number of 11s (22 states). For each operation the table gives the number of states of the machine built and of the minimal DFA of the result.

Closure constructions on two small languages: start

Computed by a script, not typed
operationconstructionstates of the machine builtstates of the minimal DFAremark
union
intersection
complement
difference
concatenation
star
reversal
homomorphism 0 → 01, 1 → ε
inverse homomorphism 0 → 01, 1 → 1
right quotient L / 1
prefixes of strings in L

Step 0

L1 is 'ends with 01' (3 states), L2 is 'even number of 1s' (2 states). Each row builds the machine for the operation and minimises its DFA; the language of every construction was checked against the definition on all strings up to length 8.

0 / 11
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc2-traces.py

The union and the intersection are built from 3×2=63 \times 2 = 6 states but both minimise to 44. Complement does not change the size. The reversal of "ends with 0101" is "starts with 1010", whose minimal DFA has 44 states (start, after 11, accepting, dead) even though the original had 33. The image under h(0)=01h(0) = 01, h(1)=εh(1) = \varepsilon is (01)+(01)^+ (verified), the inverse image under h(0)=01h(0) = 01, h(1)=1h(1) = 1 is "ends with 00", and the right quotient L1/1L_1 / 1 is also "ends with 00" (both with 22 states). Every string is a prefix of a string ending in 0101, so the prefix language is Σ∗\Sigma^* with 11 state.

Reversal can blow up

Let LnL_n = "the nn-th symbol from the start is 11". Its minimal DFA has n+2n + 2 states (count to nn, then accept or reject, plus a trap). The reversal is "the nn-th symbol from the end is 11", whose minimal DFA needs 2n2^n states. Computed for n=2,…,6n = 2, \ldots, 6: 4,8,16,32,644, 8, 16, 32, 64. So an nn-state DFA can need about 2n2^n states for its reversal.

Using closure to show non-regularity

If LL is regular, so is L∩RL \cap R for every regular RR. So to prove LL not regular, intersect with a regular language and get a known non-regular language.

  • L={w∈{a,b}∗:#a(w)=#b(w)}L = \{w \in \{a, b\}^* : \#a(w) = \#b(w)\}. Then L∩a∗b∗={anbn}L \cap a^* b^* = \{a^n b^n\} is non-regular, so LL is not regular.
  • L={0n1m:n≠m}L = \{0^n 1^m : n \ne m\}. Its complement, intersected with 0∗1∗0^* 1^*, is {0n1n}\{0^n 1^n\}, so LL is not regular.
  • L={anbmcn:n,m≥0}L = \{a^n b^m c^n : n, m \ge 0\}. Then L∩a∗c∗={ancn}L \cap a^* c^* = \{a^n c^n\} is non-regular, so LL is not regular.

The converse direction: closure also shows languages regular without building a machine (for example a finite union of regular pieces, or L∖FL \setminus F for a finite FF).

What you cannot conclude

  • L1∪L2L_1 \cup L_2 regular does not imply L1L_1 and L2L_2 regular ({anbn}∪{anbn}‾=Σ∗\{a^n b^n\} \cup \overline{\{a^n b^n\}} = \Sigma^*).
  • L1L_1 regular and L2L_2 non-regular: L1∪L2L_1 \cup L_2 and L1∩L2L_1 \cap L_2 may or may not be regular (L1=∅L_1 = \emptyset gives L1∩L2=∅L_1 \cap L_2 = \emptyset, regular; L1=Σ∗L_1 = \Sigma^* gives L1∩L2=L2L_1 \cap L_2 = L_2, non-regular).
  • L1L2L_1 L_2 regular does not imply L1L_1 and L2L_2 regular: L1=Σ∗L_1 = \Sigma^* and L2L_2 any language containing ε\varepsilon gives L1L2=Σ∗L_1 L_2 = \Sigma^*, however irregular L2L_2 is.

Worked examples

EX 1Complement size

Easy

A complete DFA with 55 states accepts LL. The complement has a DFA with the same 55 states, accepting set swapped. If the DFA is the minimal DFA of LL, the swapped machine is the minimal DFA of L‾\overline{L}.

EX 2Product bound

Easy

L1L_1 has a DFA with 44 states and L2L_2 a DFA with 66 states. L1∪L2L_1 \cup L_2 has a DFA with at most 2424 states, and so does L1∩L2L_1 \cap L_2. The bound mnm n is reached for counters: aa's divisible by 33 and bb's divisible by 44 give 1212 minimal states for the union and also 1212 for the intersection (computed for four pairs of moduli).

EX 3A homomorphism

Medium

h(0)=01h(0) = 01, h(1)=εh(1) = \varepsilon, LL = "ends with 0101". Strings of LL are x01x01 with xx arbitrary; h(x01)=h(x)⋅01h(x01) = h(x) \cdot 01 and h(x)∈(01)∗h(x) \in (01)^*, so h(L)=(01)+h(L) = (01)^+: strictly smaller than the strings that merely end in 0101 (for example 001001 is not in h(L)h(L)). The minimal DFA has 44 states: q0→0q1→1q2q_0 \xrightarrow{0} q_1 \xrightarrow{1} q_2 (accepting), q2→0q1q_2 \xrightarrow{0} q_1, every other move goes to a dead state.

EX 4Is it regular

Medium

(a) a∗b∗∩{w:#a=#b}={anbn}a^* b^* \cap \{w : \#a = \#b\} = \{a^n b^n\}: the first language is regular and the result is not, so {w:#a=#b}\{w : \#a = \#b\} cannot be regular. (b) The set of binary strings with equally many 00s and 11s whose length is at most 100100 is regular: it is finite. (c) The set of binary strings that have equally many 00s and 11s and do not contain 0101: strings of the form 1i0j1^i 0^j with i=ji = j: non-regular. (d) L/{akbk}L / \{a^k b^k\} is regular for every regular LL (the quotient by a non-regular language still gives a regular language, since the DFA does not change).

EX 5Typical questions

GATE level

(a) "Which of the following is regular: L1∪L2L_1 \cup L_2 for L1L_1 regular, L2L_2 finite?" Yes (finite is regular). (b) "Is the set of all strings not in a regular language regular?" Yes, complement. (c) "Reversal of a regular language" is regular, and an nn-state DFA can need 2n2^n states for it. (d) "Subset of a regular language": not necessarily regular. (e) "Infinite union of regular languages": not necessarily regular. (f) "Is the family of regular languages closed under the operation half⁡(L)\operatorname{half}(L)?" Yes (constructed above). (g) "Is {wwR}\{ww^R\} regular?" No; closure does not help with that, use the pumping lemma (pumping lemma).

Cheat box

Cheat box

  • Closed: union, intersection, complement, difference, concatenation, star, reversal, homomorphism, inverse homomorphism, quotients, prefixes, suffixes, half.
  • Not closed: infinite union, infinite intersection, subsets (also subsets of finite sets are fine: they are finite).
  • Product m⋅nm \cdot n; complement mm; concatenation NFA m+nm + n; star NFA m+1m + 1; reversal NFA m+1m + 1 (DFA up to 2m2^m); inverse homomorphism at most mm.
  • Prove non-regular: intersect with a regular language, apply a homomorphism, take complements, until you reach a known non-regular language.
  • Complete the DFA before complementing.

Traps and GATE patterns

Connections

The pumping lemma (pumping lemma) and closure together prove most non-regularity statements; context-free languages are closed under fewer operations (closure of CFLs): they are not closed under intersection or complement.

PYQs

15 previous year questions from your book. I re-solved each one myself (6 by running or simulating, 9 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · Set 1 · MSQ · 2 marksQ2 · page 197 of the book
Let L1 and L2 be two languages over a finite alphabet,
such that L1∩L2 and L2 are regular languages. Which of
the following statements is/are always true?
  • (a). L1 is regular
  • (b). L1∪L2 is regular
  • (c). L2 is context-free
  • (d). L1 is context-free
GATE 2025 · Set 2 · MSQ · 1 markQ9 · page 198 of the book
Consider the two lists List I and List II given below:

List 1
List 2
(i) Context free languages
  • (a)Closed under union (ii) Recursive languages
  • (b)Not closed under complementation (iii) Regular languages
  • (c)Closed under intersection For matching of items in List I with those in List II, which of the following option(s) is/are CORRECT?
  • (a)(i) – (a), (ii) – (b), and (iii) – (c)
  • (b)(i) – (b), (ii) – (a), and (iii) – (c)
  • (c)(i) – (b), (ii) – (c), and (iii) – (a)
  • (d)(i) – (a), (ii) – (c), and (iii) – (b)
GATE 2025 · Set 2 · MSQ · 2 marksQ10 · page 198 of the book
Let Σ = {a, b, c}. For x ∈ Σ* , and α ∈ Σ, let #α(x) denote
the number of occurrences of α in x. Which one or more of
the following option(s) define(s) regular language(s)?
  • (a){ambn | m, n ≥ 0}
  • (b){a, b}* ∩ {ambn cm - n | m ≥ n ≥ 0}
  • (c){w | w ∈ {a, b}* , #a (w) ≡ 2 (mod 7), and #b (w) ≡ 3 (mod 9)}
  • (d){w | w ∈ {a, b}* , #a (w) ≡ 2 (mod 7), and #a (w) ≡ #b(w)}
GATE 2024 · Set 1 · MSQ · 1 markQ13 · page 198 of the book
Let L1, L2 be two regular languages and L3 a language
which is not regular. Which of the following statements
is/are always TRUE?
  • (a). L1 = L2 if and only if L1 ∩L2 = φ
  • (b). L1 ∪L3 is not regular
  • (c). L3 is not regular
  • (d). L1 ∪L2 is regular THEORY OF COMPUTATION
GATE 2020 · MCQ · 1 markQ24 · page 200 of the book
Consider the following statements.
I. If L1 U L2 is regular, then both L1 and L2 must be
regular.
II. The class of regular languages is closed under infinite
union.
Which of the above statements is/are TRUE?
  • (a)Both I and II
  • (b)II only
  • (c)Neither I nor II
  • (d)I only
GATE 2019 · MCQ · 1 markQ25 · page 200 of the book
If L is a regular language over Σ = {a,b}, which one of the
following languages is NOT regular?
  • (a)Suffix (L) = {y ε Σ* such that xy ε L}
  • (b){wwR | w ε L}
  • (c)Prefix (L) = {x ε Σ*| ∃y ε Σ* such that xy ε L}
  • (d)L.L R = {xy | x ε L, yR ε L}
GATE 2015 · Set 1 · MCQ · 2 marksQ39 · page 202 of the book
Consider the DFAs M and N given above. The number of
states in a minimal DFA that accepts the language
 L(M) ∩ L(N) is __________.
  • (a). 1
  • (b). 2
  • (c). 3
  • (d). 4
GATE 2015 · Set 2 · MCQ · 2 marksQ40 · page 202 of the book
Which of the following language is/are regular
languages?

L1 : {wxwR|w,x ε {a, b}* and |w|, |x| > 0}, wR is the
reverse of string w
L2 : {anbm | m != n and m, n >= 0}
L3 : {apbqcr | p, q, r >= 0}
  • (a)L1 and L3 only
  • (b)L2 only
  • (c)L2 and L3 only
  • (d)L3 only
GATE 2014 · Set 2 · MCQ · 1 markQ47 · page 203 of the book
If L1 = {an | n > 0} and L2 = {bn | n >= 0}, consider
(I) L1.L2 is a regular language
(II) L1.L2 = {anbn | n >= 0}
Which one of the following is CORRECT?
  • (a)Only (I)
  • (b)Only (II)
  • (c)Both (I) and (II)
  • (d)Neither (I) nor (II)
GATE 2011 · MCQ · 1 markQ56 · page 205 of the book
Let P be a regular language and Q be a context-free
language such that Q ⊆ P. (For example, let P be the
language represented by the regular expression p*q* and
Q be [pnqn | n ∈ N]). Then which of the following
is ALWAYS regular?
  • (a)P ∩ Q
  • (b)P – Q
  • (c)Σ* – P
  • (d)Σ* – Q
GATE 2008 · MCQQ61 · page 206 of the book
Given below are two finite state automata (-> indicates
the start state and F indicates a final state)
Automaton Y

a
b
→1
1
2
2(F)
2
1

Automaton Z

a
b
→1
2
2
2(F)
1
1
Which of the following represents the product
automaton Z × Y?
  • (a). a b →p S R Q R S R(F) Q P S Q P
  • (b)a b →p S Q Q R S R(F) Q P S P Q
  • (c)a b →p Q S Q R S R(F) Q P S Q P
  • (d)a b →p S Q Q S R R(F) Q P S Q P THEORY OF COMPUTATION
GATE 2008 · MSQ · 2 marksQ64 · page 207 of the book
Consider the following two finite automata. M1 accepts L1
and M2 accepts L2

Which one of the following is TRUE?
  • (a). L1 = L2
  • (b). L1 ⊂ L2
  • (c). L1 ∩ L2c = ∅
  • (d). L1 ∪ L2 ≠ L1
GATE 2007 · MCQQ68 · page 208 of the book
Consider the following finite automata P and Q over the
alphabet {a, b, c}. The start states are indicated by a
double arrow and final states are indicated by a double
circle. Let the languages recognized by them be denoted
by L(P) and L(Q) respectively.

The automata which recognizes the language L(P) ∩
L(Q) is:
  • (a).
  • (b).
  • (c).
  • (d). THEORY OF COMPUTATION
GATE 2007 · MCQQ72 · page 210 of the book
Which of the following is TRUE?
  • (a)Every subset of a regular set is regular
  • (b)Every finite subset of a non-regular set is regular
  • (c)The union of two non-regular sets is not regular
  • (d)Infinite union of finite sets is regular
year not read yetQ14 · page 227 of the book
Consider the following languages:
L1 = { anwan | w ∈ {a, b}* }
L2 = { wxwr | w, x ∈ {a, b}*, |w|, |x| > 0 }
Note that wr is the reversal of the string w. Which of
the following is/are TRUE?
  • (a)L1 and L2 are regular.
  • (b)L1 and L2 are context-free.
  • (c)L1 is regular and L2 is context-free.
  • (d)L1 and L2 are context-free but not regular.

Self-check

Question 1

Is the intersection of two regular languages always regular? How many states does the product need at most?

Show answer

Yes. At most mnm n for DFAs of mm and nn states.

Question 2

LL is regular and FF is a finite language. Is L∖FL \setminus F regular?

Show answer

Yes: FF is regular, regular languages are closed under difference.

Question 3

Show {w∈{a,b}∗:#a=#b}\{w \in \{a, b\}^* : \#a = \#b\} is not regular using closure.

Show answer

Intersect it with the regular language a∗b∗a^* b^*; the result is {anbn}\{a^n b^n\}, which is not regular. A regular LL would give a regular intersection.

Question 4

Why must a DFA be complete before swapping the accepting states?

Show answer

A missing transition stands for rejection. After the swap those strings must be accepted, which only a dead state (made accepting) can do.

Question 5

The minimal DFA of "the 44th symbol from the start is 11" has 66 states. How many does its reversal need?

Show answer

24=162^4 = 16.

Revision card

One-screen revision

  • Closed under all the usual operations; not under infinite union or subsets.
  • Product mnmn, complement mm, concatenation NFA m+nm + n, star NFA m+1m + 1, reversal NFA m+1m + 1 but DFA up to 2m2^m.
  • Non-regularity: intersect with a regular language to reach {anbn}\{a^n b^n\}.
  • Complement needs the complete DFA.

References

  • ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 1.1 (closure under union, concatenation, star, Theorems 1.25 to 1.49)
  • ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Chapter 4, Section 4.2 (closure properties of regular languages)

Verification

scripts/enum-checks/toc_regular.py: on 120 random pairs of DFAs (up to 5 states) every construction on this page (product for union, intersection and difference; complement; concatenation NFA; star NFA; reversal NFA; non-erasing homomorphism NFA; inverse homomorphism DFA; right quotient by a symbol; prefix closure) accepts exactly the strings that the set definition says, on every string up to length 8 (star and prefixes up to length 6, homomorphic image by brute force over preimages). Half(L), suffix(L) and the quotient by the NON-regular language a^k b^k were constructed and compared with their definitions on 300 random DFAs. For 'ends with 01' and 'even number of 1s' the sizes in the table were recomputed from distinct futures; reversal of the DFA 'n-th symbol is 1' (n + 2 states) needs exactly 2^n states for n = 2..6; union and intersection of counters modulo m and n need exactly m * n states for four pairs. The upper bound for concatenation and the infinite-union examples are standard facts, not machine-proved here (needs verification). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never