What is pumping lemma?

Pumping lemma for regular languages

The pumping lemma is a property of a regular languageA formal language which can be expressed with a regular expression.. It is used to prove the non-regularity of certain languages.

Regular languages always satisfy the pumping lemma. However, if the pumping lemma is satisfied, the language does not need to be regular.

Note: This is only useful for infinite languages since all finite languages are regular.

Theorem

In simple terms, this theorem states that if LL is a regular language ∃ (there exists), a FA of pp states holds string sLs ∈ L. Then, for all strings sLs ∈ L, with sp|s| ≥ p, there exists a division of ss in three parts, i.e., S=x.y.zS= x.y.z, such that the following three conditions are held:

  • x.yp|x.y| ≤ p (length of xx + length of yy is p≤ p)
  • y!=0|y| != 0 ( xx,zz can be null, but yy cannot be null, and the length of y1y ≥ 1)
  • xyizL  i0xy^iz ∈ L \ ∀ \ i ≥ 0

Let's look at an example where the pumping lemma does not hold.

Example

Prove that L1=anbnn0L_1= {a^nb^n | n ≥ 0 } is a non-regular language.

Applying Pumping lemma

Step 1: Assume that L1L_1 is a regular language with pp states to prove by contradiction.

Step 2: Taking a string s with sp|s| ≥ p,s=apbps = a^pb^p

String s belongs to L1

Step 3: Dividing s into xx, yy, and zz. There are three possible divisions for yy in this case.

  Case 1: yy gets only aa's from apa^p

  Case 2: y gets only bb's from bpb^p

  Case 3: y gets some aa's and some bb's from apbpa^p b^p

Step 4: Pumping the yy substring.

  Case 1:

Contradiction: Pumping y gives us more number of a's than b's

  Case 2:

Contradiction: Pumping y gives us more number of b's than a's

  Case 3:

Contradiction: Pumping y generates a string where b's appear from a's

Because there is a contradiction in every case, we conclude that L1L_1 is not regular, and the pumping lemma does not hold.

Now, let's look at an example where the pumping lemma holds:

Example

Prove that L2L_2 = {all string ending with abaaba} is a non-regular language.

Applying pumping lemma

Step 1: Suppose that L2L_2 is a regular language and take a FA with p=8p=8

Step 2: Take a string ss with sp|s| ≥ p , s ends with 'abaaba'

string s with length > 8

Step 3: Divide ss into x,y,zx, y, z

Dividing s into x, y and z substrings

Step 4: Pump the yy substring such that:

y has been pumped twice

As the new string still ends with abaaba, we can conclude that the pumping lemma holds, but it cannot be said that L2L_2 is regular or non-regular. 

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved