Theory of Computation
Regular Properties
GATE asks “which of these languages is regular?” and “which closure property holds?”. Learn the pumping-lemma game, the closure table, and the short list of classic regular and non-regular languages.
GATE CSE properties of regular languages — pumping lemma (and how GATE uses it to prove non-regularity), closure under union, concatenation, star, complement, intersection and homomorphism, Myhill-Nerode idea, and regular vs non-regular language MCQs.
Learning outcomes
- State the pumping lemma for regular languages and use it as a game to prove a language is NOT regular
- Recall closure of regular languages under union, concatenation, star, complement, intersection, difference, reversal and homomorphism
- Use closure properties (for example intersection with a*b*) to prove non-regularity indirectly
- Classify classic languages as regular or non-regular and recognise decidable questions about regular languages
Closure properties of regular languages
- Regular languages are closed under union, intersection, complement, difference, concatenation, Kleene star, reversal, homomorphism, inverse homomorphism, prefix/suffix closure and quotient with any language.
- Union, concatenation and star follow from regular expressions; complement and intersection use a complete DFA (swap final states / product construction); reversal reverses the NFA arrows; homomorphism replaces each symbol by a string in the regex.
- Closure is under FINITE operations only: an infinite union of regular languages need not be regular, e.g. ∪_{n ≥ 0} {a^n b^n} is the non-regular language {a^n b^n}.
- An arbitrary subset of a regular language need not be regular: Σ* is regular, but {a^n b^n} ⊂ Σ* is not. Likewise a superset or an arbitrary language L with L ⊆ regular tells nothing.
- If L1 ∪ L2 is regular, neither L1 nor L2 must be regular (take L1 = {a^n b^n} and L2 = Σ*, whose union is Σ*). Similarly L1 ∩ L2 can be regular even when both L1 and L2 are non-regular (for example disjoint non-regular languages with ∅ as the intersection).
- Complement of a non-regular language is non-regular (otherwise complementing again would make the original regular). Concatenation or union of two non-regular languages can however be regular.
- Homomorphism: h(L) is regular for regular L, but h of a non-regular language can be regular (for instance h mapping every symbol to ε).
- Closure under these operations is the tool for indirect non-regularity proofs: if L were regular then L ∩ a*b* would be regular, which is false for L = {w | #a(w) = #b(w)}.
- Constructions behind each closure: union/intersection → product DFA (m·n states); complement → complete DFA with F ↔ Q∖F (n states, no blow-up); reversal → reverse arrows of the NFA (DFA may need 2^n states); star/concatenation → ε-moves; difference L1 ∖ L2 = L1 ∩ complement(L2).
- Quotient: L1 / L2 = {x | ∃y ∈ L2, xy ∈ L1} is regular for regular L1 and ANY L2 (even non-regular). Mark as final every state from which some string of L2 reaches a final state of the DFA for L1. Typical GATE use: init(L) = {x | ∃y xy ∈ L} is regular.
- Inverse homomorphism h⁻¹(L) = {w | h(w) ∈ L} is regular; compute by running the DFA of L on the image h(a) for every symbol a. Homomorphic image can blow up the regex size but never leaves the regular class.
- Closed ≠ size-preserving: complement keeps n states, product multiplies (m·n), reversal can blow up exponentially, and star on an NFA only adds one state plus ε-moves.
- Special operations: min(L) = {w ∈ L | no proper prefix of w is in L} and max(L) are regular; cyclic shift, “half(L) = {x | ∃y, |y| = |x|, xy ∈ L}” are also regular (half is a classic hard example, proved by guessing the midpoint state with an NFA that simulates two copies of the DFA).
| Operation | Regular languages closed? |
|---|---|
| Union, intersection, complement, difference | Yes |
| Concatenation, Kleene star, reversal | Yes |
| Homomorphism, inverse homomorphism | Yes |
| Prefix, suffix, quotient | Yes |
| Finite union / intersection | Yes |
| Infinite union | No |
| Arbitrary subset of a regular language | No |
Worked example
Problem. Show that L = {w ∈ {a,b}* | #a(w) = #b(w)} is not regular using closure properties.
Solution. If L were regular, then L ∩ L(a*b*) would be regular. But L ∩ a*b* = {a^n b^n | n ≥ 0}, which is non-regular (pumping lemma). Contradiction, so L is not regular.
Pumping lemma for regular languages
- Statement: if L is regular there is a pumping length p ≥ 1 such that EVERY string w ∈ L with |w| ≥ p can be written as w = xyz with (1) |y| ≥ 1, (2) |xy| ≤ p and (3) xy^i z ∈ L for all i ≥ 0.
- Idea: a DFA with p states reading a string of length ≥ p must repeat a state within the first p symbols (pigeonhole). The loop y can be pumped up or down and the string is still accepted.
- The lemma is a NECESSARY condition for regularity, never sufficient. A non-regular language may still satisfy it, so you can use it only to prove a language is NOT regular.
- Proof by contradiction as a game: (1) assume L is regular with pumping length p; (2) YOU choose a string w ∈ L with |w| ≥ p (depending on p); (3) the opponent splits w = xyz with |xy| ≤ p, |y| ≥ 1; (4) YOU pick i such that xy^i z ∉ L; contradiction.
- The choice of w must work for EVERY legal split. Because |xy| ≤ p, the segment y lies entirely inside the first p symbols of w — choose w so that its first p symbols are all the same (for example a^p b^p).
- Pumping down (i = 0) is often the quickest: for {a^n b^n} with w = a^p b^p, y is all a’s, so xz has fewer a’s than b’s.
- Standard w choices: {a^n b^n}: a^p b^p; {a^(n²)}: a^(p²); {ww}: 0^p 1 0^p 1; {a^n b^m : n > m}: a^(p+1) b^p with i = 0; {a^p : p prime}: a^q with q a prime ≥ p and i = q + 1.
- Pumping lemma cannot show a language is regular. To prove regularity, give a DFA, NFA or regular expression.
- Common mistakes: (a) choosing w that depends on a particular split instead of on p alone; (b) forgetting that |xy| ≤ p restricts WHERE y can lie; (c) assuming y is a single symbol — it can be any nonempty block inside the first p symbols; (d) trying i = 1, which never changes the string.
- Pumping length is not unique: if p works then any p′ ≥ p works. A finite language has pumping length longer than its longest string (so the condition holds vacuously). A regular language with an n-state minimal DFA has p = n.
- Quantifier order matters: ∃p ∀w ∃(split) ∀i for the lemma, so for the PROOF of non-regularity you flip to ∀p ∃w ∀(split) ∃i. Mixing the order is the usual source of wrong arguments.
Formulas to remember
-
L regular ⇒ ∃ p ∀ w ∈ L, |w| ≥ p ∃ xyz = w: |y| ≥ 1, |xy| ≤ p, ∀ i ≥ 0 xy^i z ∈ L
| Language | String w | Pump i | Why it fails |
|---|---|---|---|
| {a^n b^n} | a^p b^p | 0 or 2 | y ⊆ a’s: a’s ≠ b’s |
| {a^(n²)} | a^(p²) | 2 | p² < p² + |y| ≤ p² + p < (p+1)² |
| {ww} | 0^p 1 0^p 1 | 2 | y ⊆ first block of 0s: halves differ |
| {a^p : p prime} | a^q, q ≥ p prime | q + 1 | length q(1 + |y|) is composite |
| {a^n b^m : n > m} | a^(p+1) b^p | 0 | a’s drop to ≤ b’s |
Worked example
Problem. Show L = {a^(n²) | n ≥ 0} is not regular.
Solution. Assume regular with pumping length p. Take w = a^(p²). Then y = a^k with 1 ≤ k ≤ p. Pumping once gives length p² + k with p² < p² + k ≤ p² + p < (p + 1)², so it lies strictly between two consecutive squares and is not a square. Contradiction, so L is not regular.
Worked example — pumping lemma for palindromes
- Claim: PAL = {w ∈ {a,b}* | w = w^R} is not regular. Assume it is regular with pumping length p.
- Choose w = a^p b a^p. It is a palindrome of length 2p + 1 ≥ p, so w ∈ PAL. The special middle b prevents the opponent from finding a symmetric split.
- Any split w = xyz with |xy| ≤ p puts y strictly inside the first block of a’s, so y = a^k for some k with 1 ≤ k ≤ p.
- Pump up with i = 2: xy²z = a^(p+k) b a^p. The left block has p + k a’s, the right block has p a’s, and k ≥ 1, so the string is not a palindrome — a contradiction.
- Why not w = a^p a^p? That string a^(2p) stays a palindrome after pumping (still all a’s), so the proof would fail. A good w must make pumping break a symmetry or a count.
- The same template proves {ww^R}, {ww} and {w c w} non-regular: choose w with a uniform first block, a unique separator, and a mirrored second half.
- Odd and even palindromes are both non-regular, but palindromes over a ONE-letter alphabet are just a*, which is regular — alphabet size matters.
| Step | Move | Result |
|---|---|---|
| 1 | Assume regular, pumping length p | p ≥ 1 fixed by the opponent |
| 2 | Pick w = a^p b a^p | palindrome, |w| = 2p + 1 |
| 3 | Any split has y = a^k, 1 ≤ k ≤ p | y inside the first block |
| 4 | Pump i = 2 | a^(p+k) b a^p |
| 5 | Compare with its reverse | not a palindrome ⇒ contradiction |
Worked example
Problem. Show that L = {0^n 1 0^n | n ≥ 0} is not regular.
Solution. Assume regular with pumping length p and take w = 0^p 1 0^p ∈ L. Because |xy| ≤ p, y = 0^k with 1 ≤ k ≤ p. Then xz = 0^(p−k) 1 0^p has fewer 0s before the 1 than after it, so xz ∉ L. This contradicts the pumping lemma, so L is not regular.
Worked example — proving non-regularity by closure
- Goal: show L = {a^n b^m | n ≠ m} is not regular without running the pumping lemma on L itself.
- Step 1: assume L is regular. Regular languages are closed under complement, so L̄ (over {a, b}) would be regular.
- Step 2: intersect with the regular language a*b*: L̄ ∩ a*b* would be regular (closure under intersection).
- Step 3: compute that intersection. A string a^n b^m is in L̄ exactly when NOT (n ≠ m), i.e. n = m. So L̄ ∩ a*b* = {a^n b^n | n ≥ 0}.
- Step 4: {a^n b^n} is not regular (pumping lemma or Myhill-Nerode), a contradiction. Hence L is not regular.
- Template: reduce a new language to a known non-regular one using only operations under which regular languages are closed (∩ with a*b*, complement, homomorphism, inverse homomorphism, quotient).
- Homomorphism variant: to show {0^n 1^n 2^n} is non-regular, take h(0) = a, h(1) = b, h(2) = ε; h(L) = {a^n b^n} which is non-regular, so L cannot be regular (homomorphic images of regular sets are regular).
- Warning: closure rules go ONE way. “L ∩ R regular” does not imply L regular; the argument only works when the operation preserves regularity.
Formulas to remember
-
L regular ⇒ complement(L) regular ⇒ complement(L) ∩ a*b* regular -
L = {a^n b^m | n ≠ m}: complement(L) ∩ a*b* = {a^n b^n}
| Given | Is the result regular? | Why |
|---|---|---|
| L1 regular, L2 non-regular: L1 ∪ L2 | Not necessarily | L1 = Σ*, L2 = {a^n b^n} gives Σ*, but L1 = ∅ gives L2 |
| L1, L2 both non-regular: L1 ∪ L2 | Can be | L and complement(L) union to Σ* |
| L non-regular: complement(L) | Never regular | complement twice would make L regular |
| L regular: any subset of L | Not necessarily | {a^n b^n} ⊂ a*b* |
| L regular: h(L), h⁻¹(L), L^R, L* | Always | closure properties |
Worked example
Problem. Is {0^n 1^n 2^n | n ≥ 0} regular? Argue with a homomorphism.
Solution. No. Let h(0) = a, h(1) = b, h(2) = ε. Then h({0^n 1^n 2^n}) = {a^n b^n}, which is not regular. Regular languages are closed under homomorphism, so if {0^n 1^n 2^n} were regular, {a^n b^n} would be too — a contradiction.
Classic regular vs non-regular languages
- Non-regular (needs unbounded counting or matching): {a^n b^n}, {a^n b^m | n > m}, {a^n b^m | n ≠ m}, {w | #a = #b}, {ww}, {ww^R} (even palindromes), palindromes, {a^(n²)}, {a^(2^n)}, {a^p | p prime}, {a^n b^(n²)}, {a^i b^j | i > j}.
- Regular (bounded memory suffices): {a^i b^j | i, j ≥ 0} = a*b*, {w | #a(w) mod m = r}, {w | |w| is even}, strings with a fixed substring, ending/starting patterns, and ANY finite language.
- Surprising regular languages: {xy | x, y ∈ {a,b}*, |x| = |y|} = even-length strings; {w ∈ {0,1}* | #01(w) = #10(w)} = strings that are empty or start and end with the same symbol; {a^n b^n | n ≤ 10^6} is finite hence regular.
- A language with a bounded (constant) amount of counting is regular: “number of a’s is at most 5” and “#a mod 3 = 0” are regular, but “#a = #b” is not.
- Every finite language is regular; every subset of a finite language is finite and so regular. Unary context-free languages are regular (Parikh), but this is not needed for most MCQs.
- {a^n b^m c^(n+m)} and {a^n b^m | n ≠ m} are non-regular. The second follows because its complement intersected with a*b* gives {a^n b^n}.
- Ask whether the machine must remember an UNBOUNDED quantity (a count, a prefix to compare). If yes, the language is not regular; if only a constant amount (parity, remainder, last k symbols), it is regular.
- Mixed cases that look hard: {w | #a(w) − #b(w) ≡ 0 (mod 3)} is regular (3 states track the difference mod 3), but {w | #a(w) − #b(w) = 0} is not; {a^n b^m | n + m is even} is regular; {a^n b^m | n·m is even} is regular too (n·m is even exactly when n or m is even, a union of two simple languages).
- Subset trap: {a^n b^n | n ≥ 0} ⊂ a*b*, and a*b* is regular, yet the subset is not. Similarly L = {a^p | p prime} is a subset of a* (regular) and is not regular.
| Language | Regular? | Reason |
|---|---|---|
| {a^n b^n | n ≥ 0} | No | unbounded counting |
| {w | #a(w) = #b(w)} | No | unbounded counting |
| {ww} | No | must remember first half |
| {xy | |x| = |y|} | Yes | even length strings |
| {w | #01 = #10} | Yes | first symbol = last symbol |
| {a^p | p prime} | No | pumping changes primality |
| {a^n b^n | n ≤ 10^6} | Yes | finite language |
Worked example
Problem. Is L = {xy | x, y ∈ {a,b}*, |x| = |y|} regular?
Solution. Since x and y can be any strings with the same length, xy can be any even-length string. L = ((a+b)(a+b))*, which is regular, even though it looks like it needs matching.
Myhill-Nerode idea and decision problems
- Myhill-Nerode: define x ~_L y iff for every z, xz ∈ L ⇔ yz ∈ L. L is regular iff ~_L has finitely many equivalence classes; the number of classes equals the size of the minimal DFA.
- To show non-regularity with Myhill-Nerode, exhibit infinitely many strings that are pairwise distinguishable. For {a^n b^n}, the strings a^i and a^j (i ≠ j) are distinguished by the suffix b^i, so there are infinitely many classes.
- To get the minimal DFA size, count the distinct “futures” of prefixes. For “ends with 01” the three futures are those after ε, 0 and 01, giving 3 states.
- Decision problems for regular languages given as DFA / NFA / regex are all decidable: membership (simulate), emptiness (reachability of a final state), finiteness (a cycle on a path from the start to a final state means infinite), equivalence (minimal DFAs are isomorphic or the symmetric difference is empty), universality, and containment.
- Finiteness test: L(DFA) is infinite iff there is a string of length n ≤ |w| < 2n accepted by the DFA with n states.
- Closure tool to test equivalence: L1 = L2 iff (L1 ∖ L2) ∪ (L2 ∖ L1) = ∅, and emptiness is checkable on the product DFA.
Formulas to remember
-
x ~_L y ⇔ ∀z (xz ∈ L ⇔ yz ∈ L) -
|min DFA| = number of ~_L classes
| Problem for a DFA / regex | Decidable? | Method |
|---|---|---|
| Membership (w ∈ L?) | Yes | Simulate the DFA |
| Emptiness (L = ∅?) | Yes | No final state reachable |
| Finiteness (L finite?) | Yes | No cycle on a start → final path |
| Equivalence (L1 = L2?) | Yes | Symmetric-difference DFA is empty |
| Universality (L = Σ*?) | Yes | Complement is empty |
Worked example
Problem. Use Myhill-Nerode to show {a^n b^n} is not regular.
Solution. For i ≠ j, the strings a^i and a^j are distinguished by the suffix b^i: a^i b^i ∈ L but a^j b^i ∉ L. So the language has infinitely many Myhill-Nerode classes and cannot be regular.
GATE exam tricks — pumping lemma and closure MCQs
- GATE uses the pumping lemma only to show NON-regular. A statement “L satisfies the pumping lemma, therefore L is regular” is always false as a reasoning rule.
- Statement “an infinite union of regular languages is regular” is FALSE; “a finite union of regular languages is regular” is TRUE. Similarly “every subset of a regular language is regular” is FALSE.
- When asked “which language is regular”, look for bounded memory: parity, modulo, fixed suffix/prefix/substring or finite. Reject equal counts, squares, primes, powers of 2, ww and palindromes.
- Indirect proof: to show {a^n b^m | n ≠ m} is non-regular, note that if it were regular its complement intersected with a*b* would be regular, but that intersection is {a^n b^n}.
- Check homomorphism questions by applying h to a typical string: h(0) = aa, h(1) = ε sends (01)* to (aa)*.
- Emptiness, finiteness, membership and equivalence are all decidable for regular languages given as DFA / NFA / regex. Questions listing these as “undecidable” are distractors; undecidability appears only for CFG equivalence and TM problems.
Worked example
Problem. L1 is regular and L1 ∪ L2 is regular. Must L2 be regular?
Solution. No. Take L1 = Σ* (regular) and L2 = {a^n b^n}. Then L1 ∪ L2 = Σ* is regular but L2 is not.
Exam tips
- Use the pumping lemma only to disprove regularity; never to prove it.
- Pick a string whose first p symbols are identical, so that y is forced to be a block of one symbol.
- Use closure (intersection with a*b*, complement) to reduce unfamiliar languages to {a^n b^n}.
- Ask “does the machine need unbounded memory?” — if yes, the language is not regular.
- Finite unions and finite languages stay regular; infinite unions and arbitrary subsets may not.
10 GATE-style MCQs for Regular Properties with full explanations. Attempt each question before revealing the answer.
Which of the following languages over {0, 1} is regular?
Show answer & explanation
Answer: D
Occurrences of 01 and 10 alternate along the string, so their counts are equal exactly when the first and last symbol of w coincide (or w is empty). That is a regular condition. A, B and C need unbounded memory.
Let L be a regular language. Which of the following is NOT necessarily regular?
Show answer & explanation
Answer: C
Regular languages are closed under star, reversal and complement, but a subset of a regular language can be non-regular (e.g., {a^n b^n} ⊂ Σ*).
To prove that {a^n b^n | n ≥ 0} is not regular with the pumping lemma, take w = a^p b^p. For any split w = xyz with |xy| ≤ p and |y| ≥ 1, the substring y consists of:
Show answer & explanation
Answer: C
Because |xy| ≤ p, both x and y lie in the initial block a^p, so y = a^k with k ≥ 1. Pumping changes the number of a’s but not the b’s.
Which of the following languages is NOT regular?
Show answer & explanation
Answer: B
The set of prime lengths is not periodic. Pumping a^q (q prime) i = q + 1 times gives length q(1 + |y|), which is composite.
Which technique correctly shows that L = {w ∈ {a,b}* | #a(w) = #b(w)} is not regular?
Show answer & explanation
Answer: B
If L were regular then L ∩ a*b* would be regular because regular languages are closed under intersection. But that intersection is {a^n b^n}, which is not regular.
Let h(0) = aa and h(1) = ε be a homomorphism. If L = (01)*, then h(L) is:
Show answer & explanation
Answer: A
Each 01 maps to aa·ε = aa, so h((01)*) = (aa)*, which is regular.
The number of Myhill-Nerode equivalence classes of L = {w ∈ {a,b}* | |w| is divisible by 4} is:
Show answer & explanation
Answer: B
A prefix is characterised by its length mod 4, giving 4 classes, so the minimal DFA has 4 states.
L1 ∪ L2 is regular and L1 is regular. Which statement is correct?
Show answer & explanation
Answer: B
Take L1 = Σ* and L2 = {a^n b^n}: L1 ∪ L2 = Σ* is regular but L2 is not.
If a language L satisfies the conditions of the pumping lemma for regular languages, then L is:
Show answer & explanation
Answer: B
The pumping lemma is only a necessary condition. For example {a^i b^j c^k | i = 1 ⇒ j = k} is non-regular yet satisfies the pumping property.
Which of the following languages is regular?
Show answer & explanation
Answer: B
Since x and y are arbitrary, xy ranges over all even-length strings, i.e. ((a+b)(a+b))*, which is regular. A, C and D are not regular.
Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.
A complete minimal DFA for L has n states. The minimal DFA for the complement of L has:
Show answer & explanation
Answer: B) n states
Swapping final and non-final states of a complete DFA keeps it minimal with the same number of states.
Which of the following languages over {0, 1} is regular?
Show answer & explanation
Answer: B) {0^n 1^m | n + m is even}
n + m is even iff n and m have the same parity: (00)*(11)* + 0(00)*1(11)*. Only parities must be remembered, so it is regular.
If L = a(a + b)*, the reversal L^R is:
Show answer & explanation
Answer: B) (a + b)*a
Reversing every string that starts with a gives strings that end with a: (a + b)*a.
Is the union of an infinite family of regular languages always regular?
Show answer & explanation
Answer: B) No, not necessarily
{a^n b^n | n ≥ 0} is the union over n of the single-string languages {a^n b^n}, yet it is non-regular. Closure holds only for finite unions.
A finite language has a longest string of length 6. A valid pumping length p for this language is:
Show answer & explanation
Answer: C) 7
With p = 7 no string has length ≥ p, so the pumping condition is vacuously true. p must exceed the longest string length.
The minimum number of states in a DFA for {a^n | n is a multiple of 3 or a multiple of 5} is:
Show answer & explanation
Answer: B) 15
The language is periodic with minimal period 15, so the minimal DFA is a cycle of 15 states.
To prove that {ww | w ∈ {0,1}*} is not regular via the pumping lemma, a suitable string is:
Show answer & explanation
Answer: B) 0^p 1 0^p 1
Since |xy| ≤ p, y lies in the first block 0^p; pumping changes the length of the first half only, so the two halves differ. The string 0^p 0^p fails as a choice because the opponent can pick y = 00 and every pumped string 0^(2p+2i−2) is still of the form ww.
If L is non-regular and h is a homomorphism, then h(L) is:
Show answer & explanation
Answer: C) not necessarily non-regular
If h maps every symbol to ε, then h(L) ⊆ {ε} is regular for every L.
If L1 and L2 are both non-regular, then L1 ∩ L2:
Show answer & explanation
Answer: C) can be regular
For instance L1 = {a^n b^n} and L2 = {a^n b^(n+1)} are disjoint non-regular languages, so L1 ∩ L2 = ∅ is regular.
For L = {a^n b^n | n ≥ 0}, the number of Myhill-Nerode equivalence classes is:
Show answer & explanation
Answer: D) infinite
The prefixes a^i (i ≥ 0) are pairwise distinguishable using suffix b^i, giving infinitely many classes, so L is not regular.
Topic FAQs
Can the pumping lemma prove that a language is regular?
No. It is a necessary condition for regularity. A non-regular language can satisfy the pumping property, so you only use it to prove non-regularity by contradiction.
Why must the pumped substring lie within the first p symbols?
The lemma guarantees |xy| ≤ p, so y is inside the first p symbols. Choosing w with a uniform first block (such as a^p) forces y to consist of that symbol alone.
Are regular languages closed under infinite union?
No. {a^n b^n} is the union over n of the finite (hence regular) languages {a^n b^n}, but it is not regular.
Is the complement of a non-regular language regular?
No. If the complement were regular, then complementing it again would make the original language regular, a contradiction.
Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.