0% found this document useful (0 votes)
27 views

PDA6

PDA is an automata that recognizes context-free languages by using a pushdown stack. A PDA has 7 components - a finite set of states, input alphabet, stack alphabet, transition function, start state, initial stack symbol, and set of final/accepting states. The transition function specifies how the PDA can change states and manipulate the stack based on the current state, stack symbol, and next input symbol. There are two types of PDA acceptance - by final state, where the input is accepted if the PDA reaches a final state with empty input, and by empty stack, where the input is accepted if the stack empties regardless of final state. A PDA that accepts by empty stack does

Uploaded by

Raghu Nayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

PDA6

PDA is an automata that recognizes context-free languages by using a pushdown stack. A PDA has 7 components - a finite set of states, input alphabet, stack alphabet, transition function, start state, initial stack symbol, and set of final/accepting states. The transition function specifies how the PDA can change states and manipulate the stack based on the current state, stack symbol, and next input symbol. There are two types of PDA acceptance - by final state, where the input is accepted if the PDA reaches a final state with empty input, and by empty stack, where the input is accepted if the stack empties regardless of final state. A PDA that accepts by empty stack does

Uploaded by

Raghu Nayak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Pushdown Automata (PDA)

Reading: Chapter 6

1
PDA - the automata for CFLs
◼ What is?
◼ FA to Reg Lang, PDA is to CFL
◼ PDA == [  -NFA + “a stack” ]
◼ Why a stack?

Input -NFA Accept/reject


string

A stack filled with “stack symbols”


2
Pushdown Automata -
Definition
◼ A PDA P := ( Q,∑,, δ,q0,Z0,F ): is a 7 tuple
◼ Q: is set of finite states
◼ ∑: input alphabet
◼ : stack symbols
◼ δ: transition function from Qx(∑U )x  to
finite sub set of Qx *
◼ q0: start state
◼ Z0: Initial stack top symbol
◼ F: Final/accepting states

3
old state Stack top input 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 a X Y
3. X is the current stack top q p
symbol
4. Y is the replacement for X; Y=? Action
it is in * (a string of stack
symbols) i) Y= Pop(X)
i. Set Y =  for: Pop(X)
ii) Y=X Pop(X)
ii. If Y=X: stack top is Push(X)
unchanged
iii. If Y=Z1Z2…Zk: X is popped iii) Y=Z1Z2..Zk Pop(X)
and is replaced by Y Push(Zk)
in reverse order (i.e., Z1 Push(Zk-1)
will be the new stack top) …
Push(Z2)
Push(Z1)

Give eg of what does each of the transactions represent-5.2278 4


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
PDA for Lwwr - Action of PDA being represented with a δ
notation
1. δ(q0,0, Z0)={(q0,0Z0)}
First symbol push on stack
2. δ(q0,1, Z0)={(q0,1Z0)}
Initial state of the PDA:
3. δ(q0,0, 0)={(q0,00)}
4. δ(q0,0, 1)={(q0,01)}
5. δ(q0,1, 0)={(q0,10)} Grow the stack by pushing
6. δ(q0,1, 1)={(q0,11)} new symbols on top of old Stack
(w-part) top Z0
7. δ(q0, , 0)={(q1, 0)}
8. δ(q0, , 1)={(q1, 1)} Switch to popping mode
9. δ(q0, , Z0)={(q1, Z0)} (boundary between w and wR)

10. δ(q1,0, 0)={(q1, )}


Shrink the stack by popping matching
11. δ(q1,1, 1)={(q1, )}
symbols (wR-part)
12. δ(q1, , Z0)={(q2, Z0)} Enter acceptance state
6
Acion of a PDA as a state diagram or Graphical representation

δ(qi,a, X)={(qj,Y)}

Next Current Stack


input stack Top
Current symbol top Replacement
state (w/ string Y)

a, X / Y Next
qi qj state

7
PDA for Lwwr: Transition Diagram

Grow stack ∑ = {0, 1}


0, Z0/0Z0 = {Z0, 0, 1}
1, Z0/1Z0 Pop stack for Q = {q0,q1,q2}
0, 0/00
0, 1/01
matching symbols
1, 0/10 0, 0/ 
1, 1/11 1, 1/ 

, Z0/Z0 q0 q1 q2
, Z0/Z0 , Z0/Z0
, 0/0
, 1/1 Go to acceptance
Switch to
popping mode

8
Example 2: language of
balanced paranthesis
Pop stack for ∑ = { (, ) }
matching symbols = {Z0, ( }
Grow stack
Q = {q0,q1,q2}
(, Z0 / ( Z0
(, ( / ( ( ), ( / 

q0 q1 q2
, Z0 / Z0 ), ( /  , Z0 / Z0
, Z0 / Z0 Go to acceptance (by final state)
Switch to when you see the stack bottom symbo
(, ( / ( (
popping mode
(, Z0 / ( Z0

To allow adjacent
blocks of nested paranthesis 9
Example 2: language of balanced
paranthesis (another design)
∑ = { (, ) }
(,Z0 / ( Z0 = {Z0, ( }
(,( / ( (
), ( / 
Q = {q0,q1}

start ,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
◼ w - remainder of the input (i.e., unconsumed part)
◼ y - current stack contents as a string from top to bottom of stack
Eg: Let the current configuration of PDA be δ(q,aw, Z).
It means - q is the current state, aw is the string to be processed and
Z is the current content of the stack
If the transition is defined by δ(q,a, Z)=(p,) then the new configuration will
be (p,w,  )
The move from the current config to next config is given by
(q,aw, Z)|- (p,w,  )
This can be read as “configuration (q,aw, Z) derives (p,w,  )
|--- sign is called a “turnstyle notation” and represents one move
|---* sign represents a sequence of moves

11
How does the PDA for Lwwr
work on input “1111”?
All moves made by the non-deterministic PDA
(q0,1111,Z0)

(q1,1111,Z0) Path dies…


(q0,111,1Z0)

(q0,11,11Z0) (q1,111,1Z0) Path dies…

(q0,1,111Z0) (q1,11,11Z0)
Acceptance by
(q1,1,1Z0) final state:
(q0,,1111Z0) (q1,1,111Z0)
= empty input
(q1, ,1111Z0) (q1, ,11Z0) (q1, ,Z0) AND
final state
Path dies… Path dies…
(q2, ,Z0)
12
There are two types of PDAs that one can design:
those that accept by final state or by empty stack

Acceptance of a language by PDA

◼ PDAs that accept by final state:


◼ For a PDA P, the language accepted by P,
denoted by L(P) by final state, is: Checklist:
◼ {w | (q0,w,Z0) |---* (q,, A) }, s.t., q  F - input exhausted?
- in a final state?
(Contents of stack is irrelevant)
◼ PDAs that accept by empty stack:
◼ For a PDA P, the language accepted by P,
denoted by N(P) by empty stack, is: Checklist:
◼ {w | (q0,w,Z0) |---* (q, , ) }, for any q  Q. - input exhausted?
- is the stack empty?

Q) Does a PDA that accepts by empty stack


need any final state specified in the design? 13
Example: L of balanced
parenthesis
An equivalent PDA that
PDA that accepts by final state accepts by empty stack
(,Z0 / ( Z0
PF: (,Z0 / ( Z0
PN: (, ( / ( (
), ( / 
(,( / ( ( ,Z0 / 
), ( / 

start ,Z0/ Z0 start


q0 q1 q0
,Z0/ Z0 ,Z0/ Z0

How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( )


Eg Book-Construction of PDA5.5-
14
283
PDAs 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)
◼ 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)

15
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
PN

PF: P N: , X0/ X0
, X0/Z0X0 , X0/ X0
New
start p0 q0 , X0/ X0 pf

 , X0 / X0
, X0/ X0

PF = (QN U {p0,pf}, ∑, PN U {X0}, δF, p0, X0, {pf}) 16


Example: Matching parenthesis “(” “)”
PN: ( {q0}, {(,)}, {Z0,Z1}, δN, q0, Z0 ) Pf : ( {p0,q0 ,pf}, {(,)}, {X0,Z0,Z1}, δf, p0, X0 , pf)

δN: δN(q0,(,Z0) = { (q0,Z1Z0) } δf: δf(p0, ,X0) = { (q0,Z0 X0) }


δN(q0,(,Z1) = { (q0, Z1Z1) } δf(q0,(,Z0) = { (q0,Z1 Z0) }
δN(q0,),Z1) = { (q0, ) }
δf(q0,(,Z1) = { (q0, Z1Z1) }
δf(q0,),Z1) = { (q0, ) }
δN(q0, ,Z0) = { (q0, ) } δf(q0, ,Z0) = { (q0, ) }
δf(p0, ,X0) = { (pf, X0 ) }

(,Z0 /Z1Z0 (,Z0/Z1Z0


(,Z1 /Z1Z1 (,Z1/Z1Z1
),Z1 /  ),Z1/ 
,Z0 /   ,Z0/ 

start
q0
start
,X /Z X
0 0 0
,X / X
0 0
p0 q0 pf

Accept by empty stack Accept by final state 17


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 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)
PN = (Q U {p0,pe}, ∑,  U {X0}, δN, p0, X0)

PN:
, X0/Z0X0 , any/  , any/ 
New
start p0 q0 , any/  pe

, any/ 
PF

18
Deterministic PDAs

19
This PDA for Lwwr is non-deterministic
Grow stack
0, Z0/0Z0
Why does it have
1, Z0/1Z0 Pop stack for to be non-
0, 0/00
matching symbols deterministic?
0, 1/01
1, 0/10 0, 0/ 
1, 1/ 
1, 1/11

q0 q1 q2
, Z0/Z0 , Z0/Z0
, 0/0
, 1/1 Accepts by final state
Switch to To remove
popping mode guessing,
impose the user
to insert c in the
middle 20
Example shows that: Nondeterministic PDAs ≠ D-PDAs

D-PDA for Lwcwr = {wcwR | c is some


special symbol not in w}
Note:
• all transitions have
Grow stack become deterministic
0, Z0/0Z0 Pop stack for
1, Z0/1Z0 matching symbols
0, 0/00
0, 1/01 0, 0/ 
1, 1/ 
1, 0/10
1, 1/11

q0 q1 q2
c, Z0/Z0 , Z0/Z0
c, 0/0
c, 1/1 Accepts by
Switch to final state
popping mode

21
Deterministic PDA: Definition
◼ A PDA is deterministic if and only if:
1. δ(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 empty.
◼ Eg: Book5.11305

22

You might also like