Explain Pumping lemma for context free language

Data Structure AlgorithmsComputer ScienceComputers

Pumping lemma for context free language (CFL) is used to prove that a language is not a Context free language

Assume L is context free language

Then there is a pumping length n such that any string w εL of length>=n can be written as follows −


We can break w into 5 strings, w=uvxyz, such as the ones given below

  • |vxy| >=n
  • |vy| # ε
  • For all k>=0, the string uvkxyyz∈L

The steps to prove that the language is not a context free by using pumping lemma are explained below −

  • Assume that L is context free.
  • The pumping length is n.
  • All strings longer than n can be pumped |w|>=n.
  • Now find a string 'w' in L such that |w|>=n.
  • Divide w into uvxyz
  • Show that uvkxykz ∉L for some k
  • Then, consider the ways that w can be divided into uvxyz.
  • Show that none of these can satisfy all the 3 pumping conditions at same time.
  • w cannot be pumped (contradiction).


Find out whether L={xnynzn|n>=1} is context free or not


  • Let L be context free.
  • L must satisfy pumping length, say n.
  • Now we can take a string such that s=xnynzn
  • We divide s into 5 strings uvxyz.

Let n=4 so, s=x4y4z4

Case 1:

v and y each contain only one type of symbol.

{we are considering only v and y because v and y has power uv2xy2z}

X xx x yyyyz z zz

=uvkxykz when k=2




(Number of x # number of y #number of z)

Therefore,The resultant string is not satisfying the condition

x6y4z5 ∉ L

If one case fails then no need to check another condition.

Case 2:

Either v or y has more than one kind of symbols

Xx xx yy y y zzzz

=uvkxykz (k=2)




This string is not following the pattern of our string xnynzn

Published on 12-Jun-2021 11:39:51