FLA Unit IV PDA
FLA Unit IV PDA
UNIT – IV
UNIT-IV 4. 1
Paavai Institutions Department of CSE
CONTENTS
UNIT-IV 4. 2
Paavai Institutions Department of CSE
PUSHDOWN AUTOMATA
Formal Definition:
A nondeterministic pushdown automaton or npda is a 7-tuple M = (Q, , , , q0, z, F), where
UNIT-IV 4. 3
Paavai Institutions Department of CSE
Transition function: for any given state, input symbol and stack symbol, gives a new state and
stack symbol; i.e. it has the form: (P, a, t) (Q, u)
Basically, if, a , t and P and Q are states. Means “read the symbol ‘a’ from the input, move from
state P to state Q, and replace the symbol‘t’ on top of the stack with the symbol ‘u’ ”.
Example 1:
nn
Construct PDA for the language L= {a b | a, b Σ n 0}.
Start at state q0 and keep Z0 in the stack. The following transitions are possible:
1. If current state is q0, and symbol on input tape is at , and stack top is Z0, then move to q2 the
final state.
2. If current state is q0, and input tape symbol is a, and stack top Z0, then stay in q0 and push ‘a’
to the stack.
3. If current state is q0, input tape symbol is ‘a’, and stack top is a, stay in q0 and push ‘a’ to the
stack.
4. If current state is q0, input tape symbol is b, stack top is a, move to state q1 and pop the top
symbol of the stack.
5. If current state is q1, input tape symbol is b, stack top is a, stay in q1 and pop the top symbol
of the stack
UNIT-IV 4. 4
Paavai Institutions Department of CSE
6. If current state is q1, input tape symbol is and stack top is Z0, move to q2 the final state.
So we can define PDA as M = ({q0, q1, q2}, {a, b}, {a, b, Z0}, δ, q0, Z0, {q2}), where δ is
defined by following rules:
δ(q0, a, Z0) = {(q0, aZ0)}
δ(q0, b, a) = {(q1, )}
δ(q1, b, a) = {(q1, )}
To understand the behavior or PDA clearer, the transition diagram of PDA can be used.
Transition diagram of PDA is generalization of transition diagram of FA.
4. Arc corresponds to transitions of PDA. If δ(q, a, X) = {(p, )…} is an arc labeled (a, X/ )
from state q to state p means that an input tape head positioned at symbol a and stack top
with X, moves automaton to state q and replaces the stack top with .
The transition diagram for the above example PDA is given in Figure 2.
UNIT-IV 4. 5
Paavai Institutions Department of CSE
Instantaneous Description:
Moves of A PDA:
Let the symbol "|-" indicates a move of the nPDA. There are two types of moves possible for
a PDA.
Suppose that (q1, a, x) = {(q2, y), ...}. Then the following move by consuming an input
symbol is possible:
where W indicates the rest of the input string following the a, and Z indicates the rest of the stack
contents underneath the x. This notation says that in moving from state q1 to state q2, an input
symbol ‘a’ is consumed from the input string aW, and the symbol ‘x’ at the top (left) of the stack
xZ is replaced with symbol ‘y’, leaving yZ on the stack.
The above example PDA with a few example input strings, the moves are given below:
(q0, aabb, Z0) |- (q0, abb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}
UNIT-IV 4. 6
Paavai Institutions Department of CSE
PDA reached a configuration of (q2, , ). The input tape is empty, stack is empty and PDA has
(q0, aaabb, Z0) |- (q0, aabb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}
(q0, aabbb, Z0) |- (q0, abbb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}
UNIT-IV 4. 7
Paavai Institutions Department of CSE
2. - move
Suppose that (q1, , x) = {(q2, y), ...}. Then the following move without consuming an input
symbol is possible:
This notation says that in moving from state q1 to state q2, an input symbol ‘a’ is not consumed
from the input string aW, and the symbol ‘x’ at the top (left) of the stack xZ is replaced with
symbol ‘y’, leaving yZ on the stack. In this move, the tape head position will not move forward.
This move is usually used to represent non-determinism.
*
The relation |- is the reflexive-transitive closure of |- used to represent zero or more moves of
PDA. For the above example, (q0, aabb, Z0) |-* (q2, , ).
Example 2:
Design a PDA to accept the set of all strings of 0’s and 1’s such that no prefix has more 1’s than
0’s.
UNIT-IV 4. 8
Paavai Institutions Department of CSE
(b, 1, 0) ={(c, )}
(c, 1, 0) ={(c, )}
(a, 0010110, Z) |- (b, 010110, 0Z) |- (b,10110, 00Z) |- (c, 0110, 0Z) |- (b, 110, 00Z) |-
LANGUAGES OF PDA
a. Accept by Final state After consuming the input, PDA enters a final state.
UNIT-IV 4. 9
Paavai Institutions Department of CSE
b. Accept by empty stack after consuming the input, stack of the PDA will be empty. The
current state could be final or non-final state.
Both methods are equivalent. It is possible to covert a PDA accept by final state to another PDA
accept by empty stack and also the vice versa. Usually the languages that a PDA accept by final
n m
state and PDA by empty stack are different. For example the language {L = a b | n m}, the
appropriate PDA could be by final state. After consuming the input, the stack may not be empty.
PDA by
CFG PDA by
empty stack
Final state
Let G = (V, T, Q, S) be a CFG. The PDA which accepts L(G) by empty stack is given by:
UNIT-IV 4. 10
Paavai Institutions Department of CSE
δ(q, a, a) = {(q, )}
Example:
Convert the grammar with following production to PDA accepted by empty stack:
S 0S1 | A
A 1A0 | S |
Solution:
δ(q, 0, 0) = {(q, )}
δ(q, 1, 1) = {(q, )}
Let P = (Q, Σ, Γ, δ, q0, Z0) be a PDA. An equivalent CFG is G = (V, Σ, R, S), where
2. Let δ(q,a,X) = {(r, Y1Y2…Yk)} where a Σ or a = , k can be 0 or any number and r1r2
…rk are list of states. G has productions
UNIT-IV 4. 11
Paavai Institutions Department of CSE
Example:
Construct PDA to accept if-else of a C program and convert it to CFG. (This does not accept if –
if –else-else statements).
Let the PDA P = ({q}, {i, e}, {X,Z}, δ, q, Z), where δ is given by:
Solution:
S = [qZq]
[qZq]= i[qXq][qZq]
[qXq]= e
[qZq]
If [qZq] is renamed to A and [qXq] is renamed to B, then the CFG can be defined by:
Example:
Convert PDA to CFG. PDA is given by P = ({p,q}, {0,1}, {X,Z}, δ, q, Z)), Transition function δ
is defined by:
δ(p, 1, X) = {(p, )}
UNIT-IV 4. 12
Paavai Institutions Department of CSE
Solution:
S[qZq] | [qZp]
[qZq]1[qXq][qZq]
[qZq]1[qXp][pZq]
[qZp]1[qXq][qZp]
[qZp]1[qXp][pZp]
[qXq]1[qXq][qXq]
[qXq]1[qXp][pXq]
[qXp]1[qXq][qXp]
[qXp]1[qXp][pXp]
[qXq]
[qXq]0[pXq]
[qXp]0[pXp]
For δ(p, 1, X) = {(p, )}
UNIT-IV 4. 13
Paavai Institutions Department of CSE
[pXp] = 1
[pZq]= 0[qZq]
[pZp]= 0[qZp]
Definition
A deterministic finite state pushdown automaton (abbreviated PDA or, when the context is
clear, an automaton) is a 7-tuple = (X, Z,, R, zA, SA, ZF), where
X = {x1, ... , xm} is a finite set of input symbols. As above, it is also called an alphabet.
The empty symbol is not a member of this set. It does, however, carry its usual meaning
when encountered in the input.
UNIT-IV 4. 14
Paavai Institutions Department of CSE
QUESTION BANK
PART-A
UNIT-IV 4. 15
Paavai Institutions Department of CSE
PART-B
1. a) If L is Context free language then prove that there exists PDA M such that L=N(M).
b) Explain different types of acceptance of a PDA.Are they equivalent in sense of lan- guage
acceptance? Justify your answer.
2. Construct a PDA accepting {an bm an/ m, n>=1} by empty stack. Also construct the
corresponding context-free grammar accepting the same set.
3. a) Prove that L is L(M2 ) for some PDA M2 if and only if L is N(M1) for somePDA M.
b) Define Deterministic Push Down Automata DPDA. Is it true that DPDA and PDA are
equivalent in the sense of language acceptance is concern? Justify Your answer.
c) Define a PDA. Give an Example for a language accepted byPDA by empty stack.
4. a) If L is Context free language then prove that there exists PDA M such that L=N(M).
b) Explain different types of acceptance of a PDA. Are they equivalent in sense of language
acceptance? Justify your answer
5. a) Construct the grammar for the following PDA.
M=({q0, q1},{0,1},{X,z0},δ,q0,Z0,Φ) and where δis given by
δ(q0,0,z0)={(q0,XZ0)}, δ(q0,0,X)={(q0,XX)},δ(q0,1,X)={(q1, ε)},
δ(q1,1,X)={(q1, ε)},δ(q1, ε,X)={(q1, ε)}, δ(q1, ε, Z0 )={(q1, ε)}. (12)
b) Prove that if L is N(M1) for some PDA M1 then L is L(M2 ) for some PDA M2.
6. a) Construct a PDA that recognizes the language
{ai bj ck| i,j,k>0 and i=j or i=k}.
b) Discuss about PDA acceptance 1)From empty Stack to final state. 2)From Final state to
Empty Stack.
7. a) Show that E->E+E/E*E/(E)/id is ambiguous. (6)
b) Construct a Context free grammar G which accepts N(M), where M=({q0,
q1},{a,b},{z0,z},δ,q0,z0,Φ)
and where δ is given by δ(q0,b,z0)={(q0,zz0)}δ(q0, ε,z0)={(q0, ε)}
δ(q0,b,z)={(q0,zz)}
δ(q0,a,z)={(q1,z)}
δ(q1,b,z)={(q1, ε)
δ(q1,a,z0)={(q0,z0)
Website References
1. www.youtube.com/watch?v=7axUgprsqCFc
2. www.youtube.com/watch?v=urwX97FGKLKw
Unit - IV 4.16