PUSHDOWN AUTOMATA (PDA)
ALAK ROY.Assistant ProfessorDept. of CSENIT Agartala
CSE-501 FORMAL LANGUAGE & AUTOMATA
THEORYAug-Dec,2010
2
PUSHDOWN AUTOMATA (PDA) Informally:
Think of an ε-NFA with the additional power that it can manipulate a stack.
Transitions are modified to accommodate stack operations.
Questions: What is a stack? How does a stack help?
Why PDA? A DFA can “remember” only a finite amount of
information, whereas a PDA can “remember” an infinite amount of (certain types of) information.
3
Example:
{0n1n | 0=<n} Is not regular
{0n1n | 0nk, for some fixed k} Is regular, for any fixed k.
For k=3:
L = {ε, 01, 0011, 000111}
0/1
q0
q7
0q1
11
q2
1q5
0q3
11
q4
0
1
00
0/1 q6
0
4
In a DFA, each state remembers a finite amount of information.
To get {0n1n | 0n} with a DFA would require an infinite number of states using the preceding technique.
An infinite stack solves the problem for {0n1n | 0n} as follows: Read all 0’s and place them on a stack Read all 1’s and match with the corresponding 0’s on the
stack
Only need two states to do this in a PDA
Similarly for {0n1m0n+m | n,m0}
PDA MODEL
CHARACTERISTIC OF PDA
PDS (Pushdown Stack)
7
PDA Being nondeterministic, the PDA can
have a choice of next moves.
Its moves are determined by:1. The current state (of its “NFA”),2. The current input symbol (or ε), and 3. The current symbol on top of its stack.
In each choice, the PDA can:1. Change state, and also2. Replace the top symbol on the stack by
a sequence of zero or more symbols. Zero symbols = “pop.” Many symbols = sequence of “pushes.”
8
FORMAL DEFINITION OF A PDA
A pushdown automaton (PDA) is a seven-tuple:
M = (Q, Σ, Г, δ, q0, z0, F)
Q A finite set of states
Σ A finite input alphabet
Г A finite stack alphabet
q0 The initial/starting state, q0 is in Q
z0 A starting stack symbol, is in Г
F A set of final/accepting states, which is a subset of Q
δ A transition function, where
δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*
9
Consider the various parts of δ:
Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*
Q on the LHS means that at each step in a computation, a PDA must consider its’ current state.
Г on the LHS means that at each step in a computation, a PDA must consider the symbol on top of its’ stack.
Σ U {ε} on the LHS means that at each step in a computation, a PDA may or may not consider the current input symbol, i.e., it may have epsilon transitions.
“Finite subsets” on the RHS means that at each step in a computation, a PDA will have several options.
Q on the RHS means that each option specifies a new state. Г* on the RHS means that each option specifies zero or
more stack symbols that will replace the top stack symbol.
10
CONVENTIONS
a, b, … are input symbols. But sometimes we allow ε as a possible value.
…, X, Y, Z are stack symbols. …, w, x, y, z are strings of input symbols. , ,… are strings of stack symbols.
11
THE TRANSITION FUNCTION
Takes three arguments:1. A state, in Q.2. An input, which is either a symbol in Σ or ε.3. A stack symbol in Γ.
δ(q, a, Z) is a set of zero or more actions of the form (p, ).
p is a state; is a string of stack symbols.
12
ACTIONS OF THE PDA
If δ(q, a, Z) contains (p, ) among its actions, then one thing the PDA can do in state q, with a at the front of the input, and Z on top of the stack is:
1. Change the state to p.2. Remove a from the front of the input (but a
may be ε).3. Replace Z on the top of the stack by . (or Pop
Z, Push )
13
Two types of PDA transitions:
δ(q, a, z) = {(p1, 1), (p2, 2),…, (pm, m)}
Current state is q Current input symbol is a Symbol currently on top of the stack z Move to state pi from q
Replace z with i on the stack (leftmost symbol on top) Move the input head to the next input symbol
:
q
p1
p2
pm
a/z/ 1
a/z/ 2
a/z/ m
14
Two types of PDA transitions:
δ(q, ε, z) = {(p1, 1), (p2, 2),…, (pm, m)}
Current state is q Current input symbol is not considered Symbol currently on top of the stack z Move to state pi from q
Replace z with i on the stack (leftmost symbol on top) No input symbol is read
:
q
p1
p2
pm
ε/z/ 1
ε/z/ 2
ε/z/ m
15
EXAMPLE: PDA
Design a PDA to accept {0n1n | n > 1}. The states:
q = start state. We are in state q if we have seen only 0’s so far.
p = we’ve seen at least one 1 and may now proceed only if the inputs are 1’s.
f = final state; accept.
16
EXAMPLE: PDA – (2)
The stack symbols: Z0 = start symbol. Also marks the bottom of the
stack, so we know when we have counted the same number of 1’s as 0’s.
X = marker, used to count the number of 0’s seen on the input.
17
EXAMPLE: PDA – (3)
The transitions: δ(q, 0, Z0) = {(q, XZ0)}. δ(q, 0, X) = {(q, XX)}. These two rules cause one
X to be pushed onto the stack for each 0 read from the input.
δ(q, 1, X) = {(p, ε)}. When we see a 1, go to state p and pop one X.
δ(p, 1, X) = {(p, ε)}. Pop one X per 1. δ(p, ε, Z0) = {(f, Z0)}. Accept at bottom.
ACTIONS OF THE EXAMPLE PDA
q
0 0 0 1 1 1
Z0
ACTIONS OF THE EXAMPLE PDA
q
0 0 1 1 1
XZ0
ACTIONS OF THE EXAMPLE PDA
q
0 1 1 1
XXZ0
ACTIONS OF THE EXAMPLE PDA
q
1 1 1
XXXZ0
22
ACTIONS OF THE EXAMPLE PDA
p
1 1
XXZ0
ACTIONS OF THE EXAMPLE PDA
p
1
XZ0
ACTIONS OF THE EXAMPLE PDA
p
Z0
ACTIONS OF THE EXAMPLE PDA
f
Z0
THANK YOU
Top Related