Pumping lemma for regular languages
The pumping lemma as a necessary condition for regularity: the statement with its quantifiers, the pigeonhole proof from a DFA with p states, the game view used to prove that a language is not regular (a^n b^n, ww, squares, primes, balanced parentheses), the standard mistakes (the lemma never proves regularity, the cut is chosen by the adversary), the pumpable-but-not-regular counterexample, and the DFA tests for emptiness and finiteness.
Why it exists
DFAs have finitely many states, so a long enough input must repeat a state, and the part of the input between the two visits can be repeated any number of times without the machine noticing. The pumping lemma turns this observation into a test: if a language has no such repeatable part, it is not regular. GATE asks it constantly: "which of these languages is not regular?" and "which step of this proof is wrong?"
Prerequisites
You need closure properties of regular languages (closure properties): many non-regularity proofs combine the pumping lemma with intersection or complement.
Precise definitions
Pumping lemma. If is a regular language, then there is an integer (the pumping length) such that every string with can be written as with
- (the pumped part is not empty),
- (the pumped part lies within the first symbols),
- for every (pumping up and also "pumping down" with ).
Quantifier structure (this is where mistakes come from):
It is only a necessary condition. The lemma can prove a language is not regular; it can never prove that a language is regular.
Proof sketch. Take a DFA for and let be its number of states. Let , . Reading the first symbols visits states (counting the start state), so by the pigeonhole principle some state occurs twice among them. Let be the string that leads from the start to the first visit of , the nonempty string that leads from back to , and the rest. Then , and going round the loop times (or not at all) still ends in the same accepting state: .
How it works
The game
To prove is not regular, play against an adversary who claims is regular.
- The adversary chooses (you cannot choose it).
- You choose a string with (it may depend on ; choose it so that the first symbols are very restricted).
- The adversary chooses any cut with and .
- You choose so that .
If you have a winning strategy for every and every cut, is not regular. The table plays the game with for six languages: for each, the string you choose, the number of legal cuts ( when : the pairs with , ), how many cuts survive pumping with and which breaks them.
The pumping lemma game with p = 5: start
Computed by a script, not typed| language | the string s chosen (|s| ≥ p) | cuts x y z with |xy| ≤ 5, |y| ≥ 1 | cuts that survive i = 0 ... 9 (or 11) | the pumping exponent i that breaks a cut |
|---|---|---|---|---|
| a^n b^n | ||||
| ww (a word followed by a copy of itself) | ||||
| a^(n^2) (squares) | ||||
| a^p, p a prime number | ||||
| balanced parentheses | ||||
| a^i b^j with i > j |
Step 0
For each non-regular language a string s of length at least p = 5 is chosen and every legal cut into x, y, z is tried with i = 0, 1, 2, ...; a cut 'survives' if all the pumped strings stay in the language. No cut survives, which is the contradiction the proof needs.
In every row no cut survives, which is the proof. Below are the arguments in words.
Standard proofs
. Choose . Since , consists only of 's. Then has fewer 's than 's, so it is not in .
. Choose with . The cut lies inside the first block of 's, so with and , of length . If is odd the length is odd, so it is not of the form . If is even then , and a hypothetical would have length , so would lie inside the leading block of 's and contain no , while contains two 's: contradiction. (A careless choice such as fails: the cut pumps to and always survives.)
. Choose . After pumping once, the length is with , strictly between and , so it is not a perfect square.
. Choose a prime . Pump with : the length is with , which is composite. (This works for every cut.)
Balanced parentheses. Choose . The cut lies inside the opening parentheses, so pumping down gives more closing than opening ones.
Palindromes. Choose . The cut lies inside the first block of 's; pumping up moves the away from the centre.
. Choose with ; after one pump the length lies strictly between and .
Languages that look hard but are regular. (equal numbers of occurrences of the substrings and ) is regular: the occurrences alternate, so the counts are equal iff the string is empty or begins and ends with the same symbol (checked for all strings up to length ). Do not be fooled by "equal counts".
Using it together with closure
For languages defined by counts of two symbols, intersect with first (closure properties): if were regular, would be regular; it is for . This is often shorter than the pumping argument.
The lemma is not an "if and only if"
There are non-regular languages that satisfy the pumping condition. Example:
Every string in with can be pumped with (verified for all strings up to length ). The cut always has : if , let be the first symbol (the string stays of the form ); if , let (pumping gives with or , which is in since , and is itself); if , let (the number of 's becomes , never ); if , let (the number of 's stays at least ). Yet is not regular, because is not. So: pumping condition holds does not mean regular. The exact characterisation is the Myhill-Nerode theorem (Myhill-Nerode): a language is regular iff it has finitely many classes of equivalent strings. For the strings all have different futures, so there are infinitely many classes; in the check, no DFA with states agrees with on all strings up to length (all machines tried).
Useful consequences for DFAs
Let a DFA have states.
- is non-empty iff it accepts a string of length .
- is infinite iff it accepts a string of length and .
- If is finite and its longest string has length , the pumping lemma holds with (no string is long enough, so the condition is empty): every finite language is regular.
Both tests agree with a direct graph search on 300 random DFAs.
Worked examples
EX 1Find a pumping cut
Easyhas a minimal DFA with states, so . Take (). The cuts with and : of them; only and survive every (checked up to ). For example , which is in . A cut such as , , fails: gives .
EX 2Why a^n b^n cannot be regular
EasyA DFA with states reading visits states, so two of the states after and () are equal. Then and end in the same state, but only the first is in the language: a contradiction. (This is the pumping argument without the formal quantifiers.)
EX 3Choosing the string
MediumProve is not regular. Take . The cut lies in the 's, . Pump down: has 's, so and it is not in . Pumping up would not work here ( keeps ): this is the example that needs .
EX 4A wrong choice of string
MediumTo show that is not regular, the string is in the language and long enough, but it does not work: the cut , , gives , which is for every . The adversary wins. The string must make every cut harmful: has a in a fixed place, so pumping the leading 's shifts it. The rule: choose a string whose first symbols are a single repeated symbol (so every cut is ) and whose rest makes any change of that block visible.
EX 5Typical questions
GATE level(a) Which of these is not regular: , , , ? . (b) "If satisfies the pumping lemma then is regular." False (counterexample above). (c) "If does not satisfy the pumping lemma then is not regular." True (contrapositive). (d) "The pumping length of a regular language is unique." False: any larger also works; for a language with a DFA of states one valid choice is . (e) "Every finite language satisfies the pumping lemma." True, vacuously. (f) "Is regular?" Yes. (g) Number of ways to cut a string of length at least into with , : ( for ).
Cheat box
Cheat box
- Regular : , , for all .
- Used only to prove NON-regularity. Never proves regularity. The converse is false.
- You choose (long, restricted first symbols); the adversary chooses and the cut; you choose ( pumps down).
- = number of states of a DFA. Finite languages are always regular.
- DFA with states: non-empty iff a string shorter than is accepted; infinite iff a string of length in is accepted.
- Non-regular: , , palindromes, , primes, balanced parentheses, . Regular though they look hard: equal numbers of and .
Traps and GATE patterns
Connections
Across subjects
No cross-subject links yet.
The same idea (a repeated state in a bounded computation) gives the pumping lemma for context-free languages with two pumped parts (pumping lemma for CFLs); the Myhill-Nerode theorem is the exact test that the pumping lemma only approximates (Myhill-Nerode); closure properties shorten many proofs (closure properties).
PYQs
11 previous year questions from your book. I re-solved each one myself (6 by running or simulating, 5 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following two languages over the alphabet {a,
b}:
L1 = { αβα | α ∈ {a, b}+ AND β ∈ {a, b}+ }
L2 = { αβα | α ∈ {a}+ AND β ∈ {a, b}+ }
Which ONE of the following statements is CORRECT?- (a). Both L1 and L2 are regular languages.
- (b). L1 is a regular language but L2 is not a regular language.
- (c). L1 is not a regular language but L2 is a regular language.
- (d). Neither L1 nor L2 is a regular language.
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)}
For Σ = {a,b}, let us consider the regular language L = {x|x
= a 2+3k or x = b 10+12k , k ≥ 0}. Which one of the following
can be a pumping length (the constant guaranteed by the
pumping lemma) for L?- (a)3
- (b)9
- (c)5
- (d)24
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
Let L1 = {w ∈ {0,1}* | w has at least as many occurrences
of (110)'s as (011)'s}. Let L2 = {w ∈ {0,1}*|w has at least
as many occurrences of (000)'s as (111)'s}. Which one of
the following is TRUE?- (a)L1 is regular but not L2.
- (b)L2 is regular but not L1.
- (c)Both L1 and L2 are regular.
- (d)Neither L1 nor L2 are regular THEORY OF COMPUTATION
Which one of the following is TRUE?
- (a)The language L = {anbn | n >= 0} is regular.
- (b)The language L = {an | n is prime} is regular.
- (c)The language L = {w | w has 3k + 1b's for some k ε N with Σ = {a, b} } is regular.
- (d)The language L = (ww| wεΣ* with Σ = {0, 1} } is regular.
Which of the following are regular sets?
I. { anb2m | n ≥ 0, m ≥ 0 }
II. { anbm | n = 2m }
III. { anbm | n ≠ m }
IV. { xcy | x, y ∈ {a, b}* }- (a)I and IV only
- (b)I and III only
- (c)I only
- (d)IV only M1 THEORY OF COMPUTATION
Which of the following languages is regular?
- (a){ wwR | w ∈ {0,1}+ }
- (b){ wwRx | x, w ∈ {0,1}+ }
- (c){ wxwR | x, w ∈ {0,1}+ }
- (d){ xwwR | x, w ∈ {0,1}+ }
If s is a string over (0 + 1)* then let n0(s) denote the number of 0's in s and n1(s) the number of 1's in s. Which one of the following languages is not regular?
- (a)L = { s ∈ (0 + 1)* | n0(s) is a 3-digit prime }
- (b)L = {s ∈ (0 + 1)* | for every prefix s' of s, | n0(s') - n1(s') | ≤ 2 }
- (c)L = { s ∈ (0 + 1)* | | n0(s) - n1(s) | ≤ 4 }
- (d)L = {s ∈ (0 + 1)* | n0(s) mod 7= n1(s) mod 5= 0 }
Consider the following languages.
L1 = {wxyx | w, x, y ε (0 + 1)+}
L2 = {xy | x, y ε(a + b)*, |x| = |y|, x !=y}
Which one of the following is TRUE?- (a)L1 is context-free but not regular and L2 is context-free.
- (b)Neither L1 nor L2 is context-free.
- (c)L1 is regular and L2 is context-free.
- (d)L1 is context-free but L2 is not context-free.
Which of the following is true for the language
{ ap| p is prime} ?- (a)It is not accepted by a Turing Machine
- (b)It is regular but not context-free
- (c)It is context-free but not regular
- (d)It is neither regular nor context-free, but accepted by a Turing machine
Self-check
Question 1
State the pumping lemma for regular languages. Which part of it does the adversary choose?
Show answerHide
Every regular has a such that each with can be split with , and for all . The adversary chooses and the split; you choose and .
Question 2
A DFA has states. What is a valid pumping length, and which test decides whether its language is infinite?
Show answerHide
. The language is infinite iff the DFA accepts a string of length from to .
Question 3
Prove is not regular by pumping.
Show answerHide
Take ; the pumped part has length with ; then lies strictly between and , so it is not a square.
Question 4
Is regular?
Show answerHide
Yes: it is the set of strings that are empty or have equal first and last symbols, a regular language.
Question 5
How many different cuts with and does a string of length at least have?
Show answerHide
: choose with .
Revision card
One-screen revision
- Necessary condition only; proves non-regularity, never regularity.
- You pick and ; the adversary picks and the cut with , .
- Choose so the first symbols are one repeated symbol. Try and .
- DFA with states: ; empty iff nothing shorter than ; infinite iff a string of length to .
- Non-regular: , , primes, squares, palindromes; regular: equal and counts.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 1.4 (Theorem 1.70, the pumping lemma for regular languages)
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 4.1 (the pumping lemma for regular languages)
Verification
scripts/enum-checks/toc_regular.py: in 300 random DFAs with n states, EVERY accepted string of length at least n over {a, b} up to length 9 (125128 strings) has a cut xyz with |xy| <= n, |y| >= 1 such that x y^i z is accepted for i = 0..7; for six non-regular languages (a^n b^n, ww, a^(n^2), a^p with p prime, balanced parentheses, a^i b^j with i > j) and palindromes the chosen string has NO pumpable cut for p = 1..8; no complete 3-state DFA agrees with a^n b^n on all strings up to length 8 (all 5832 machines tried) and the strings a^0..a^6 have 7 different futures; the language {a^i b^j c^k : i = 1 implies j = k} satisfies the pumping condition with p = 3 on all strings up to length 9 (checked with i up to 6), yet its intersection with a b* c* is {a b^j c^j}; emptiness (a string shorter than n) and finiteness (a string of length between n and 2n - 1) tests agree with a graph search on 300 random DFAs; the number of strings with equally many occurrences of 01 and 10 was checked for all strings up to length 14. The pumping lemma statement and proof are standard; unary-language and other quoted facts are marked. 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)