Class 19 Pushdown Automata
Class 19 Pushdown Automata
In a given state, PDA will read input symbol and stack symbol (top of
the stack) and move to a new state and change the symbol of stack.
Transitions and Graphical Notation
Let ((P, α, β), (q, γ) ) ε δ, then it means that
• read α from the tape
• pop the string β from the stack
• move from state p to state q
• push string γ on to the stack
The following diagram shows a transition in a PDA from a state q1 to state q2, labeled
as a,b → c
This means at state q1, if we encounter an input string ‘a’ and top symbol of the
stack is ‘b’, then we pop ‘b’, push ‘c’ on top of the stack and move to state q2.
Instantaneous Description (ID)
Instantaneous Description (ID) is an informal notation of
how a PDA “computes” a input string and make a decision
that string is accepted or rejected.
PDA
III. ((p,a, β), (q,y) )
if machine M is in state P, the symbol read from
input tape is ‘a’ and β is on the top of the stack
goes to state q and replace β by y on the top of the
stack
1. ((S,a,e), (S,a))
if machine M is in state S, reads ‘a’ remains in state S and
push ‘a’ onto stack (e- empty stack)
2. ((S,c,e),( f,e))
if read ‘c’ in state S and stack is empty, goes to final state f
and nothing to push onto stack.
3. ((S,e,e), (f,e))
if in state S, go to state f.
4. ((f,a,a) , (f, Ф)
if read ‘a’ in state f, remain in state f and pop ‘a’ from stack
iii) Once in q1, we compare input symbols with the symbol at the top
of the stack. If they match we consume the input symbol, pop
the stack and proceed. If they do not match, the input string is
not palindrome.
iv) If we empty the stack, we have seen input ‘w’ followed by wr. The
string is accepted
PDA P (Q, ∑, Γ, δ, q0, z0, F)
Q ={q0,q1,q2}
∑ = {0,1}
Γ = {0,1, z0}
Start state = q0
Start stack symbol =z0
Final state {q2}
I. Set to push w onto stack
δ ( q0 , 0 , z0) = { (q0,0z0)}
δ ( q0 , 1 , z0) = { (q0,1z0)}
δ ( q0 , 0 , 0) = { (q0,`00)}
δ ( q0 , 0 , 1) = { (q0, 01)}
δ ( q0 , 1 , 0) = { (q0, 10)}
δ ( q0 , 1 , 1) = { (q0, 11)}
To find middle of the string, NPDA switches state from q0 to
q1
δ ( q0 , ε , z0) = { (q1, z0)}
δ ( q0 , ε , 0) = { (q1, 0)}
δ ( q0 , ε , 1) = { (q1, 1)}
Solution
Step 1:
We must construct equivalent CFG with Greibach
Normal Form by changing productions to
S aSA/a
AbB
Bb
Step 2:
Now we can construct pda in the following way
M = (Q, Σ, Γ,δ,q0,z0,F) where
Q = {q0,q1,q2}. q0 – Initial state , q2- Final state
Σ - terminals of grammar = {a,b}
Γ - Variables of grammar U {z0} = V0 U {z0}
F – {q2} = Final state and δ is defined as:
Solution:
We can construct pda
M = (Q, Σ, Γ,δ,q0,z0,F) where
Q = {q0, f}. q0 – Initial state , f- Final state
Σ - terminals of grammar = {a,b}
Γ - Variables of grammar U {z0} = V0 U {z0} = { S,A, B,Z0}
F – {f} = Final state and δ is defined as:
R1 : δ ( q0,λ, z0) = { (f, Sz0)}
R6 : δ ( f, a, a ) = { (f, λ )}
R7 : δ ( f, b, b ) = { (f, λ )}
R8 : δ ( f, λ, z0 ) = { (f, λ )}
PDA to CFG
R1: The Production for start symbol S are given by
S[q0,z0,q] for each state q in Q
R2: For Each move that pops a symbol from stack with transition as
δ(q,a,z0) = (q1, ε) induces a production as
(q,z0,q1) a for each q’ in Q
R3: For Each move that does not pop symbol from stack with
transition as δ(q1,a,z0) = (q1, z1z2z3z4) induces a production as
[q, z, q’] a [q1 , z1, q2] [q2 , z2, q3] [q3 , z3, q4]………….[qm, zm. q’]
Where each state q’, q1, q2, …qm can be any state in Q
Generate CFG for given PDA M is defined as M= {{q0,q1}, {a.b},{z,zo},
δ,q0,z0,q1} where δ is given as follows
1.δ(q0,b,z0) = (q0, zz0)
2.δ(q0,ε,z0) = (q0, ε)
3.δ(q0,b,z) = (q0, z1z2)
4.δ(q0,a,z) = (q1, z)
5.δ(q1,b,z) = (q1, ε)
6.δ(q1,a,z0) = (q0, z0)
Solu:
R1:
S [q0,z0,q0]
S [q0,z0,q1]
R2:
2. δ(q0,ε,z0) = (q0, ε)
δ(q0,z0,q0) ε
R3:
3. δ(q0,b,z) = (q1, z1z2)
δ[q0,z, q0] b [q1, z1, q0] [q0, z2, q0]
δ[q0,z, q0] b [q1. z1, q1] [q1, z2, q0]
δ[q0,z, q1] b [q1. z1, q0] [q0, z2, q1]
δ[q0,z, q1] b [q1. z1, q1] [q1, z2, q1]
R3:
4. δ(q0,a,z) (q1,z)
R3:
6. δ(q1,a, z0) = (q0, z0)
δ[q1,z0,q0] a [q0, z0, q0]
δ[q1, z0,q1] a [q0, z0, q1]
R3:
1. δ(q0,b, z0) = (q0, zz0)
δ[q0, z0,q0] b [q0, z, q0] [q0, z0, q0]
δ[q0, z0,q0] b [q0, z, q1] [q1, z0, q0]
δ[q0, z0,q1] b [q0, z, q0] [q0, z0, q1]
δ[q0, z0,q1] b [q0, z, q1] [q1, z0, q1]
Construct CFG from PDA
δ(q,1,z0) = (q, xz0)
δ(q,1,x) = (q, xx)
δ(q,0,x) = (p, x)
δ(q, ε, x) = (q, ε )
δ(p, 1, x) = (p, ε )
δ(p, 0, z0) = (q, z0 )
R1:
S [q, z0, q]
S [q, z0, p]
R2
δ(q, x, q) ε
δ(p, x, p) 1
δ(q,1, z0) = (q, xz0)
δ[q, z0,q] 1 [q, x, q] [q, z0, q]
δ[q, z0,q] 1 [q, x, p] [p, z0, q]
δ[q, z0,p] 1 [q, x, q] [q, z0, p]
δ[q, z0,p] 1 [q, x, p] [p, z0, p]
δ(q, 0, x) = (p, x )
δ[q, z0,p] 0 [q, z0, q]
δ[p, z0,p] 0 [q, z0, p]
Deterministic PDA’s
• A PDA is deterministic if there is atmost one move for any
input symbol, any top stack symbol and at any state
• A no move or move without advancing input string are
possible in a deterministic PDA.
• A move without advancing input string implies that no
other move exists.
• The pushdown automation for WCWR is deterministic
• The set of languages accepted by DPDA is only a subset of
the languages accepted by NPDA’s.
• A regular language is language accepted by a DPDA
• Not all language is accepted by a DPDA are regular
• A language accepted by DPDA have an unambiguous CFG
• Not all unambiguous languages are accepted by DPDA.