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 is not regular" (if were regular, then some regular combination of 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 over the following are all regular:
| operation | definition |
|---|---|
| union | |
| intersection | |
| complement | |
| difference | |
| symmetric difference | |
| concatenation | |
| star, plus | , |
| reversal | |
| homomorphism | where extended to strings |
| inverse homomorphism | |
| right quotient | , for any language |
| left quotient | |
| prefixes | |
| suffixes | |
| half |
Not closed. Infinite union and infinite intersection (every finite language is regular, but is not); and subsets: a subset of a regular language need not be regular ().
How it works
The constructions
Let be complete DFAs with and states.
- Complement. Swap accepting and non-accepting states of the complete DFA. 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 , moves go in parallel; accept if " accepts or accepts" (union), "and" (intersection), " accepts and does not" (difference). At most states. The bound is reached by two independent counters (the number of 's modulo and the number of 's modulo ; checked for four pairs).
- Concatenation. NFA: the two machines side by side, edges from the accepting states of the first to the start of the second. states. The equivalent DFA can have exponentially more (standard result, quoted).
- Star. NFA: a new accepting start state, edges from the accepting states back to the old start. states.
- Reversal. NFA: reverse every edge, make the old start the only accepting state, add a new start with edges to the old accepting states. states; the minimal DFA of the reversal can need states.
- Homomorphism. Replace each edge labelled by a path spelling (an edge if ).
- Inverse homomorphism. Same states: . At most states, a DFA directly.
- Quotients and prefixes. Same DFA with a changed accepting set: for accept the states from which some string of leads to acceptance (this is a property of the DFA, so 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 and the set of states from which some string of the length read so far leads to acceptance; accept if . Finite, so regular.
Sizes on a small example
= binary strings that end in ( states), = binary strings with an even number of s ( 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| operation | construction | states of the machine built | states of the minimal DFA | remark |
|---|---|---|---|---|
| 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.
The union and the intersection are built from states but both minimise to . Complement does not change the size. The reversal of "ends with " is "starts with ", whose minimal DFA has states (start, after , accepting, dead) even though the original had . The image under , is (verified), the inverse image under , is "ends with ", and the right quotient is also "ends with " (both with states). Every string is a prefix of a string ending in , so the prefix language is with state.
Reversal can blow up
Let = "the -th symbol from the start is ". Its minimal DFA has states (count to , then accept or reject, plus a trap). The reversal is "the -th symbol from the end is ", whose minimal DFA needs states. Computed for : . So an -state DFA can need about states for its reversal.
Using closure to show non-regularity
If is regular, so is for every regular . So to prove not regular, intersect with a regular language and get a known non-regular language.
- . Then is non-regular, so is not regular.
- . Its complement, intersected with , is , so is not regular.
- . Then is non-regular, so is not regular.
The converse direction: closure also shows languages regular without building a machine (for example a finite union of regular pieces, or for a finite ).
What you cannot conclude
- regular does not imply and regular ().
- regular and non-regular: and may or may not be regular ( gives , regular; gives , non-regular).
- regular does not imply and regular: and any language containing gives , however irregular is.
Worked examples
EX 1Complement size
EasyA complete DFA with states accepts . The complement has a DFA with the same states, accepting set swapped. If the DFA is the minimal DFA of , the swapped machine is the minimal DFA of .
EX 2Product bound
Easyhas a DFA with states and a DFA with states. has a DFA with at most states, and so does . The bound is reached for counters: 's divisible by and 's divisible by give minimal states for the union and also for the intersection (computed for four pairs of moduli).
EX 3A homomorphism
Medium, , = "ends with ". Strings of are with arbitrary; and , so : strictly smaller than the strings that merely end in (for example is not in ). The minimal DFA has states: (accepting), , every other move goes to a dead state.
EX 4Is it regular
Medium(a) : the first language is regular and the result is not, so cannot be regular. (b) The set of binary strings with equally many s and s whose length is at most is regular: it is finite. (c) The set of binary strings that have equally many s and s and do not contain : strings of the form with : non-regular. (d) is regular for every regular (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: for regular, 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 -state DFA can need 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 ?" Yes (constructed above). (g) "Is 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 ; complement ; concatenation NFA ; star NFA ; reversal NFA (DFA up to ); inverse homomorphism at most .
- 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
Builds on
Unlocks
Across subjects
No cross-subject links yet.
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
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
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)
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)}
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
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
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}
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
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
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)
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
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
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
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
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
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 answerHide
Yes. At most for DFAs of and states.
Question 2
is regular and is a finite language. Is regular?
Show answerHide
Yes: is regular, regular languages are closed under difference.
Question 3
Show is not regular using closure.
Show answerHide
Intersect it with the regular language ; the result is , which is not regular. A regular would give a regular intersection.
Question 4
Why must a DFA be complete before swapping the accepting states?
Show answerHide
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 th symbol from the start is " has states. How many does its reversal need?
Show answerHide
.
Revision card
One-screen revision
- Closed under all the usual operations; not under infinite union or subsets.
- Product , complement , concatenation NFA , star NFA , reversal NFA but DFA up to .
- Non-regularity: intersect with a regular language to reach .
- 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
My notes (saved in this browser)