L33-Pumping Lemma For CFL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

L33- ToC

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:
SAC|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 k0
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 zL(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

 Some a’s and some b’s

 Some b’s and some c’s


1. |vwx|  k
Example (1) Contd… 2. vx  
 vwx consists of all a’s
 If z = a2b2c2 and u=, v=a, w=, x=a, y=b2c2, then
uv2wx2y will be a4b2c2 L
 vwx consists of some a’s and some b’s
 If z = a2b2c2 and u=a, v=a, w=, x=b, y=bc2, then
uv2wx2y will be a3b3c2 L
 vwx consists of some b’s and some c’s
 If z = a2b2c2 and u=a2b,v=b, w=c, x= ,y=c, then
uv2wx2y will be a2b3c2 L
Example (1) Contd…
 uv2wx2y not having equal number of a’s b’s
and c’s.
 Pumping Lemma says uv2wx2y L
 Can’t contradict the pumping lemma!
 Our original assumption must be wrong
 L is not context-free.
Example (2)
 Show that L = {ww |w {0, 1}* } is not CFL
 Assume L is CFL.
 Sufficient to show that L1= {0m1n0m1n | m, n  0},
where n is pumping lemma constant, is CFL
 Pick z = 0n1n0n1n =uvwxy, |vwx|n and vx
 Proof considers i = 0 for uviwxiy is in L.
 If |vwx|n, then |uwy| 3n. If uwy is some
repeating string tt, then |t| 3n/2
Example (2) Contd…
1. Suppose vwx is within first n 0’s. Let vx
consists of k 0’s. Then uwy begins with 0n-
k1n

 Example: z=03130313, vx = 02 then


uwy=tt1=0130313, so t=0130 and t1=0213 they
are not same.
 |uwy| = 4n-k. If uwy is some repeating string
tt, then |t| =2n-k/2. t does end in 0, but tt ends
with 1. So second t is not a repetition of first
t.
Example (2) Contd…
2. vwx consists of 1st block of 0’s and 1st block
of 1’s. vx consists of only 0’s if x= , then
uwy is not in the form tt. If vx has at least
one 1, then |t| is at least 3n/2 and first t ends
with a 0, not a 1.
3. If vwx consists of first block of 1’s
4. If vwx consists of 1st block of 1’s and 2nd
block of 0’s.
 In all cases uwy is not in the form of tt. So
uwy is not in L. so L is not context free.
Polling
 Is L={0i1j2i3j | i 1, j1} CFL?
A. Yes

B. No

19
20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy