L33-Pumping Lemma For CFL
L33-Pumping Lemma For CFL
L33-Pumping Lemma For CFL
Course Instructors:
Div 1: Praveen Pawar (Div 1)
Div 2: Jibi Abraham (Div 2)
1
Pumping Lemma for CFL
The pumping lemma for regular languages states
that every sufficiently long string in a regular
language contains a short substring that can be
pumped. That is, inserting as many copies of the
substring as we like always yields a string in the
regular language.
The pumping lemma for CFL’s states that there
are always two short sub-strings close together
that can be repeated, both the same number of
times, as often as we like.
Remember Parse Trees
CFL L={anbn | n 1}
Equivalent CNF grammar is having
productions:
SAC|AB, A a, B b, C SB
Parse tree for string a4b4
Both leftmost derivation and rightmost
derivation have same parse tree
(unambiguous)
Extended Parse Tree
Extend the tree by duplicating
the terminals generated at each
level on all lower levels
No. of symbols at each level is
at most twice of previous level
1 at level 0, 2 at 1, 4 at 2 …2i at
level i
A complete binary tree with n
levels has 2n−1 leaf nodes
To have 2n symbols at bottom
level, tree must be having level
of at least n+1
Pumping Lemma Theorem
Let L be a CFL. Then there exists a constant k0
such that if z is any string in L such that |z| k,
then we can write z=uvwxy such that
1. |vwx| k (that is, the middle portion is not too
long).
2. vx (since v and x are the pieces to be
“pumped”, at least one of the strings we pump
must not be empty).
3. For all i 0, uviwxiy is in L.
Pumping Lemma Proof
The parse tree for a grammar G in CNF will be a
binary tree
Let k=2n, n is number of variables of G
Suppose zL(G) and |z| k
Any parse tree for z must be of depth at least n
The longest path in the parse tree is at least n+1, so
must contain at least n+1 occurrences of the
variables.
Proof Contd…
By pigeonhole principle, some variables occur
more than once along the path.
Reading from bottom to top, consider the first
pair of same variable along the path.
Say X has 2 occurrences. Break z into uvwxy
such that w is the string of terminals generated
at the lower occurrence of X, vwx is the string
generated by upper occurrence of X.
Example parse tree
w = ab is the string
generated by lower
occurrence of S and vwx =
aabb is the string
generated by upper
occurrence of S
So u = aa, v = a, w = ab, x
= b, y = bb
Parse sub trees
Let T be the subtree rooted at upper
occurrence of S and t be subtree rooted at
lower occurrence of S
uv wx y
2 2 L
Repeat the cutting out of t
and replacing it with copy
of T as many times to get a
valid parse tree for uviwxiy
for i 1
uwy L
Cut T out of the original
tree and replace it with t
to get a parse tree of
uv0wx0y = uwy
Pumping Lemma game
To show that a language L is not a CFL,
assume L is context free
Choose an “appropriate” string z in L
Express z = uvwxy following rules of pumping
lemma
Show that uvkwxkz is not in L, for some k
The above contradicts the Pumping Lemma
Our assumption that L is context free is wrong
Example(1)
Show that L = { aibici | i 1 }is not CFL
Assume L is CFL. Choose an appropriate z =
anbncn = uvwxy.
Since |vwx| n then vwx must consists of
All a’s or all b’s or all c’s
B. No
19
20