Pumping Lemma for Context-Free Languages

The Pumping Lemma for Context-Free Languages (CFLs) is a fundamental property used to prove that a language is not context-free. It is similar in working to the pumping lemma for regular languages.

Pumping Lemma For Context Free Language

Conditions for Pumping Lemma in Context-Free Languages

If is a context-free language, then there exists a constant pp (called the pumping length) such that every string w ∈ L with ∣w∣≥p can be written as:

w = uvxyzw 

such that the following conditions hold:

Condition 01: Length restriction:

∣vxy∣≤p

The length of “middle” part “vxy” sould always less than or equal to pumping “p” value.

Condition 02: Pumping parts not empty:

∣vy∣ ≥ 1

At least one of “v” or “y” is not empty. So that string can pump.

Condition 03: Closure under pumping

uvixyiz ∈ L for all i≥0

The string remains in the language for any number of repetitions (including zero).

Pumping Lemma Algorithm in Context-Free Languages

let explain the pumping lemma algorithm in context free languages

Pumping Lemma Algorithm for Context free Languages

Key Differences in Context-Free vs. Regular Pumping Lemma

Here’s a clear comparison showing the key differences between the Pumping Lemma for Regular Languages and Context-Free Languages:

Property Regular Languages Context-Free Languages
Division w=xyzw w=uvxyzw 
Repeatable part y v and y
Repetition xyiz uvixyiz

Pumping Lemma Examples

Example 01: Using Pumping Lemma prove that the language A = { yy | y ∈ {0,1}*is not context free language

Below is a descriptive diagram that explains that why the language A = { yy | y ∈ {0,1}* } is not a context-free language.

Pumping lemma in Context Free Grammar Examples - 01

Step-by-step proof using the Pumping Lemma for CFLs:

Let explain again why the language A = { yy | y ∈ {0,1}* } is not a context-free language by using different values of pumping “p” and “i”.

  1. Assume A is context-free.

  2. Let the pumping length be p=4 (or any value ≥ 1).

  3. Choose a string S=01010101 ∈ A, because this is of the form yy, where y=0101. So we can select the following string:

    S=0101 0101

  4. According to the pumping lemma, S can be split as:

    S=uvxyz 

    with:

    • ∣vxy∣≤p

    • ∣vy∣≥1

    • uvixyiz∈A, for all

  5. Let’s say:

    • u=0

    • v=1

    • x=0

    • y=1

    • z=0101

    Then:

    S

  6. Now pump with i=2

    uv2xy2z=

  7. Check the result:

    • The new string is 0110110101, which is not of the form yy (it’s not a repeat of the same string).

  8. So, the pumped string is not in language A.

Example 02: Using Pumping Lemma prove that the language A = { anbncn | n ≥ 0 } is not a Context Free Language



Below is a descriptive diagram that explains that why the language A ={ anbncn | n ≥ 0 } is not a context-free language.

Pumping lemma in Context Free Grammar Examples - 02

Explain: Pumping Lemma for CFLs

Let’s explain that, A = { aⁿ bⁿ cⁿ | n ≥ 1 } is not context-free by using different values of pumping “p” and “i”.

Note: By using different values of “p” and “i” as in the above diagram.

  • Assume A is context-free.
  • Let the pumping length be (or any value ≥ 1).
  • Choose a string S=aaabbbccc ∈ A, i.e., a3b3c3.
  • According to the pumping lemma rule, it can be written as:

S=uvxyz

With conditions:

  • ∣vxy∣≤p
  • ∣vy∣≥1
  • uvixyiz ∈ A, where

Let’s say:

  • u=a
  • v=a
  • x=a
  • y=b
  • z=bbccc

Then S=uvxyz=aaabbbccc, Now pump with i=2

S = uv2xy2z=aaaabbbbccc 

This gives 4 a’s, 4 b’s, and 3 c’s, which is not in A. Therefore, the pumped string is not in language A.

Example 03: Using Pumping Lemma prove that the language A = { anb2n | n ≥ 0 } is not a Context Free Language

Below is a descriptive diagram that explains that why the language A ={ anb2n | n ≥ 0 } is not a context-free language.

Pumping lemma in Context Free Grammar Examples - 03

Explain: Pumping Lemma for CFLs

Let’s explain that A = { aⁿ b²ⁿ | n ≥ 0 } is not a context-free language by using different values of pumping “p” and “i”.

Note: By using different values of “p” and “i” as in the above diagram.

  • Assume A is context-free.
  • Let the pumping length be (or any value ≥ 1).
  • Choose a string  S=a3b6=aaabbbbbb ∈ A.
  • According to the pumping lemma rule, it can be written as:

S=uvxyz

With conditions:

  • ∣vxy∣≤p
  • ∣vy∣≥1
  • uvixyiz ∈ A, where

Let’s say:

  • v=a
  • x=a
  • y=ε (empty, optional)
  • z=bbbbbb

Then

S=uvxyz=aaabbbbbb

Now pump with i=2

S = uv2xy2z=aaaabbbbbb=a4b6

But in A, for every “a “, the number of b’s must be twice the number of a’s.

  • Here: 4 a’s → should have 8 b’s

  • But we have only 6 b’s → not in A

"Your Support, Our Priority"

"We Make It Easy"