SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Pushdown Automata (PDA)( )
Reading: Chapter 6
1
PDA - the automata for CFLs
 What is?
 FA to Reg Lang PDA is to CFL FA to Reg Lang, PDA is to CFL
 PDA == [  -NFA + “a stack” ]
Wh t k? Why a stack?
-NFAInput
string
Accept/reject
2
A stack filled with “stack symbols”
Pushdown Automata -
Definition
 A PDA P := ( Q,∑,, δ,q0,Z0,F ):
 Q: states of the -NFA
 ∑: input alphabet
  : stack symbols
 δ: transition function
 q0: start state
Z Initial stack top s mbol Z0: Initial stack top symbol
 F: Final/accepting states
3
old state Stack topinput symb. new state(s)new Stack top(s)
δ : Q x ∑ x  => Q x 
δ : The Transition Function
δ(q,a,X) = {(p,Y), …}
1. state transition from q to p
2. a is the next input symbol
X is the current stack top symbol q
a X
p
Y
3. X is the current stack top symbol
4. Y is the replacement for X;
it is in * (a string of stack
symbols)
Set Y = for: Pop(X)
q p
Y = ? Action
i) Y= Pop(X)i. Set Y =  for: Pop(X)
ii. If Y=X: stack top is
unchanged
iii. If Y=Z1Z2…Zk: X is popped
and is replaced by Y in
i) Y= Pop(X)
ii) Y=X Pop(X)
Push(X)
iii) Y=Z1Z2 Zk Pop(X)and is replaced by Y in
reverse order (i.e., Z1 will be
the new stack top)
iii) Y Z1Z2..Zk Pop(X)
Push(Zk)
Push(Zk-1)
…
Push(Z2)
4
Push(Z2)
Push(Z1)
Example
Let Lwwr = {wwR | w is in (0+1)*}
 CFG for Lwwr : S==> 0S0 | 1S1 | 
 PDA for Lwwr :
 P := ( Q,∑, , δ,q0,Z0,F )
= ( {q0, q1, q2},{0,1},{0,1,Z0},δ,q0,Z0,{q2})
5
Initial state of the PDA:
qSt k
PDA for Lwwr
Z0
q0Stack
top
1. δ(q0,0, Z0)={(q0,0Z0)}
2. δ(q0,1, Z0)={(q0,1Z0)}
δ(q 0 0) {(q 00)}
First symbol push on stack
3. δ(q0,0, 0)={(q0,00)}
4. δ(q0,0, 1)={(q0,01)}
5. δ(q0,1, 0)={(q0,10)}
6. δ(q0,1, 1)={(q0,11)}
Grow the stack by pushing
new symbols on top of old
( t)
7. δ(q0, , 0)={(q1, 0)}
8. δ(q0, , 1)={(q1, 1)}
9 δ(q0  Z0)={(q1 Z0)}
(w-part)
Switch to popping mode, nondeterministically
(boundary between w and wR)9. δ(q0, , Z0) {(q1, Z0)}
10. δ(q1,0, 0)={(q1, )}
11. δ(q1,1, 1)={(q1, )}
(boundary between w and w )
Shrink the stack by popping matching
symbols (wR-part)
6
12. δ(q1, , Z0)={(q2, Z0)}
y ( p )
Enter acceptance state
PDA as a state diagram
δ(qi,a, X)={(qj,Y)}
Next
input
Current
stack
Stack
Topinput
symbolCurrent
state
stack
top
Top
Replacement
(w/ string Y)
qi qj
a, X / Y Next
state
7
PDA for Lwwr: Transition Diagram
0, Z0/0Z0
1, Z0/1Z0
Grow stack
Pop stack for
∑ = {0, 1}
= {Z0, 0, 1}
Q = {q q q }1, Z0/1Z0
0, 0/00
0, 1/01
1, 0/10
1, 1/11
0, 0/ 
1, 1/ 
Pop stack for
matching symbols
Q = {q0,q1,q2}
q0 q1 q2
, Z0/Z0
, 0/0
, Z0/Z0
G
, Z0/Z0
, 1/1
Switch to
popping mode
Go to acceptance
8This would be a non-deterministic PDA
Example 2: language ofp g g
balanced paranthesis
Grow stack
Pop stack for
matching symbols
∑ = { (, ) }
= {Z0, ( }
Q = {q q q }
(, Z0 / ( Z0
Q = {q0,q1,q2}
(, ( / ( ( ), ( / 
q0 q1 q2
Z / Z
, Z0 / Z0
G (b fi l )
), ( / , Z0 / Z0
, Z0 / Z0
Switch to
popping mode
Go to acceptance (by final state)
when you see the stack bottom symbo
(, ( / ( (
(, Z0 / ( Z0
9
To allow adjacent
blocks of nested paranthesis
(, 0 ( 0
Example 2: language of balancedExample 2: language of balanced
paranthesis (another design)
∑ = { (, ) }
= {Z0, ( }
Q = {q q }
(,Z0 / ( Z0
(,( / ( (
Q = {q0,q1}
q
(,( ( (
), ( / 
start
q
,Z0/ Z0
q0 q1
,Z0/ Z0
10
PDA’s Instantaneous
Description (ID)
A PDA has a configuration at any given instance:
(q,w,y)
 q current state q - current state
 w - remainder of the input (i.e., unconsumed part)
 y - current stack contents as a string from top to bottom
f t kof stack
If δ(q,a, X)={(p, A)} is a transition, then the following are also true:
 (q, a, X ) |--- (p,,A)
( ) | ( ) (q, aw, XB ) |--- (p,w,AB)
|--- sign is called a “turnstile notation” and represents
one move
11
|---* sign represents a sequence of moves
How does the PDA for Lwwrwwr
work on input “1111”?
(q0,1111,Z0)
All moves made by the non-deterministic PDA
(q0,111,1Z0)
(q 11 11Z ) (q 111 1Z )
(q1,1111,Z0) Path dies…
Path dies(q0,11,11Z0)
(q0,1,111Z0) (q1,11,11Z0)
(q1,111,1Z0) Path dies…
(q0,,1111Z0)
( 1111Z ) (q  11Z )
(q1,1,111Z0) (q1,1,1Z0)
(q  Z )
Acceptance by
final state:
t i t
12
(q1, ,1111Z0) (q1, ,11Z0) (q1, ,Z0)
(q2, ,Z0)
= empty input
AND
final state
Path dies…Path dies…
Principles about IDs
 Theorem 1: If for a PDA,
(q, x, A) |---* (p, y, B), then for any string
∑* d * it i l t th tw  ∑* and   *, it is also true that:
 (q, x w, A ) |---* (p, y w, B )
 Theorem 2: If for a PDA,
(q, x w, A) |---* (p, y w, B), then it is also true(q, , ) | (p, y , ),
that:
 (q, x, A) |---* (p, y, B)
13
There are two types of PDAs that one can design:
those that accept by final state or by empty stack
Acceptance by…
 PDAs that accept by final state:
 For a PDA P, the language accepted by P,
d t d b L(P) b fi l t t idenoted by L(P) by final state, is:
 {w | (q0,w,Z0) |---* (q,, A) }, s.t., q  F
Checklist:
- input exhausted?
- in a final state?
 PDAs that accept by empty stack:
 For a PDA P, the language accepted by P,
denoted by N(P) by empty stack, is:
 {w | (q0,w,Z0) |---* (q, , ) }, for any q  Q.
14
{ | (q0, , 0) | (q, , ) }, y q Q
Checklist:
- input exhausted?
- is the stack empty?
Q) Does a PDA that accepts by empty stack
need any final state specified in the design?
Example: L of balancedp
parenthesis
PDA that accepts by final state
( Z / ( Z
An equivalent PDA that
accepts by empty stack
(,Z0 / ( Z0
(,( / ( (
), ( / 
(,Z0 / ( Z0
(, ( / ( (
), ( / 
,Z0 / 
PF: PN:
q0
), ( / 
start
q1
,Z0/ Z0
 Z0/ Z0
q0
start
 Z / Z,Z0/ Z0 ,Z0/ Z0
15
How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( )
PDA for Lwwr: Proof ofwwr
correctness
 Theorem: The PDA for Lwwr accepts a string x
by final state if and only if x is of the form
RwwR.
 Proof:
 (if part) If the string is of the form wwR then there (if-part) If the string is of the form wwR then there
exists a sequence of IDs that leads to a final state:
(q0,wwR,Z0) |---* (q0,wR,wZ0) |---* (q1,wR,wZ0) |---*
(q  Z ) | * (q  Z )(q1, ,Z0) |--- (q2, ,Z0)
 (only-if part)
16
 Proof by induction on |x|
PDAs accepting by final state and emptyPDAs accepting by final state and empty
stack are equivalent
 PF <= PDA accepting by final state
 PF = (QF,∑, , δF,q0,Z0,F)
 PN <= PDA accepting by empty stack
 PN = (QN,∑, , δN,q0,Z0)
Th Theorem:
 (PN==> PF) For every PN, there exists a PF s.t. L(PF)=L(PN)
 (PF==> PN) For every PF, there exists a PN s.t. L(PF)=L(PN)
17
How to convert an empty stack PDA into a final state PDA?
PN==> PF construction
 Whenever PN’s stack becomes empty, make PF go to
a final state without consuming any addition symbol
 To detect empty stack in PN: PF pushes a new stack
symbol X0 (not in  of PN) initially before simultating
PNN
, X0/ X0PF: PN:
q0
… pfp0
, X0/Z0X0
New
start
, X0/ X0
, X0/ X0
, X0/ X0
PF: N
, X0 / X0
18
, X0/ X0
PNPF = (QN U {p0,pf}, ∑,  U {X0}, δF, p0, X0, {pf})
Example: Matching parenthesis “(” “)”
PN: ( {q0}, {(,)}, {Z0,Z1}, δN, q0, Z0 )
δN: δN(q0,(,Z0) = { (q0,Z1Z0) }
δ (q ( Z ) = { (q Z Z ) }
Pf: ( {p0,q0 ,pf}, {(,)}, {X0,Z0,Z1}, δf, p0, X0 , pf)
δf: δf(p0, ,X0) = { (q0,Z0) }
δ (q ( Z ) = { (q Z Z ) }δN(q0,(,Z1) = { (q0, Z1Z1) }
δN(q0,),Z1) = { (q0, ) }
δN(q0, ,Z0) = { (q0, ) }
δf(q0,(,Z0) = { (q0,Z1 Z0) }
δf(q0,(,Z1) = { (q0, Z1Z1) }
δf(q0,),Z1) = { (q0, ) }
δf(q0, ,Z0) = { (q0, ) }
δf(p0, ,X0) = { (pf, X0 ) }
(,Z0 /Z1Z0
(,Z1 /Z1Z1
),Z1 / 
,Z0 / 
(,Z0/Z1Z0
(,Z1/Z1Z1
),Z1/ 
 Z0/ 
q0
start
0
q0
 ,Z0/ 
start
p0 pf
,X0/Z0X0
,X0/ X0
19Accept by empty stack Accept by final state
How to convert an final state PDA into an empty stack PDA?
PF==> PN construction
 Main idea:
 Whenever PF reaches a final state, just make an  -transition into a
new end state, clear out the stack and acceptnew end state, clear out the stack and accept
 Danger: What if PF design is such that it clears the stack midway
without entering a final state?
 to address this, add a new start symbol X0 (not in  of PF), y 0 ( F)
PN = (Q U {p0,pe}, ∑,  U {X0}, δN, p0, X0)
PN:
p0
, X0/Z0X0
New
start
, any/ 
, any/ q0
… pe
, any/ 
PN:
20
, any/ 
PF
Equivalence of PDAs andEquivalence of PDAs and
CFGs
21
CFGs == PDAs ==> CFLs
PDA by
final state
PDA by
empty stack
≡
?
CFG
22
This is same as: “implementing a CFG using a PDA”
Converting CFG to PDA
Main idea: The PDA simulates the leftmost derivation on a given
w, and upon consuming it fully it either arrives at acceptance (by
empty stack) or non acceptanceempty stack) or non-acceptance.
PDA
(w
accept
UT
PUT
(acceptance
by empty
stack)
w
reject
INPU
OUTP
implements
23
CFG
This is same as: “implementing a CFG using a PDA”
Converting a CFG into a PDA
Main idea: The PDA simulates the leftmost derivation on a given w,
and upon consuming it fully it either arrives at acceptance (by
empty stack) or non-acceptance.p y ) p
Steps:
1. Push the right hand side of the production onto the stack,
with leftmost symbol at the stack topwith leftmost symbol at the stack top
2. If stack top is the leftmost variable, then replace it by all its
productions (each possible substitution will represent a
distinct path taken by the non deterministic PDA)distinct path taken by the non-deterministic PDA)
3. If stack top has a terminal symbol, and if it matches with the
next symbol in the input string, then pop it
S i i i l ( l i d d)
24
State is inconsequential (only one state is needed)
Formal construction of PDA
from CFG Note: Initial stack symbol (S)
same as the start variable
i th
 Given: G= (V,T,P,S)
 Output: P = ({q} T V U T δ q S)
in the grammar
 Output: PN = ({q}, T, V U T, δ, q, S)
 δ:
F ll A V dd th f ll i
Before: After:
 For all A  V , add the following
transition(s) in the PDA:
δ(q  A) = { (q ) | “A ==>”  P}
A
Before:
…

After:
…
 δ(q,  ,A) = { (q, ) | A ==>  P}
 For all a  T, add the following
transition(s) in the PDA:a
Before:
After: a…
25
transition(s) in the PDA:
 δ(q,a,a)= { (q,  ) }
a
…
a
…
pop
Example: CFG to PDA
 G = ( {S,A}, {0,1}, P, S)
 P:
1,1 / 
0,0 / 
,A/ 01
,A/ A1
,A/ 0A1
 S / 
 S ==> AS | 
 A ==> 0A1 | A1 | 01
PDA ({ } {0 1} {0 1 A S} δ S)
q
,S / S
,S / 
,S / AS
 PDA = ({q}, {0,1}, {0,1,A,S}, δ, q, S)
 δ:
 δ(q  S) = { (q AS) (q  )} δ(q,  , S) = { (q, AS), (q,  )}
 δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }
 δ(q, 0, 0) = { (q,  ) }
26
 δ(q, 1, 1) = { (q,  ) } How will this new PDA work?
Lets simulate string 0011
Simulating string 0011 on theg g
new PDA …
1 1 / 
Leftmost deriv.:
PDA (δ):
δ(q,  , S) = { (q, AS), (q,  )}
δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }
1,1 / 
0,0 / 
,A/ 01
,A/ A1
,A/ 0A1
,S / 
S => AS
=> 0A1S
=> 0011S
δ(q, 0, 0) = { (q,  ) }
δ(q, 1, 1) = { (q,  ) }
Stack moves (shows only the successful path): q
,S / S
,
,S / AS
0011S
=> 0011
A
0
A 1
0
1
S S
A
S
1
S
1
0
S
1
S
1
0
S
1
1
S
1 
Accept by
empty stack
27
S =>AS =>0A1S =>0011S => 0011
Proof of correctness for CFG ==> PDAProof of correctness for CFG ==> PDA
construction
 Claim: A string is accepted by G iff it is
accepted (by empty stack) by the PDA
 Proof:
 (only-if part)
 Prove by induction on the number of derivation steps Prove by induction on the number of derivation steps
 (if part)
If ( S) | * ( B) th S * B If (q, wx, S) |--* (q,x,B) then S =>*
lm wB
28
Converting a PDA into a CFG
 Main idea: Reverse engineer the
productions from transitions
If δ(q,a,Z) => (p, Y1Y2Y3…Yk):
1. State is changed from q to p;
2. Terminal a is consumed;
3. Stack top symbol Z is popped and replaced with a
sequence of k variables.
 Action: Create a grammar variable calledg
“[qZp]” which includes the following
production:
 [qZp] => a[pY q ] [q Y q ] [q Y q ] [q Y q ]
29
 [qZp] => a[pY1q1] [q1Y2q2] [q2Y3q3]… [qk-1Ykqk]
 Proof discussion (in the book)
Example: Bracket matching
 To avoid confusion, we will use b=“(“ and e=“)”
PN: ( {q0}, {b,e}, {Z0,Z1}, δ, q0, Z0 )
0. S => [q0Z0q0]
1 [q Z q ] => b [q Z q ] [q Z q ]1. δ(q0,b,Z0) = { (q0,Z1Z0) }
2. δ(q0,b,Z1) = { (q0,Z1Z1) }
3. δ(q0,e,Z1) = { (q0,  ) }
4. δ(q0,  ,Z0) = { (q0,  ) }
1. [q0Z0q0] => b [q0Z1q0] [q0Z0q0]
2. [q0Z1q0] => b [q0Z1q0] [q0Z1q0]
3. [q0Z1q0] => e
4. [q0Z0q0] => 
(q0, , 0) { (q0, ) }
Let A=[q0Z0q0]
Let B=[q0Z1q0]
0. S => A
Simplifying,
0. S => b B S | 
1. B => b B B | e
If you were to directly write a CFG:
1. A => b B A
2. B => b B B
3. B => e
4. A => 
1. B b B B | e
S => b S e S | 
30
Two ways to build a CFG
Build a PDA Construct
CFG from PDA
(indirect)
Derive CFG directly (direct)
Derive a CFG Construct
PDA f CFG
Similarly…
(indirect)
Two ways to build a PDA
PDA from CFG
Design a PDA directly
(indirect)
(direct)
31
Design a PDA directly (direct)
Deterministic PDAs
32
This PDA for Lwwr is non-deterministic
0, Z0/0Z0
1, Z0/1Z0
Grow stack
Pop stack for
Why does it have
to be non-1, Z0/1Z0
0, 0/00
0, 1/01
1, 0/10
1, 1/11
0, 0/ 
1, 1/ 
Pop stack for
matching symbols deterministic?
q0 q1 q2
,
, Z0/Z0
, 0/0
1/1
, Z0/Z0
A b fi l, 1/1
Switch to
popping mode
Accepts by final state
To remove
guessing,
33
impose the user
to insert c in the
middle
D-PDA for L = {wcwR | c is some
Example shows that: Nondeterministic PDAs ≠ D-PDAs
D PDA for Lwcwr {wcw | c is some
special symbol not in w}
Note:
0, Z0/0Z0
1, Z0/1Z0
Grow stack
Pop stack for
matching symbols
Note:
• all transitions have
become deterministic
1, Z0/1Z0
0, 0/00
0, 1/01
1, 0/10
1, 1/11
0, 0/ 
1, 1/ 
matching symbols
q0 q1 q2
c, Z0/Z0
c, 0/0
1/1
, Z0/Z0
A bc, 1/1
Switch to
popping mode
Accepts by
final state
34
Deterministic PDA: Definition
 A PDA is deterministic if and only if:
1 δ(q a X) has at most one member for any1. δ(q,a,X) has at most one member for any
a  ∑ U {}
 If δ(q,a,X) is non-empty for some a∑,
then δ(q  X) must be emptythen δ(q, ,X) must be empty.
35
PDA vs DPDA vs Regularg
languages
Lwwr
Lwcwr
Regular languages D-PDA
non-deterministic PDA
36
Summary
 PDAs for CFLs and CFGs
 Non-deterministic
 Deterministic
 PDA acceptance types
By final state1. By final state
2. By empty stack
 PDA PDA
 IDs, Transition diagram
 Equivalence of CFG and PDA
37
 CFG => PDA construction
 PDA => CFG construction

Contenu connexe

Tendances

Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)Naman Joshi
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite AutomataArchana Gopinath
 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular setsSampath Kumar S
 
LINEAR BOUNDED AUTOMATA (LBA).pptx
LINEAR BOUNDED AUTOMATA (LBA).pptxLINEAR BOUNDED AUTOMATA (LBA).pptx
LINEAR BOUNDED AUTOMATA (LBA).pptxAkhilJoseph63
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automatahafizhamza0322
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of AutomataFarooq Mian
 
context free language
context free languagecontext free language
context free languagekhush_boo31
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automatadeepinderbedi
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 

Tendances (20)

Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
 
Push down automata
Push down automataPush down automata
Push down automata
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
Turing machines
Turing machinesTuring machines
Turing machines
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
LINEAR BOUNDED AUTOMATA (LBA).pptx
LINEAR BOUNDED AUTOMATA (LBA).pptxLINEAR BOUNDED AUTOMATA (LBA).pptx
LINEAR BOUNDED AUTOMATA (LBA).pptx
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automata
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
context free language
context free languagecontext free language
context free language
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 

En vedette

Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)dhea zafarina
 
Class8
 Class8 Class8
Class8issbp
 
PUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINEPUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINEAbhishek Shivhare
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaPhttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaHafeez Rehman
 
Brno Perl Mongers 28.5.2015 - Perl family by mj41
Brno Perl Mongers 28.5.2015 - Perl family by mj41Brno Perl Mongers 28.5.2015 - Perl family by mj41
Brno Perl Mongers 28.5.2015 - Perl family by mj41Michal Jurosz
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7Bianca Teşilă
 
Regular expressions and languages pdf
Regular expressions and languages pdfRegular expressions and languages pdf
Regular expressions and languages pdfDilouar Hossain
 
Advanced Regular Expressions Redux
Advanced Regular Expressions ReduxAdvanced Regular Expressions Redux
Advanced Regular Expressions ReduxJakub Nesetril
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiIbrahim Alfayoumi
 
Pumping lemma for regular language
Pumping lemma for regular languagePumping lemma for regular language
Pumping lemma for regular languagesadique_ghitm
 
0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programmingMaher Alshammari
 

En vedette (20)

Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Pushdown autometa
Pushdown autometaPushdown autometa
Pushdown autometa
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Class8
 Class8 Class8
Class8
 
PUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINEPUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINE
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Patent ductus arteriosus
Patent ductus arteriosusPatent ductus arteriosus
Patent ductus arteriosus
 
Pda
PdaPda
Pda
 
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaPhttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
 
Brno Perl Mongers 28.5.2015 - Perl family by mj41
Brno Perl Mongers 28.5.2015 - Perl family by mj41Brno Perl Mongers 28.5.2015 - Perl family by mj41
Brno Perl Mongers 28.5.2015 - Perl family by mj41
 
Normalization
NormalizationNormalization
Normalization
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7
 
Regular expressions and languages pdf
Regular expressions and languages pdfRegular expressions and languages pdf
Regular expressions and languages pdf
 
Advanced Regular Expressions Redux
Advanced Regular Expressions ReduxAdvanced Regular Expressions Redux
Advanced Regular Expressions Redux
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
 
Normalization
NormalizationNormalization
Normalization
 
Pumping lemma for regular language
Pumping lemma for regular languagePumping lemma for regular language
Pumping lemma for regular language
 
0 1 knapsack problem
0 1 knapsack problem0 1 knapsack problem
0 1 knapsack problem
 
0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming
 

Similaire à Pda

Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Akila Krishnamoorthy
 
Theory of automata
Theory of automataTheory of automata
Theory of automataArslan905905
 
Pushdown Automaton (1).ppt
Pushdown Automaton (1).pptPushdown Automaton (1).ppt
Pushdown Automaton (1).pptviswanath kani
 
Materi 3 Finite State Automata
Materi 3   Finite State AutomataMateri 3   Finite State Automata
Materi 3 Finite State Automataahmad haidaroh
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguagesissbp
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introductionNAMRATA BORKAR
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).pptssuser47f7f2
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.pptRohitPaul71
 
Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Abhimanyu Mishra
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsRushabh2428
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxamara jyothi
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxranjan317165
 
Deterministic finite automata
Deterministic finite automata Deterministic finite automata
Deterministic finite automata Muhammad Love Kian
 

Similaire à Pda (20)

PDA (1) (1).pptx
PDA (1) (1).pptxPDA (1) (1).pptx
PDA (1) (1).pptx
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Theory of automata
Theory of automataTheory of automata
Theory of automata
 
Dfa
DfaDfa
Dfa
 
Pushdown Automaton (1).ppt
Pushdown Automaton (1).pptPushdown Automaton (1).ppt
Pushdown Automaton (1).ppt
 
Materi 3 Finite State Automata
Materi 3   Finite State AutomataMateri 3   Finite State Automata
Materi 3 Finite State Automata
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introduction
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).ppt
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.ppt
 
Finite automata
Finite automataFinite automata
Finite automata
 
Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1
 
Pda
PdaPda
Pda
 
Fsa
FsaFsa
Fsa
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Teori automata lengkap
Teori automata lengkapTeori automata lengkap
Teori automata lengkap
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
Deterministic finite automata
Deterministic finite automata Deterministic finite automata
Deterministic finite automata
 

Dernier

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 

Dernier (20)

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 

Pda

  • 1. Pushdown Automata (PDA)( ) Reading: Chapter 6 1
  • 2. PDA - the automata for CFLs  What is?  FA to Reg Lang PDA is to CFL FA to Reg Lang, PDA is to CFL  PDA == [  -NFA + “a stack” ] Wh t k? Why a stack? -NFAInput string Accept/reject 2 A stack filled with “stack symbols”
  • 3. Pushdown Automata - Definition  A PDA P := ( Q,∑,, δ,q0,Z0,F ):  Q: states of the -NFA  ∑: input alphabet   : stack symbols  δ: transition function  q0: start state Z Initial stack top s mbol Z0: Initial stack top symbol  F: Final/accepting states 3
  • 4. old state Stack topinput symb. new state(s)new Stack top(s) δ : Q x ∑ x  => Q x  δ : The Transition Function δ(q,a,X) = {(p,Y), …} 1. state transition from q to p 2. a is the next input symbol X is the current stack top symbol q a X p Y 3. X is the current stack top symbol 4. Y is the replacement for X; it is in * (a string of stack symbols) Set Y = for: Pop(X) q p Y = ? Action i) Y= Pop(X)i. Set Y =  for: Pop(X) ii. If Y=X: stack top is unchanged iii. If Y=Z1Z2…Zk: X is popped and is replaced by Y in i) Y= Pop(X) ii) Y=X Pop(X) Push(X) iii) Y=Z1Z2 Zk Pop(X)and is replaced by Y in reverse order (i.e., Z1 will be the new stack top) iii) Y Z1Z2..Zk Pop(X) Push(Zk) Push(Zk-1) … Push(Z2) 4 Push(Z2) Push(Z1)
  • 5. Example Let Lwwr = {wwR | w is in (0+1)*}  CFG for Lwwr : S==> 0S0 | 1S1 |   PDA for Lwwr :  P := ( Q,∑, , δ,q0,Z0,F ) = ( {q0, q1, q2},{0,1},{0,1,Z0},δ,q0,Z0,{q2}) 5
  • 6. Initial state of the PDA: qSt k PDA for Lwwr Z0 q0Stack top 1. δ(q0,0, Z0)={(q0,0Z0)} 2. δ(q0,1, Z0)={(q0,1Z0)} δ(q 0 0) {(q 00)} First symbol push on stack 3. δ(q0,0, 0)={(q0,00)} 4. δ(q0,0, 1)={(q0,01)} 5. δ(q0,1, 0)={(q0,10)} 6. δ(q0,1, 1)={(q0,11)} Grow the stack by pushing new symbols on top of old ( t) 7. δ(q0, , 0)={(q1, 0)} 8. δ(q0, , 1)={(q1, 1)} 9 δ(q0  Z0)={(q1 Z0)} (w-part) Switch to popping mode, nondeterministically (boundary between w and wR)9. δ(q0, , Z0) {(q1, Z0)} 10. δ(q1,0, 0)={(q1, )} 11. δ(q1,1, 1)={(q1, )} (boundary between w and w ) Shrink the stack by popping matching symbols (wR-part) 6 12. δ(q1, , Z0)={(q2, Z0)} y ( p ) Enter acceptance state
  • 7. PDA as a state diagram δ(qi,a, X)={(qj,Y)} Next input Current stack Stack Topinput symbolCurrent state stack top Top Replacement (w/ string Y) qi qj a, X / Y Next state 7
  • 8. PDA for Lwwr: Transition Diagram 0, Z0/0Z0 1, Z0/1Z0 Grow stack Pop stack for ∑ = {0, 1} = {Z0, 0, 1} Q = {q q q }1, Z0/1Z0 0, 0/00 0, 1/01 1, 0/10 1, 1/11 0, 0/  1, 1/  Pop stack for matching symbols Q = {q0,q1,q2} q0 q1 q2 , Z0/Z0 , 0/0 , Z0/Z0 G , Z0/Z0 , 1/1 Switch to popping mode Go to acceptance 8This would be a non-deterministic PDA
  • 9. Example 2: language ofp g g balanced paranthesis Grow stack Pop stack for matching symbols ∑ = { (, ) } = {Z0, ( } Q = {q q q } (, Z0 / ( Z0 Q = {q0,q1,q2} (, ( / ( ( ), ( /  q0 q1 q2 Z / Z , Z0 / Z0 G (b fi l ) ), ( / , Z0 / Z0 , Z0 / Z0 Switch to popping mode Go to acceptance (by final state) when you see the stack bottom symbo (, ( / ( ( (, Z0 / ( Z0 9 To allow adjacent blocks of nested paranthesis (, 0 ( 0
  • 10. Example 2: language of balancedExample 2: language of balanced paranthesis (another design) ∑ = { (, ) } = {Z0, ( } Q = {q q } (,Z0 / ( Z0 (,( / ( ( Q = {q0,q1} q (,( ( ( ), ( /  start q ,Z0/ Z0 q0 q1 ,Z0/ Z0 10
  • 11. PDA’s Instantaneous Description (ID) A PDA has a configuration at any given instance: (q,w,y)  q current state q - current state  w - remainder of the input (i.e., unconsumed part)  y - current stack contents as a string from top to bottom f t kof stack If δ(q,a, X)={(p, A)} is a transition, then the following are also true:  (q, a, X ) |--- (p,,A) ( ) | ( ) (q, aw, XB ) |--- (p,w,AB) |--- sign is called a “turnstile notation” and represents one move 11 |---* sign represents a sequence of moves
  • 12. How does the PDA for Lwwrwwr work on input “1111”? (q0,1111,Z0) All moves made by the non-deterministic PDA (q0,111,1Z0) (q 11 11Z ) (q 111 1Z ) (q1,1111,Z0) Path dies… Path dies(q0,11,11Z0) (q0,1,111Z0) (q1,11,11Z0) (q1,111,1Z0) Path dies… (q0,,1111Z0) ( 1111Z ) (q  11Z ) (q1,1,111Z0) (q1,1,1Z0) (q  Z ) Acceptance by final state: t i t 12 (q1, ,1111Z0) (q1, ,11Z0) (q1, ,Z0) (q2, ,Z0) = empty input AND final state Path dies…Path dies…
  • 13. Principles about IDs  Theorem 1: If for a PDA, (q, x, A) |---* (p, y, B), then for any string ∑* d * it i l t th tw  ∑* and   *, it is also true that:  (q, x w, A ) |---* (p, y w, B )  Theorem 2: If for a PDA, (q, x w, A) |---* (p, y w, B), then it is also true(q, , ) | (p, y , ), that:  (q, x, A) |---* (p, y, B) 13
  • 14. There are two types of PDAs that one can design: those that accept by final state or by empty stack Acceptance by…  PDAs that accept by final state:  For a PDA P, the language accepted by P, d t d b L(P) b fi l t t idenoted by L(P) by final state, is:  {w | (q0,w,Z0) |---* (q,, A) }, s.t., q  F Checklist: - input exhausted? - in a final state?  PDAs that accept by empty stack:  For a PDA P, the language accepted by P, denoted by N(P) by empty stack, is:  {w | (q0,w,Z0) |---* (q, , ) }, for any q  Q. 14 { | (q0, , 0) | (q, , ) }, y q Q Checklist: - input exhausted? - is the stack empty? Q) Does a PDA that accepts by empty stack need any final state specified in the design?
  • 15. Example: L of balancedp parenthesis PDA that accepts by final state ( Z / ( Z An equivalent PDA that accepts by empty stack (,Z0 / ( Z0 (,( / ( ( ), ( /  (,Z0 / ( Z0 (, ( / ( ( ), ( /  ,Z0 /  PF: PN: q0 ), ( /  start q1 ,Z0/ Z0  Z0/ Z0 q0 start  Z / Z,Z0/ Z0 ,Z0/ Z0 15 How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( )
  • 16. PDA for Lwwr: Proof ofwwr correctness  Theorem: The PDA for Lwwr accepts a string x by final state if and only if x is of the form RwwR.  Proof:  (if part) If the string is of the form wwR then there (if-part) If the string is of the form wwR then there exists a sequence of IDs that leads to a final state: (q0,wwR,Z0) |---* (q0,wR,wZ0) |---* (q1,wR,wZ0) |---* (q  Z ) | * (q  Z )(q1, ,Z0) |--- (q2, ,Z0)  (only-if part) 16  Proof by induction on |x|
  • 17. PDAs accepting by final state and emptyPDAs accepting by final state and empty stack are equivalent  PF <= PDA accepting by final state  PF = (QF,∑, , δF,q0,Z0,F)  PN <= PDA accepting by empty stack  PN = (QN,∑, , δN,q0,Z0) Th Theorem:  (PN==> PF) For every PN, there exists a PF s.t. L(PF)=L(PN)  (PF==> PN) For every PF, there exists a PN s.t. L(PF)=L(PN) 17
  • 18. How to convert an empty stack PDA into a final state PDA? PN==> PF construction  Whenever PN’s stack becomes empty, make PF go to a final state without consuming any addition symbol  To detect empty stack in PN: PF pushes a new stack symbol X0 (not in  of PN) initially before simultating PNN , X0/ X0PF: PN: q0 … pfp0 , X0/Z0X0 New start , X0/ X0 , X0/ X0 , X0/ X0 PF: N , X0 / X0 18 , X0/ X0 PNPF = (QN U {p0,pf}, ∑,  U {X0}, δF, p0, X0, {pf})
  • 19. Example: Matching parenthesis “(” “)” PN: ( {q0}, {(,)}, {Z0,Z1}, δN, q0, Z0 ) δN: δN(q0,(,Z0) = { (q0,Z1Z0) } δ (q ( Z ) = { (q Z Z ) } Pf: ( {p0,q0 ,pf}, {(,)}, {X0,Z0,Z1}, δf, p0, X0 , pf) δf: δf(p0, ,X0) = { (q0,Z0) } δ (q ( Z ) = { (q Z Z ) }δN(q0,(,Z1) = { (q0, Z1Z1) } δN(q0,),Z1) = { (q0, ) } δN(q0, ,Z0) = { (q0, ) } δf(q0,(,Z0) = { (q0,Z1 Z0) } δf(q0,(,Z1) = { (q0, Z1Z1) } δf(q0,),Z1) = { (q0, ) } δf(q0, ,Z0) = { (q0, ) } δf(p0, ,X0) = { (pf, X0 ) } (,Z0 /Z1Z0 (,Z1 /Z1Z1 ),Z1 /  ,Z0 /  (,Z0/Z1Z0 (,Z1/Z1Z1 ),Z1/   Z0/  q0 start 0 q0  ,Z0/  start p0 pf ,X0/Z0X0 ,X0/ X0 19Accept by empty stack Accept by final state
  • 20. How to convert an final state PDA into an empty stack PDA? PF==> PN construction  Main idea:  Whenever PF reaches a final state, just make an  -transition into a new end state, clear out the stack and acceptnew end state, clear out the stack and accept  Danger: What if PF design is such that it clears the stack midway without entering a final state?  to address this, add a new start symbol X0 (not in  of PF), y 0 ( F) PN = (Q U {p0,pe}, ∑,  U {X0}, δN, p0, X0) PN: p0 , X0/Z0X0 New start , any/  , any/ q0 … pe , any/  PN: 20 , any/  PF
  • 21. Equivalence of PDAs andEquivalence of PDAs and CFGs 21
  • 22. CFGs == PDAs ==> CFLs PDA by final state PDA by empty stack ≡ ? CFG 22
  • 23. This is same as: “implementing a CFG using a PDA” Converting CFG to PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or non acceptanceempty stack) or non-acceptance. PDA (w accept UT PUT (acceptance by empty stack) w reject INPU OUTP implements 23 CFG
  • 24. This is same as: “implementing a CFG using a PDA” Converting a CFG into a PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or non-acceptance.p y ) p Steps: 1. Push the right hand side of the production onto the stack, with leftmost symbol at the stack topwith leftmost symbol at the stack top 2. If stack top is the leftmost variable, then replace it by all its productions (each possible substitution will represent a distinct path taken by the non deterministic PDA)distinct path taken by the non-deterministic PDA) 3. If stack top has a terminal symbol, and if it matches with the next symbol in the input string, then pop it S i i i l ( l i d d) 24 State is inconsequential (only one state is needed)
  • 25. Formal construction of PDA from CFG Note: Initial stack symbol (S) same as the start variable i th  Given: G= (V,T,P,S)  Output: P = ({q} T V U T δ q S) in the grammar  Output: PN = ({q}, T, V U T, δ, q, S)  δ: F ll A V dd th f ll i Before: After:  For all A  V , add the following transition(s) in the PDA: δ(q  A) = { (q ) | “A ==>”  P} A Before: …  After: …  δ(q,  ,A) = { (q, ) | A ==>  P}  For all a  T, add the following transition(s) in the PDA:a Before: After: a… 25 transition(s) in the PDA:  δ(q,a,a)= { (q,  ) } a … a … pop
  • 26. Example: CFG to PDA  G = ( {S,A}, {0,1}, P, S)  P: 1,1 /  0,0 /  ,A/ 01 ,A/ A1 ,A/ 0A1  S /   S ==> AS |   A ==> 0A1 | A1 | 01 PDA ({ } {0 1} {0 1 A S} δ S) q ,S / S ,S /  ,S / AS  PDA = ({q}, {0,1}, {0,1,A,S}, δ, q, S)  δ:  δ(q  S) = { (q AS) (q  )} δ(q,  , S) = { (q, AS), (q,  )}  δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }  δ(q, 0, 0) = { (q,  ) } 26  δ(q, 1, 1) = { (q,  ) } How will this new PDA work? Lets simulate string 0011
  • 27. Simulating string 0011 on theg g new PDA … 1 1 /  Leftmost deriv.: PDA (δ): δ(q,  , S) = { (q, AS), (q,  )} δ(q,  , A) = { (q,0A1), (q,A1), (q,01) } 1,1 /  0,0 /  ,A/ 01 ,A/ A1 ,A/ 0A1 ,S /  S => AS => 0A1S => 0011S δ(q, 0, 0) = { (q,  ) } δ(q, 1, 1) = { (q,  ) } Stack moves (shows only the successful path): q ,S / S , ,S / AS 0011S => 0011 A 0 A 1 0 1 S S A S 1 S 1 0 S 1 S 1 0 S 1 1 S 1  Accept by empty stack 27 S =>AS =>0A1S =>0011S => 0011
  • 28. Proof of correctness for CFG ==> PDAProof of correctness for CFG ==> PDA construction  Claim: A string is accepted by G iff it is accepted (by empty stack) by the PDA  Proof:  (only-if part)  Prove by induction on the number of derivation steps Prove by induction on the number of derivation steps  (if part) If ( S) | * ( B) th S * B If (q, wx, S) |--* (q,x,B) then S =>* lm wB 28
  • 29. Converting a PDA into a CFG  Main idea: Reverse engineer the productions from transitions If δ(q,a,Z) => (p, Y1Y2Y3…Yk): 1. State is changed from q to p; 2. Terminal a is consumed; 3. Stack top symbol Z is popped and replaced with a sequence of k variables.  Action: Create a grammar variable calledg “[qZp]” which includes the following production:  [qZp] => a[pY q ] [q Y q ] [q Y q ] [q Y q ] 29  [qZp] => a[pY1q1] [q1Y2q2] [q2Y3q3]… [qk-1Ykqk]  Proof discussion (in the book)
  • 30. Example: Bracket matching  To avoid confusion, we will use b=“(“ and e=“)” PN: ( {q0}, {b,e}, {Z0,Z1}, δ, q0, Z0 ) 0. S => [q0Z0q0] 1 [q Z q ] => b [q Z q ] [q Z q ]1. δ(q0,b,Z0) = { (q0,Z1Z0) } 2. δ(q0,b,Z1) = { (q0,Z1Z1) } 3. δ(q0,e,Z1) = { (q0,  ) } 4. δ(q0,  ,Z0) = { (q0,  ) } 1. [q0Z0q0] => b [q0Z1q0] [q0Z0q0] 2. [q0Z1q0] => b [q0Z1q0] [q0Z1q0] 3. [q0Z1q0] => e 4. [q0Z0q0] =>  (q0, , 0) { (q0, ) } Let A=[q0Z0q0] Let B=[q0Z1q0] 0. S => A Simplifying, 0. S => b B S |  1. B => b B B | e If you were to directly write a CFG: 1. A => b B A 2. B => b B B 3. B => e 4. A =>  1. B b B B | e S => b S e S |  30
  • 31. Two ways to build a CFG Build a PDA Construct CFG from PDA (indirect) Derive CFG directly (direct) Derive a CFG Construct PDA f CFG Similarly… (indirect) Two ways to build a PDA PDA from CFG Design a PDA directly (indirect) (direct) 31 Design a PDA directly (direct)
  • 33. This PDA for Lwwr is non-deterministic 0, Z0/0Z0 1, Z0/1Z0 Grow stack Pop stack for Why does it have to be non-1, Z0/1Z0 0, 0/00 0, 1/01 1, 0/10 1, 1/11 0, 0/  1, 1/  Pop stack for matching symbols deterministic? q0 q1 q2 , , Z0/Z0 , 0/0 1/1 , Z0/Z0 A b fi l, 1/1 Switch to popping mode Accepts by final state To remove guessing, 33 impose the user to insert c in the middle
  • 34. D-PDA for L = {wcwR | c is some Example shows that: Nondeterministic PDAs ≠ D-PDAs D PDA for Lwcwr {wcw | c is some special symbol not in w} Note: 0, Z0/0Z0 1, Z0/1Z0 Grow stack Pop stack for matching symbols Note: • all transitions have become deterministic 1, Z0/1Z0 0, 0/00 0, 1/01 1, 0/10 1, 1/11 0, 0/  1, 1/  matching symbols q0 q1 q2 c, Z0/Z0 c, 0/0 1/1 , Z0/Z0 A bc, 1/1 Switch to popping mode Accepts by final state 34
  • 35. Deterministic PDA: Definition  A PDA is deterministic if and only if: 1 δ(q a X) has at most one member for any1. δ(q,a,X) has at most one member for any a  ∑ U {}  If δ(q,a,X) is non-empty for some a∑, then δ(q  X) must be emptythen δ(q, ,X) must be empty. 35
  • 36. PDA vs DPDA vs Regularg languages Lwwr Lwcwr Regular languages D-PDA non-deterministic PDA 36
  • 37. Summary  PDAs for CFLs and CFGs  Non-deterministic  Deterministic  PDA acceptance types By final state1. By final state 2. By empty stack  PDA PDA  IDs, Transition diagram  Equivalence of CFG and PDA 37  CFG => PDA construction  PDA => CFG construction