Pushdown Automata
Pushdown Automata
206
Theory of Computation
Unit-III
Pushdown Automata
Input tape: The input tape is divided in many cells or symbols. The input head is read-only
and may only move from left to right, one symbol at a time.
Finite control: The finite control has some pointer which points the current symbol which is
to be read, with finite number of states.
Stack: The stack is a structure in which we can push and remove the items from one end
only. It has an infinite size. In PDA, the stack is used to store the items temporarily.
Definition - Pushdown Automata
Γ: a finite non-empty set of stack / pushdown symbol which can be pushed and
popped from the stack
δ: the transition function which maps from QX{ΣU^}X Γ into the set of finite subset
of QXΓ*.
Graphical Notations for PDA
The transition from an ID to another ID is defined by the term move relation and
denoted by Turnstile notations:
⊢ sign describes the turnstile notation and represents one move.
…. a b a b …. …. a b a b ….
q b
a
q’ a
a a
Z0 Z0
(q,abab,baaZ0)
⊢ (q’,bab,aaZ0)
(q,abab,baaZ0) ⊢* (q’,^,Z0)
Representation of PDA by Transition Diagram
Similarly, the transition δ(qi,0,0)={(qi,^)}, popping an element from the stack can be
represented as (0,0,^)
qi
String / Language Acceptance
Now when we read b, we will change the state from q0 to q1 and start popping
corresponding 'a'. Hence,
δ(q0, b, a) = (q1, ε)
Thus this process of popping 'b' will be repeated unless all the symbols are read. Note
that popping action occurs in state q1 only.
δ(q1, b, a) = (q1, ε)
Example
Thus this process of popping 'b' will be repeated unless all the symbols are read. Note that popping action
occurs in state q1 only.
δ(q1, b, a) = (q1, ε)
After reading all b's, all the corresponding a's should get popped. Hence when we read ε as input symbol
then there should be nothing in the stack. Hence the move will be:
δ(q1, ε, Z) = (q2, ε)
Where
PDA = ({q0, q1, q2}, {a, b}, {a, Z}, δ, q0, Z, {q2})
We can summarize the ID as:
δ(q0, a, Z) = (q0, aaZ)
δ(q0, a, a) = (q0, aaa)
δ(q0, b, a) = (q1, ε)
δ(q1, b, a) = (q1, ε)
δ(q1, ε, Z) = (q2, ε)
Example
Now we will simulate this PDA for the input string "aaabbbbbb".
⊢ δ(q1, b, aZ)
⊢ δ(q1, ε, Z)
⊢ δ(q2, ε)
ACCEPT
Example
2. Design a PDA for accepting a language {0n1m0n | m, n>=1}.
Solution: Hence the logic for design of such PDA will be as follows:
Push all 0's onto the stack on encountering first 0's. Then if we read 1, just do nothing.
Then read 0, and on each read of 0, pop one 0 from the stack.
δ(q0, 1, 0) = δ(q1, 0)
δ(q1, 1, 0) = δ(q1, 0)
δ(q1, 0, 0) = δ(q1, ε)
δ(q1, ε, Z) = δ(qf, Z) (ACCEPT state)
Exercise
1. Construct Pushdown automata for L = {0n1m2m3n | m,n ≥ 0}
2. Construct Pushdown automata for L = {a(2*m)c(4*n)dnbm | m,n ≥ 0}
3. Construct Pushdown automata for L = {0n1m2(n+m) | m,n ≥ 0}
4. Construct Pushdown automata for L = {0m1(n+m)2n | m,n ≥ 0}
5. Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0}
Deterministic Push Down Automata
A deterministic pushdown automaton is one for which every input string has a unique
path through initial state to final state in the machine.
A push down automata M= (Q, ∑, Γ, δ , q0, Z0, F), is said to be deterministic if for all qϵQ,
aϵΣ and Zϵ Γ
If any of the above rules is not satisfied even once, the PDA is called nondeterministic.
Nondeterministic Push Down Automata
A push down automata M= (Q, ∑, Γ, δ , q0, Z0, F), is said to be nondeterministic with the
transition function defined as the mapping:
Context Free Language (CFL’s) can be described by Context Free Grammars (CFG’s) and
can be processed by Pushdown Automata.
Given a CFG G=(VN,Σ,P,S) generating language L(G), we define a PDA M(G) for CFG G
Step 3: The initial symbol of CFG will be the initial symbol in the PDA.
2. Construct PDA for the CFG G=({E,T,F},{(,),a,+,*},P,E), productions are defined as:
P={E->T|E+T, T->F|T*F, F->a|(E)}
Test string “a+(a*a)” against PDA.
Equivalence of PDA and Context Free Language
The productions P in grammar G are induced by moves of PDA. P is defined by the following rules:
R2: Each move removing a symbol from push down store is given by (q’,^) ϵ δ(q, a, Z) which
R3: A move that does not remove a symbol from stack is given by
M=({q0,q1},{a,b},{Z0,Z},δ,q0,Z0,{φ}),
δ is given by
δ(q0, b, Z0)={(q0, ZZ0)}
δ(q0, ^, Z0)={(q0, ^)}
δ(q0, a, Z)={(q1, Z)}
δ(q0, b, Z0)={(q0, ZZ)}
δ(q1, a, Z0)={(q0, Z0)}
δ(q1, b, Z)={(q1, ^)}
Solution:
Note that the elements in VN, except S, denoted by a triple are constructed by using all
combinations of q0, and q1, with Z0 or Z1 in the middle. Thus, there are 2m*n+1 variable in VN
(including S), if there are m unique states and n unique push down symbols.
Example
The set of production P includes
P1:S->[q0,Z0,q0]
P3:[q0,Z0,q0]->b[q0,Z,q0] [q0,Z0,q0]
P8:[q0,Z,q0]->b[q0,Z,q0] [q0,Z0,q0]
P12:[q0,Z,q0] ->a[q1,Z,q0]
P16:[q1,Z0,q1] ->a[q0,Z,q1]
… a a a . . a a a bn c c c c . . c c .
. . . . . Input Tape
a b
a Finite State Control
b
. .
. .
Z1 Z2
Stack S1 Stack S2
Input string is exhausted, stacks are left with Z1 and Z2 , and machine is in final state.
Hence, the language L={ anbncn|n>=0} can be processed by the machine.
Exercise
Construct a 2 stack PDA to recognize the language
a) L={ anbncndn|n>=0}
b) L={ anbncmdn|n,m>=0}
c) L={ anbnc2n|n>=0}
d) L={ anb2ncndn|n>=0}
e) L={ anbmcn+m|n>=0}