PPT 3.2.1 PDA Definition Examples
PPT 3.2.1 PDA Definition Examples
UNIVERSITY INSTITUTE OF
ENGINEERING
COMPUTER SCIENCE ENGINEERING
Bachelor of Engineering
Theory of Computation (CST-353)
Topic: PDA
DISCOVER . LEARN .
University Institute of Engineering (UIE) EMPOWER
Department of Computer and Science Engineering (CSE)
Outcome:
• Student will understand the
Push down automata
Applications of Push Down Automata
4
University Institute of Engineering (UIE)
old state input symb. Stack top 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 Y
3. X is the current stack top symbol
a
dde n--
q p
e
NNoo
ii. If Y=X:
i) Y= Pop(X)
issm
i
7
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
(q0,1,111Z0) (q1,11,11Z0)
,Z0/ Z0 start
start
q0 q1 q0
,Z0/ Z0 ,Z0/ Z0
13
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
PF: P N: , X0/ X0
, X0/Z0X0 , X0/ X0
New
start p0 q0 , X0/ X0 pf
…
, X0 / X0
, X0/ X0
14
University Institute of Engineering (UIE)
Example: Matching parenthesis “(” “)”
P N: ( {q0}, {(,)}, {Z0,Z1}, δN, q0, Z0 ) P f: ( {p0,q0 ,pf}, {(,)}, {X0,Z0,Z1}, δf, p0, X0 , pf)
start
q0
start
,X /Z X
0 0 0
,X / X
0 0
p0 q0 pf
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
16
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
PDA by PDA by
≡
final state empty stack
?
CFG
17
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
Example 1
18
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
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
(w-part)
7. δ(q0, , 0)={(q1, 0)}
8. δ(q0, , 1)={(q1, 1)} Switch to popping mode
9. δ(q0, , Z0)={(q1, Z0)} (boundary between w and wR)
δ(qi,a, X)={(qj,Y)}
a, X / Y Next
qi qj state
q0 q1 q2
, Z0/Z0
, Z0/Z0 , Z0/Z0
, 0/0
, 1/1 Go to acceptance
Switch to
popping mode
This would be a non-deterministic PDA
q0 q1 q2
, Z0 / Z0 ), ( / , Z0 / Z0
, Z0 / Z0 Go to acceptance (by final state)
when you see the stack bottom symbol
Switch to
(, ( / ( (
popping mode
(, Z0 / ( Z0 To allow adjacent
blocks of nested paranthesis
∑ = { (, ) }
(,Z0 / ( Z0 = {Z0, ( }
(,( / ( (
), ( /
Q = {q0,q1}
start ,Z0/ Z0
q0 q1
,Z0/ Z0
We are going to design the first part i.e. 1 comes before 0's. The
logic is that read single 1 and push two 1's onto the stack.
Thereafter on reading two 0's, POP two 1's from the stack. The δ
can be
δ(q0, 1, Z) = (q0, 11, Z) Here Z represents that stack is empty
δ(q0, 0, 1) = (q0, ε)
Now, consider the second part i.e. if 0 comes before 1's. The logic
is that read first 0, push it onto the stack and change state from q0
to q1. [Note that state q1 indicates that first 0 is read and still
second 0 has yet to read].
University Institute of Engineering (UIE) 24
Continue..
Being in q1, if 1 is encountered then POP 0. Being in q1, if 0 is
read then simply read that second 0 and move ahead. The δ will
be:
δ(q0, 0, Z) = (q1, 0Z)
δ(q1, 0, 0) = (q1, 0)
δ(q1, 0, Z) = (q0, ε) (indicate that one 0 and one 1 is already r
ead, so simply read the second 0)
δ(q1, 1, 0) = (q1, ε)
Now, summarize the complete PDA for given L is:
δ(q0, 1, Z) = (q0, 11Z)
δ(q0, 0, 1) = (q1, ε)
δ(q0, 0, Z) = (q1, 0Z)
δ(q1, 0, 0) = (q1, 0)
δ(q1, 0, Z) = (q0, ε)
δ(q0, ε, Z) = (q0, ε) ACCEPT state
Application of PDA
• For designing the parsing phase of a compiler (Syntax
Analysis).
• For implementation of stack applications.
• For evaluating the arithmetic expressions.
• For solving the Tower of Hanoi Problem.
Summary
• PDAs for CFLs and CFGs
– Non-deterministic
– Deterministic
• PDA acceptance types
1. By final state
2. By empty stack
• PDA
– IDs, Transition diagram
• Applications of PDA
27
University Institute of Engineering (UIE)
Department of Computer and Science Engineering (CSE)
FAQ :
REFERENCES :
• https://www.geeksforgeeks.org/introduction-of-
pushdown-automata/
• Martin J.C., “Introduction to Languages and Theory of
Computation”, Tata McGraw-Hill Publishing Company
Limited, 3rd Edition.
• https://www.tutorialspoint.com
• https://en.wikipedia.org