Back to the 2023 paper

Module 2: Context-Free Languages (CFL) and PDA

20237m

State the pumping lemma for context-free languages.

Worked SolutionAI Assisted

Answer

Pumping Lemma for Context-Free Languages (CFL)

Statement:
Let LL be a context-free language. Then there exists a constant p≥1p \ge 1 (the pumping length) such that for every string w∈Lw \in L with ∣w∣≥p|w| \ge p, ww can be written as

w=uvxyz w = uvxyz

satisfying the following conditions:

  1. ∣vxy∣≤p|vxy| \le p — the middle part vxyvxy is short (bounded by pp)
  2. ∣vy∣≥1|vy| \ge 1 — at least one of vv or yy is non-empty (not both empty)
  3. For all i≥0i \ge 0: uvixyiz∈Luv^i x y^i z \in L — pumping vv and yy together (0, 1, 2, … times) keeps the string in LL

Interpretation

  • For any sufficiently long CFL string, you can find a decomposition into 5 parts such that the inner vv and yy can be "pumped" simultaneously (repeated same number of times) and the result stays in the language.
  • The simultaneous pumping of vv and yy is the key difference from the regular pumping lemma (which pumps a single yy).
  • ∣vxy∣≤p|vxy| \le p means the "pumpable" region is near the center of the string (within length pp).

How to Use (Proving Non-CFL)

To prove LL is not context-free:

  1. Assume LL is CFL → pumping lemma holds with some pp.
  2. Choose a specific string w∈Lw \in L with ∣w∣≥p|w| \ge p (usually w=apbpcpw = a^p b^p c^p or similar).
  3. Show that for every valid decomposition w=uvxyzw = uvxyz satisfying (1) and (2), there exists some ii such that $uv^i x y^i z
    otin L$.
  4. Contradiction → LL not CFL.

Common Strategy: Choose ww so that any vxyvxy of length ≤p\le p cannot span all "coordinated" parts (e.g., three blocks apbpcpa^p b^p c^p). Pumping disrupts the balance.


Example Application

Prove L={anbncn∣n≥0}L = \{a^n b^n c^n \mid n \ge 0\} is not CFL.

  1. Let pp be pumping length. Take w=apbpcp∈Lw = a^p b^p c^p \in L, ∣w∣=3p≥p|w| = 3p \ge p.
  2. By lemma, w=uvxyzw = uvxyz with ∣vxy∣≤p|vxy| \le p, ∣vy∣≥1|vy| \ge 1.
  3. Since ∣vxy∣≤p|vxy| \le p, the substring vxyvxy cannot contain aa's, bb's, and cc's simultaneously — it lies within at most two adjacent blocks.
  4. Cases:
    • vxyvxy only in aa's: pumping adds aa's → $#a
      eq #b = #c$ ❌
    • vxyvxy only in bb's: pumping adds bb's → $#b
      eq #a, #c$ ❌
    • vxyvxy only in cc's: pumping adds cc's ❌
    • vxyvxy spans apbpa^p b^p boundary: pumping changes #a\#a and #b\#b differently (or adds both) → $#a
      eq #bor or #b
      eq #c$ ❌
    • vxyvxy spans bpcpb^p c^p boundary: similar ❌
  5. All decompositions fail for some $i
    e 1$. Contradiction.

Contrast with Regular Pumping Lemma

Aspect Regular (Type-3) CFL (Type-2)
String split w=xyzw = xyz w=uvxyzw = uvxyz
Pumped part yy (single) vv and yy (pair)
Constraint ∣xy∣≤p|xy| \le p ∣vxy∣≤p|vxy| \le p
Non-empty ∣y∣≥1|y| \ge 1 ∣vy∣≥1|vy| \ge 1
Result xyiz∈Lxy^i z \in L uvixyiz∈Luv^i x y^i z \in L

Important Notes

  • The lemma gives necessary but not sufficient condition for CFL.
  • There are non-CFL languages that satisfy the lemma (e.g., some non-context-free languages still pump).
  • For CFL, pumping is simultaneous of two substrings (vv and yy), reflecting stack push/pop pairing.
  • The pumping length pp depends on the grammar (e.g., number of variables in Chomsky Normal Form).

Final Answer

Pumping Lemma for CFL: ∃p≥1\exists p \ge 1 such that ∀w∈L,∣w∣≥p\forall w \in L, |w| \ge p, w=uvxyzw = uvxyz with ∣vxy∣≤p|vxy| \le p, ∣vy∣≥1|vy| \ge 1, and ∀i≥0,uvixyiz∈L\forall i \ge 0, uv^i x y^i z \in L. Used to prove languages like {anbncn}\{a^n b^n c^n\} are not context-free.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.