2. Model of PDA
• Push Down Automaton :"Finite state machine" + "a stack"
3. • A pushdown automaton has three components −
• input tape,
• control unit, and
• stack with infinite size.
• The stack head scans the top symbol of the stack.
• A stack does two operations −
• Push − a new symbol is added at the top.
• Pop − the top symbol is read and removed.
4. Def: PDA
• A PDA can be formally described as a 7-tuple
(Q, ∑, Γ, δ, q0, Z0 , F)
• Q-finite number of states
• ∑ -input alphabet
• Γ -stack symbols
• δ -transition function: Q × (∑ ∪ {ε}) × Γ Q × Γ*
• Ex: δ(q0,a, Z0 ) =(q1,aZ0 )
• Q0 initial state (q0 ∈ Q)
• Z0 is the initial stack top symbol (Z0 ∈ Γ)
• F is a set of accepting states (F ∈ Q)
7. Instantaneous Description of PDA
• 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.
• It is denoted by a triple (q, w, γ) where;
• q is the current state
• w is the unread part of the input string or the remaining input
alphabets
• γ is the current contents of the PDA stack
8. Ex 1:Write down the IDs or moves for
input string w = “aabb” of PDA as
M = ({q0, q1}, {a, b}, {a, b, Z0}, δ, q0, Z0,
{q1}), where δ is defined by following rules:
δ(q0, a, Z0) = {(q0, aZ0)} Push
δ(q0, a, a) = {(q0, aa)} Push
δ(q0, b, a) = {(q1, ε)} Pop
δ(q1, b, a) = {(q1, ε)} Pop
Also check string w is accepted by PDA or
not?
9. • Solution: Instantaneous Description for string
w = “aabb”
• (q0, aabb, Z0)
• |- (q0, abb, aZ0)
• |- (q0, bb, aaZ0)
• |- (q1, b, aZ0)
• |- (q1, ε, Z0)
• Finally the input tape is empty or input string
w is completed, PDA stack is empty and PDA
has reached a final state. So the string ‘w’
is accepted.
δ(q0, a, Z0) = {(q0, aZ0)} Push
δ(q0, a, a) = {(q0, aa)} Push
δ(q0, b, a) = {(q1, ε)} Pop
δ(q1, b, a) = {(q1, ε)} Pop
10. Example 2: Write down the Ids for input string w = “aaabb” of the above PDA.
Also check it is accepted by PDA or not?
• (q0, aaabb, Z0)
• |- (q0, aabb, aZ0)
• |- (q0, abb, aaZ0)
• |- (q0, bb, aaaZ0)
• |- (q1, b, aaZ0)
• |- (q1, ε, aZ0)
• |- There is no defined move
• So the pushdown automaton stops at this move and the string is not
accepted because the input tape is empty or input string w is completed
but the PDA stack is not empty. So the string ‘w’ is not accepted.
Note: The above method is also called testing of a string using final state method
δ(q0, a, Z0) = {(q0, aZ0)} Push
δ(q0, a, a) = {(q0, aa)} Push
δ(q0, b, a) = {(q1, ε)} Pop
δ(q1, b, a) = {(q1, ε)} Pop
11. Language Acceptance by PDA
• Method-1: Acceptance by final state
method(Ids Method)
• Method-2: Stack Empty Method
12. Ex: Design a PDA to recognize the language
L={wcwr: w ∈ (a+b)* }
13. Test the string w=aabbcbbaa is accepted by
final state method
14. Test the string w=aabbcbbaa is accepted by
Stack Empty Method
15. step1: a b b a c a b b a
current state=q0 Z0
operation=push(
a)
step2: a b b a c a b b a
a
current state=q0 Z0
operation=push(
b)
step3: a b b a c a b b a b
a
current state=q0 Z0
operation=push(
b)
step 4: a b b a c a b b a b
b
current state=q0 a
operation=push(
a) Z0
step 5: a b b a c a b b a a
b
current state=q0 b
operation= no
push a
no pop Z0
step 6: a b b a c a b b a a
b
current state=q1 b
operation=pop() a
Z0
step 7: a b b a c a b b a
b
current state=q1 b
operation=pop() a
Z0
step 8: a b b a c a b b a
current state=q1 b
operation=pop() a
Z0
step 9: a b b a c a b b a
current state=q1
operation=pop() a
Z0
step 10: a b b a c a b b a
current state=q1
string is empty
stack is empty Z0
Therefore String is accepted
16. Design a PDA which accepts L={anbn: n>=1}.
Check whether the strings I) aaabb II) aabbb and III)aaabbb are
accepted or not using i) Final state method ii) Stack Method
17.
18. step
1: a a a b b
current state=q0 Z0
operation=push(a)
step
2: a a a b b
a
current state=q0 Z0
operation=push(a)
step3: a a a b b a
a
current
state=q0 Z0
operation=pus
h(a)
step 4: a a a b b a
a
current
state=q0 a
operation=pop
() Z0
step 5: a a a b b
current
state=q1 a
operation=
pop() a
Z0
step 6: a a a b b
current
state=q1
Input string:
empty a
Z0
String is rejected
Stack Method
19. • Design a PDA which accepts only odd no of a’s defined
over {a,b}. Check whether the string baababababbbbbaa
is accepted or not using final state and stack methods
• Construct a PDA for the language L={anb2n: n>=1}. Check
whether the string aabbbb is accepted or not by the given
language using i) Final state method ii) Stack Method
• Construct a PDA for the language L={an cb2n: n>=1}. Check
the string aaacbbbbbbb
• Construct a PDA for the language L={a2nbn: n>=1}. Check
the string aaaacbb
• Design a PDA for well formed Parenthesis (),[],{}
• Design PDA for a language L={w/w is in (a+b)* and
na(w)=nb(w) }
20. • Design PDA for a language L={w/w is in
(a+b)* and na(w)>nb(w) }
• Design PDA for a language L={w/w is in
(a+b)* and na(w)<nb(w)}
21. Types of PDA
• DPDA
• Previously constructed PDAs are DPDAs
• NPDA
• Ex1: Design a PDA to recognize the language
L={wwr: w ∈ (a+b)* }
• Ex2: construct PDA for language L containing
all the strings which are palindrome over {a,b}
22. Two stack PDA
• A two stack PDA can be formally described as a 9-tuple
(Q, ∑, Γ, Γ1, δ, q0, Z1 , Z2 , F)
• Q-finite number of states
• ∑ -input alphabet
• Γ –stack1 symbols
• Γ1 –stack2 symbols
• δ -transition function: Q × (∑ ∪ {ε}) × Γ x Γ1 (Q, Γ, Γ1 )
• δ(q0,a, Z1 , Z2 ) =(q1,aZ1 , Z2)
• Q0 initial state (q0 ∈ Q)
• Z1 is the initial stack1 top symbol (Z1∈ Γ)
• Z2 is the initial stack2 top symbol (Z2∈ Γ1)
• F is a set of accepting states (F ∈ Q)
Ex: Design a two stack PDA which accepts L={anbn cn : n>=1}.
23. Construction of PDA from CFG (or) CFG to PDA Conversion
• Step 1 − Convert the productions of the CFG into GNF.
• Step 2 − The PDA will have only one state {q}.
• Step 3 − The start symbol of CFG will be the start symbol in the PDA.
• Step 4 − All non-terminals of the CFG will be the stack symbols of the PDA
and all the terminals of the CFG will be the input symbols of the PDA.
• Step 5 − For each production in the form A → aX make a transition δ (q, a,
A)=(q,X).
• Step 6- For each production in the form A → a make a transition δ (q, a,
A)=(q, ε).
24. Ex: Convert the following CFG in to PDA
SaAA, AaS/bS/a
• The grammar is in GNF
• For SaAA: δ (q, a, S)=(q,AA).
• For AaS : δ (q, a, A)=(q,S).
• For AbS : δ (q, b, A)=(q,S)
• For Aa : δ (q, a, A)=(q, ε).
• The Equivalent PDA:
δ (q, a, S)=(q,AA).
δ (q, a, A)=(q,S).
δ (q, b, A)=(q,S)
δ (q, a, A)=(q, ε)
For A → aX : δ (q, a, A)=(q,X).
For A → a :δ (q, a, A)=(q, ε).