Pushdown - Automata
Pushdown - Automata
Pushdown - Automata
1 Introduction
Pushdown Automata (pda) is a class of automata tgat can be associated with context-free gram-
mars. Thus pda is an automaton that accepts exactly the family of context-free languages. There
are two types of pda
1.Non-deterministic pda (npda)
2.Deterministic pda (dpda)
dpda has a limitation on the set of context-free languages that it can accept, while npda ccepts
exactly the family of context-free languages.In otherwords, any context-free language can be repre-
sented by an npda.
2 Schematic Representation
chematic representation of a pushdown automaton is given in Figure. pda uses an unbounded stack
as its storage. Each move of the control unit reads a symbol from the input file, while at the same
time changing the contents of the stack through the usual stack operations. Each move of the control
unit is determined by the current input symbol as well as by the symbol currently on top of the
stack. The result of the move is a new state of the control unit and a change in the top of the stack.
1
Figure 1: Schematic representation of pda
2
so that it needs a stack symbol; no move is possible if the stack is empty. Finally, the requirement
that the elements of the range of δ be a finite subset is necessary because Q × τ ∗ is an infinite set
and therefore has infinite subsets. While an npda may have several choices for its moves, this choice
must be restricted to a finite set of possibilities.
Suppose the set of transition rules of an npda contains
δ(q1 , a, b) = {(q2 , cd), (q3 , λ)}
If at any time the control unit is in state q1 , the input symbol read is a, and the symbol on top of
the stack is b, then one of two things can happen:
(1) the control unit goes into state q2 and the string cd replaces b on top of the stack,
or (2) the control unit goes into state q3 with the symbol b removed from the top of the stack.
In our notation we assume that the insertion of a string into a stack is done symbol by symbol,
starting at the right end of the string.
The triplet,
(q, w, u)
where q is the state of the control unit, w is the unread part of the input string, and u is the
stack contents (with the leftmost symbol indicating the top of the stack), is called an instantaneous
description of a pushdown automaton. A move from one instantaneous description to another will
be denoted by ⊢ the symbol; thus
(q1 , aw, bx) ⊢ (q2 , w, yx)
is possible if and only if
(q2 , y) ∈ (q1 , a, b)
Moves involving an arbitrary number of steps will be denoted by ⊢∗ . The expression
(q1 , w1 , x1 ) ⊢ (q2 , w2 , x2 )
indicates a possible configuration change over a number of steps.
3
In words, the language accepted by M is the set of all strings that can put M into a final state at
the end of the string. The final stack content u is irrelevant to this definition of acceptance.
4
Figure 2: Transition Diagram
6 Problems
1. Design an npda for L = {an bn : n ≥ 1}. Show the IDs for w = aabb
The solution is to push all a’s onto the stack and then do the pop operation for each input
b. If the stack is empty when the end of the string is reached then the input string is in L.
Othewrise the string is not in L.
Thus, we design npda with,
Q = {q0 , q1 , qf }
Σ = {a, b}
τ = {a, b}
z=z
F = {qf }
q0 = q0
and with transitions :
δ(q0 , a, z) = (q0 , az)
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , λ)
δ(q1 , b, a) = (q1 , λ)
δ(q1 , λ, z) = (qf , λ)
IDs
(q0 , aabb, z) ⊢ (q0 , abb, az) ⊢ (q0 , bb, aaz) ⊢ (q1 , b, az) ⊢ (q1 , λ, z) ⊢ (qf , λ, λ)
5
2. Design an npda for L = {an b2n : n ≥ 1}. Show the moves made by the npda for w = aabbbb
The solution is to push 2 a’s onto the stack for each input a and then do the pop operation
for each input b. If the stack is empty when the end of the string is reached then the input
string is in L. Othewrise the string is not in L.
Thus, we design npda with,
Q = {q0 , q1 , qf }
Σ = {a, b}
τ = {a, b}
z=z
F = {qf }
q0 = q0
and with transitions :
δ(q0 , a, z) =0 , aaz)
δ(q0 , a, a) =0 , aaa)
hspace*1cm δ(q0 , b, a) =1 , λ)
δ(q1 , b, a) =1 , λ)
δ(q1 , λ, z) = {(qf , λ)
IDs
(q0 , aabbbb, z) ⊢ (q0 , abbbb, aaz) ⊢ (q0 , bbbb, aaaaz) ⊢ (q1 , bbb, aaaz) ⊢ (q1 , bb, aaz) ⊢ (q1 , b, az) ⊢
(q1 , λ, z) ⊢ (qf , λ, λ)
6
δ(q0 , a, z) = (q0 , az)
δ(q0 , b, z) = (q2 , z) (only b’s)
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , λ)
δ(q1 , b, a) = (q1 , λ)
δ(q1 , b, z) = (q2 , z)
δ(q2 , b, z) = (q2 , z)
δ(q2 , λ, z) = (qf , λ)
7
then the input string is in L. Othewrise the string is not in L.
Thus, we design npda with,
Q = {q0 , q1 , qf }
Σ = {a, b}
τ = {a, b}
z=z
F = {qf }
q0 = q0
and with transitions :
δ(q0 , a, z) = (q0 , az)
δ(q0 , b, z) = (q0 , bz)
δ(q0 , a, a) = (q0 , aa)
δ(q0 , a, b) = (q0 , ab)
δ(q0 , b, b) = (q0 , bb)
δ(q0 , b, a) = (q0 , ba)
δ(q0 , c, a) = (q1 , a)
δ(q0 , c, b) = (q1 , b)
δ(q1 , a, a) = (q1 , λ)
δ(q1 , b, b) = (q1 , λ)
δ(q1 , λ, z) = (qf , λ)
8
τ = {a, b}
z=z
F = {qf }
q0 = q0
and with transitions :
δ(q0 , a, z) = (q0 , az)
δ(q0 , b, z) = (q0 , bz)
δ(q0 , a, a) = (q0 , aa)
δ(q0 , a, b) = (q0 , ab)
δ(q0 , b, b) = (q0 , bb)
δ(q0 , b, a) = (q0 , ba)
δ(q0 , λ, a) = (q1 , a)
δ(q0 , λ, b) = (q1 , b)
δ(q1 , a, a) = (q1 , λ)
δ(q1 , b, b) = (q1 , λ)
δ(q1 , λ, z) = (qf , λ)
Let w = abbbba then thge moves made by the npda are
(q0 , abbbba, z) ⊢ (q0 , bbbba, az) ⊢ (q0 , bbba, baz) ⊢ (q0 , bba, bbaz) ⊢ (q1 , bba, bbaz) ⊢ (q1 , ba, baz) ⊢
(q1 , a, az) ⊢ (q1 , λ, z) ⊢ (qf , λ, λ)
9
F = {qf }
q0 = q0
and with transitions :
δ(q0 , λ, z) = (qf , λ) (λ is accepted)
δ(q0 , a, z) = (q0 , az)
δ(q0 , b, z) = (q1 , bz) ( to accept bm cm )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , c, a) = (q2 , λ) (to accept an cn )
δ(q0 , b, a) = (q1 , ba) (to accept an bm cn+m )
δ(q1 , b, b) = (q1 , bb)
δ(q1 , c, b) = (q2 , λ)
δ(q2 , c, a) = (q2 , λ)
δ(q2 , c, b) = (q2 , λ)
δ(q2 , λ, z) = (qf , λ)
Table 1: Method
Followig the above method, we find that when reach the end of the input string the stack must
be empty if the string is in L.
Thus, we design npda with,
Q = {q0 , qf }
Σ = {a, b}
τ = {a, b}
10
z=z
F = {qf }
q0 = q0
and with transitions :
δ(q0 , a, z) = (q0 , az)
δ(q0 , b, z) = (q0 , bz)
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, b) = (q0 , bb)
δ(q0 , a, b) = (q0 , λ)
δ(q0 , b, a) = (q0 , λ)
δ(q0 , λ, z) = (qf , λ)
11
δ(q0 , b, a) = (q1 , λ)
δ(q1 , b, a) = (q1 , λ)
δ(q1 , λ, z) = (qf , λ)
15. Design an npda for L = {w : na (w) < nb (w), w ∈ {a, b}∗ }. (Exercise)
12