Pumping Lemma
Problem: – Let B be the language of all palindromes over {0,1} containing an
equal number of 0s and 1s. Show that B is not CFL
Solution:– We assume that B is a CFL and obtain a contradiction.
– Let p be the pumping constant of B that is guaranteed to exist by the pumping lemma. Select the string s = 0p1p1p0p .
– Clearly s is a member of B and of length at least p . We can show that no matter how we divide s into uvxyz, one of the conditions of the lemma is violated.
• Pumping lemma, | vxy |<= p , we can only place vxy in the following ways:
1. vxy completely falls in the first 0p
– If we pump v and y , then the new string is no longer a palindrome, and the number of 0s will be greater than the number of 1s, which is a contradiction.
2. vxy falls between 0p and 1p
– In this case, v will only contain 0s while y will only contain 1s. So if we pump s , the new string is no longer palindrome, which is a contradiction.
3. vxy completely falls in the first 1p
– Similar to (1), after pumping s , the number of 1s will be greater than the number of 0s, which is a contradiction.
4. vxy falls between 1p and 1p
– After pumping s , the number of 1s will be greater than the number of 0s, which is a contradiction.
5. vxy completely falls in the second 1p
– This case is same with (3). 6. vxy falls between 1p and 0p
– Similar to (2), v will only contain 1s while y will only contain 0s. So if we pump s , the new string is no longer palindrome, which is a contradiction.
7. vxy completely falls in the second 0p– This case is same with (1).
Hence, B is not context free.
• Let L = {w {0; 1}* : w = wR}.
• (a) Show that L is context-free by giving a context-free grammar for L.
• (b) Show that L is context-free by giving a pushdown automaton for L.
• (c) Show that L is not regular.
CFG
• L is a symmetric language. Consider a context-free grammar for L : (V, Σ, R, S) , where
i. V = {S}
ii. Σ = {0,1}
iii. Rules:
S 0S0 |1S1| 0 |1|ε
iv. S = S V
PDA
Pumping Lemma
• Assume that L regular. Let p be the pumping constant given by the pumping lemma.
• Let s be the string 1p-1101p. • s can be split into three pieces, s = xyz , where for any i
>= 0 the string xyiz is in L .• According to the pumping lemma condition, we must
have | xy |<= p . If this is the case, then y must consist only of 1’s, so xyyz L . Therefore s cannot be pumped.
• This is a contradiction.
Pushdown Automaton -- PDAInput String
Stack
States
Initial Stack Symbol
Stack
$
Stack
z
bottomspecial symbol
stackhead
top
Appears at time 0
The States
q1 q2a, b c
Inputsymbol
Popsymbol
Pushsymbol
q1 q2a, b c
a
b top
input
stack
a
Replaceeh
$eh
$
c
q1 q2ca ,
a a
Pushb
eh
$eh
$
bc
top
input
stack
q1 q2ba,
a a
Popb
eh
$eh
$
top
input
stack
q1 q2 ,a
a a
No Changeb
eh
$eh
$
btop
input
stack
q1 q2$,a
a a
Pop$ top
input
stack
Empty Stack
empty
The automaton HALTS
No possible transition after q2
q1 q2ba $,
a a
Pop$ top
input
stack
A Possible Transition
b
Non-Determinism
q1
q2a, b c
q3a, b c
q1 q2cb,
transition
PDAs are non-deterministic
Allowed non-deterministic transitions
Example PDA
,
aa ,
ab,q0 q1 q2 q3
ab,
$$,
PDA M
}0:{)( nbaML nn
}0:{)( nbaML nn
Basic Idea:
1. Push the a’s
on the stack2. Match the b’s on input
with a’s on stack
3. Match
found
,
aa ,
ab,q0 q1 q2 q3
ab,
$$,
0q q1 q2 q3
Input
a a a b b b
Stack
$
aa , ab,
$$, , ab,
q0 q1 q2 q3
a a a b b b$
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b
$
a
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b$
aa
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b
$
aaa
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b
$
aaa
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b$
aa
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b$
a
$$, ,
aa ,
ab,
ab,
Input
Stack
q0 q1 q2 q3
a a a b b b
accept
$
$$, ,
aa ,
ab,
ab,
Input
Stack
• A string is accepted if there is a computation such that:– All the input is consumed– The last state is an accepting state
– At the end of the computation,– we do not care about the stack contents– (the stack can be empty at the last state)
}0:{ nbaL nn
is the language accepted by the PDA:
q0 q1 q2 q3 ,
aa ,
ab,
ab,
$$,
aab
,
aa ,
ab,q0 q1 q2 q3
ab,
$$,
0q q1 q2 q3
a a b$
,
aa ,
ab,
ab,
$$,
0q q1 q2 q3
a a b$
,
aa ,
ab,
ab,
$$,
0q q1 q2 q3
a a b$
a
,
aa ,
ab,
ab,
$$,
0q q1 q2 q3
a a b$
aa
,
aa ,
ab,
ab,
$$,
0q q1 q2 q3
a a b$
aa
,
aa ,
ab,
ab,
$$,
0q q1 q2 q3
a a b$
aa
reject
,
aa ,
ab,
ab,
$$,
Another PDA example
$$, q1 q2
bb
aa
,
,
,q0
bb
aa
,
,
}},{:{)( bavvvML R
}},{:{)( bavvvML R
1. Push v
on stack2. Guess
middle
of input
3. Match vR on input
with v on stack
4. Match
found
$$, q1 q2
,q0
bb
aa
,
,
bb
aa
,
,
$
q1 q2q0
a ab b
bb
aa
,
,
,
bb
aa
,
,
$$,
a ab
$
q1 q2q0
ab
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
aa ab b
b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
aa ab b
b
Guess the middle
of string
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
aa ab b
b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
1q q2q0
a ab b a
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1q0
a ab b
accept
q2
bb
aa
,
,
,
bb
aa
,
,
$$,
Rejection Example:
Input
$
q1 q2q0
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
aa b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
ab
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
ab
Guess the middle
of string
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
ab
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
1q q2q0
aa b b b
There is no possible transition.
Input is not consumed
bb
aa
,
,
,
bb
aa
,
,
$$,
Another computation on same string:
$
q1 q2q0
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
aa b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$
q1 q2q0
ab
a b b b
bb
aa
,
,
,
bb
aa
,
,
$$,
$ab
a b b b
q1 q2q0
b
bb
aa
,
,
,
bb
aa
,
,
$$,
a b b b
q1 q2q0
$abbb
bb
aa
,
,
,
bb
aa
,
,
$$,
a b b b
$abbb
q1 q2q0
final state
is not reached
bb
aa
,
,
,
bb
aa
,
,
$$,
q1 q2q0
)(MLabbb
bb
aa
,
,
,
bb
aa
,
,
$$,
Another PDA example
ab
aa
,
,
q0
M
)}()( ,prefix every in
:},{{)( *
vnvnv
bawML
ba
aababbb (r)
Pushing Strings
q1 q2a, b w
Input
symbol
Pop
symbolPush
string
q1 q2a, b cdf
a
b top
a
Push
eh h
e
cdf
pushed
string
Example:
$ $
Another PDA example
$$, q1 q2
a, $ 0$a, 0 00
1,a
b, $ 1$b, 1 11
0,b
)}()(:},{{)( * wnwnbawML ba
abbbaa
Top Related