4.6.12 · D2Theory of Computation

Visual walkthrough — Pumping lemma for CFLs

2,267 words10 min readBack to topic

Step 1 — What a parse tree looks like

A parse tree records how a string was built: start at the top circle , apply rules, and read the bottom row of leaves left-to-right to get your string.

Figure — Pumping lemma for CFLs

WHAT the figure shows: a tiny parse tree whose leaves spell a b b a. WHY we care: the whole lemma is a statement about the shape of this tree, not about algebra. Get comfortable reading trees now. PICTURE: follow the lavender circles (variables) down to the coral leaves (terminals). Reading the bottom row gives the string.


Step 2 — Why we force the tree to be binary (Chomsky Normal Form)

WHAT we did: we agreed to only look at grammars where circles split in two. WHY this tool and not another? Because a tree where every internal node has two children is a binary tree, and binary trees have a clean counting law (next step). A messy grammar could split into 5 children or loop ; CNF bans all of that. Any CFG can be rewritten into CNF without changing the language, so we lose nothing.

Figure — Pumping lemma for CFLs

PICTURE: left = a "wild" node with three children (forbidden). Right = the CNF version: every split is a clean fork of two.


Step 3 — The counting law: short trees can only hold few leaves

WHAT we did: bounded how many letters a short tree can spell. WHY the power of two? Because CNF forces two children per split — "two children" is literally the "" in . This is why we insisted on binary trees in Step 2.

Figure — Pumping lemma for CFLs

PICTURE: a full binary tree drawn level by level: nodes. The bottom row has leaves — count them.


Step 4 — Choosing the magic length

WHAT we did: picked a threshold length, one bigger than . WHY exactly ? Look back at Step 3's law . If a string is strictly longer than , then a tree of height cannot produce it — because such a tree caps out at leaves. Adding the turns "" into the strict "" we need. So any with is guaranteed to force a tall tree.

Figure — Pumping lemma for CFLs

PICTURE: a number line. Everything at or right of (mint zone) is "too long for a short tree." The butter dot at is the last length a height- tree can reach.


Step 5 — Pigeonhole forces a variable to repeat

Because (Step 4), the tree's height is , so its tallest path passes through at least variable circles. But only different names exist. Pigeonhole ⇒ two circles on that path wear the same name .

WHAT we did: located a variable appearing twice on one vertical path. WHY this is the whole game: a variable that reappears below itself is a loop in disguise — the grammar re-entered the same state, so whatever it did once it can do again.

Figure — Pumping lemma for CFLs

PICTURE: a tall path highlighted; the two circles labelled (both lavender, glowing) are the repeated pigeon. We always pick the two lowest such 's — remember that choice, it pays off in Step 7.


Step 6 — Naming the five pieces

Now cut the string using those two 's.

Reading the tree:

  • The upper eventually produces the middle chunk . Everything to its left is ; to its right is .
  • Inside that, the lower produces just .
  • The material the upper grew that the lower one did not — that is (on the left branch) and (on the right branch).

WHAT we did: turned "a repeated variable" into five concrete substrings. WHY two extra pieces and (unlike the single piece in the regular lemma)? Because a CNF split branches both left and right. The lower hangs off one side; the other side's leaves become or . Branching in two directions is exactly why CFLs pump on two sides at once.

Figure — Pumping lemma for CFLs

PICTURE: the same tall tree, now colour-blocked: and in slate at the far edges, and in coral hugging the middle, in mint at the bottom under the lower .


Step 7 — Why the loop pumps (repeat the subtree)

Plugging back through the top :

WHAT we did: replaced the lower 's subtree with a copy of the upper 's subtree, as many times as we like. Setting instead deletes the loop (use the lower subtree directly). WHY it stays in : every splice uses only legal rules that were already in the grammar — we are just re-running an allowed derivation.

Figure — Pumping lemma for CFLs

PICTURE: three panels. (loop cut out, just ), (original, ), (loop nested twice, ). Watch pile up on the left and on the right, symmetrically.


Step 8 — Why the two guarantee-conditions hold

WHAT we did: proved the two "small print" promises of the lemma. WHY "lowest pair" mattered: any repeat would give a loop, but only the lowest repeat keeps the middle window short enough to satisfy — that is the entire reason we specified "lowest" back in Step 5.

Figure — Pumping lemma for CFLs

PICTURE: left — the strictly-bigger upper subtree with the extra leaves circled (proves ). Right — the "lowest pair" keeping the middle subtree short and squat (proves ).


Step 9 — The degenerate cases (never leave a gap)

  • Short strings (): the lemma says nothing and promises nothing. No tall tree is forced, no repeat, no split. That's fine — the lemma only speaks about .
  • but (the left growth is empty, right growth isn't): still legal, since Condition 1 only needs , not both nonempty. Pumping then piles up only on the right. The mirror case (, ) piles up only on the left.
  • (lower produces nothing between the pumps): allowed; and then sit adjacent. The loop still works.
  • or (the repeat sits at the very edge): allowed; nothing outside the middle window, but pumping is unaffected.

WHAT we did: confirmed the derivation survives every empty-piece scenario. WHY it matters for using the lemma: when you run the adversary game, the adversary may hand you any of these; your chosen must break membership for all of them (see the parent note's proof).

Figure — Pumping lemma for CFLs

PICTURE: four mini-trees, one per degenerate case, each still showing a valid loop. Nothing breaks.


The one-picture summary

Figure — Pumping lemma for CFLs

This single figure compresses the whole chain: long stringtall binary treepigeonhole repeat of split pump the loop.

Recall Feynman retelling — say it back in plain words

Imagine every valid string is drawn as a family tree of splitting circles, and every circle always has two kids. A short tree can only ever spell out a short string — its bottom row runs out of room. So the moment your string is long enough (longer than leaves, where is how many circle-names you own), the tree is forced to grow tall. Tall means some vertical path visits more circles than you have names, so — pigeonhole — one name shows up twice on that path. That double-visit is a loop: the grammar came back to the same circle, so it can run that stretch again and again. Running it grows letters on the left () and right () at the same time, with an untouched core in the middle and fixed ends and . That's the whole . Because the loop is legal, you can repeat it any number of times (or zero) and still land in the language. To prove a language is not context-free, you flip it around: find one long string where no loop can survive being repeated, and the whole story collapses into a contradiction.

One line ::: Long string forces a tall binary tree, pigeonhole repeats a variable, the repeat is a pumpable loop that grows and together.

Recall Quick self-check

Why must there be two pumped pieces, not one? ::: A CNF split branches both left and right, so the loop grows material on both sides — on the left, on the right. Why and not ? ::: The makes imply the strict , which forces height so a variable must repeat. Which choice guarantees ? ::: Picking the two lowest repeated occurrences of , keeping the middle subtree short.

See also: Pushdown Automata, Closure properties of CFLs.