0% found this document useful (0 votes)
91 views

FLA Unit IV PDA

The document discusses pushdown automata (PDA). It defines a PDA as a 7-tuple with states, input symbols, stack symbols, transitions, initial state, initial stack symbol, and final states. Transitions can involve reading an input symbol, changing state, and pushing/popping the stack. PDAs correspond to context-free languages in the same way that finite automata correspond to regular languages. Examples are given to illustrate PDA configurations, moves, and acceptance of strings based on reaching a final state or empty stack.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

FLA Unit IV PDA

The document discusses pushdown automata (PDA). It defines a PDA as a 7-tuple with states, input symbols, stack symbols, transitions, initial state, initial stack symbol, and final states. Transitions can involve reading an input symbol, changing state, and pushing/popping the stack. PDAs correspond to context-free languages in the same way that finite automata correspond to regular languages. Examples are given to illustrate PDA configurations, moves, and acceptance of strings based on reaching a final state or empty stack.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Paavai Institutions Department of CSE

UNIT – IV

PUSH DOWN AUTOMATA

UNIT-IV 4. 1
Paavai Institutions Department of CSE

CONTENTS

 Push Down Automata


 Definition of the pushdown automaton
 Language of a PDA
 Equivalence of PDA’s and CFG’s
 Acceptance by final state
 Acceptance by empty stack
 Deterministic pushdown automata
 CFG to PDA
 PDA to CFG
Question Bank
Website References

UNIT-IV 4. 2
Paavai Institutions Department of CSE

PUSHDOWN AUTOMATA

Just as finite-state automata correspond to regular languages, the context-free languages


(CFL) have corresponding machines called pushdown automata (PDA).

Figure 3.2: pushdown automata

Formal Definition:
A nondeterministic pushdown automaton or npda is a 7-tuple M = (Q, , , , q0, z, F), where

Q is a finite set of states,

is a the input alphabet,

is the stack alphabet,

is a transition function, has the form

:QX( { }) X finite subsets of Q X *

UNIT-IV 4. 3
Paavai Institutions Department of CSE

q0 Q is the initial state,

z is the stack start symbol, and

F Q is a set of final states.

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’ ”.

If u = t, then stack is unchanged.

If u = , then stack is popped

If u= wx, then t is replaced with x and w is pushed into the stack.

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, a, a) = {(q0, aa)}

δ(q0, b, a) = {(q1, )}

δ(q1, b, a) = {(q1, )}

δ(q1, , Z0) = {(q2, )}

δ(q0, , Z0) = {(q2, )}

δ(q,x,Y) = for all other possibilities

Graphical Notation of PDA:

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.

1. Node corresponds to states of PDA

2. Arrow labeled Start indicates start state

3. Doubly circled states are final states

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:

Instantaneous Description or configuration of a PDA describes its execution status at any


time. Instantaneous Description is a represented by a triplet (q, w, u), where

1. q is the current state of the automaton,


2. w is the unread part of the input string, w Σ*
3. u is the stack contents, written as a string, with the leftmost symbol at the top of the stack. So
*

Moves of A PDA:

Let the symbol "|-" indicates a move of the nPDA. There are two types of moves possible for
a PDA.

1. Move by consuming input symbol

Suppose that (q1, a, x) = {(q2, y), ...}. Then the following move by consuming an input
symbol is possible:

(q1, aW, xZ) |- (q2, W, yZ),

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:

a) Moves for the input string aabb:

(q0, aabb, Z0) |- (q0, abb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}

|- (q0, bb, aaZ0) as per transition rule δ(q0, a, a) = {(q0, aa)}

|- (q1, b, aZ0) as per transition rule δ(q0, b, a) = {(q1, )}

UNIT-IV 4. 6
Paavai Institutions Department of CSE

|- (q1, , Z0) as per transition rule δ(q0, b, a) = {(q1, )}

|- (q2, , ) as per transition rule δ(q1, , Z0) = {(q2, )}

PDA reached a configuration of (q2, , ). The input tape is empty, stack is empty and PDA has

reached a final state. So the string is accepted.

b) Moves for the input string aaabb:

(q0, aaabb, Z0) |- (q0, aabb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}

|- (q0, abb, aaZ0) as per transition rule δ(q0, a, a) = {(q0, aa)}

|- (q0, bb, aaaZ0) as per transition rule δ(q0, a, a) = {(q0, aa)}

|- (q1, b, aaZ0) as per transition rule δ(q0, b, a) = {(q1, )}

|- (q1, , aZ0) as per transition rule δ(q0, b, a) = {(q1, )}

|- There is no defined move.

So the automaton stops and the string is not accepted.

c) Moves for the input string aabbb:

(q0, aabbb, Z0) |- (q0, abbb, aZ0) as per transition rule δ(q0, a, Z0) = {(q0, aZ0)}

|- (q0, bbb, aaZ0) as per transition rule δ(q0, a, a) = {(q0, aa)}

|- (q1, bb, aZ0) as per transition rule δ(q0, b, a) = {(q1, )}

|- (q1, b, Z0) as per transition rule δ(q0, b, a) = {(q1, )}

|- There is no defined move.

So the automaton stops and the string is not accepted.

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:

(q1, aW, xZ) |- (q2, aW, yZ),

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.

Solution: The transition diagram could be given as figure 3.

Figure 3.3: transition diagram

UNIT-IV 4. 8
Paavai Institutions Department of CSE

M = ({a, b, c, d}, {0,1}, {0,1,Z}, , a, Z, {d}), where is given by:

(a, 0, Z) ={(b, 0Z)}


(b, 0, 0) ={(b, 00)}

(b, 1, 0) ={(c, )}

(c, 0, 0) ={(b, 00)}

(c, 1, 0) ={(c, )}

(b, , 0) ={(d, 0)}

(b, , Z) ={(d, Z)}

(c, 0, Z) ={(b, 0Z)}

(c, , 0) ={(d, 0)}

(c, , Z) ={(d, Z)}

For all other moves, PDA stops.

Moves for the input string 0010110 is given by:

(a, 0010110, Z) |- (b, 010110, 0Z) |- (b,10110, 00Z) |- (c, 0110, 0Z) |- (b, 110, 00Z) |-

(c, 10, 0Z) |- (c, 0, Z) |- (b, , 0Z) |- (d, , 0Z).

So the input string is accepted by the PDA.

Moves for 011

(a,011,Z) |- (b,11,0Z) |- (c,1,Z) |-no move, so PDA stops

LANGUAGES OF PDA

There are 2 ways of accepting an input string PDA

a. Accept by Final state After consuming the input, PDA enters a final state.

UNIT-IV 4. 9
Paavai Institutions Department of CSE

The Content of the stack is irrelevant.

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.

Equivalence of PDA and CFG

PDA by
CFG PDA by
empty stack
Final state

Figure 3.4: equivalence of PDA and CFG

From CFG to PDA:


Given a CFG G, we construct a PDA P that simulates the leftmost derivations of G. The
stack symbols of the new PDA contain all the terminal and non-terminals of the CFG. There is
only one state in the new PDA; all the rest of the information is encoded in the stack. Most
transitions are on , one for each production. New transitions are added, each one corresponding
to terminals of G. For every intermediate sentential form uA in the leftmost derivation of w
(initially w = uv for some v), M will have A on its stack after reading u. At the end (case u = w)
the stack will be empty.

Let G = (V, T, Q, S) be a CFG. The PDA which accepts L(G) by empty stack is given by:

P = ({q}, T, V T, δ, q, S) where δ is defined by:

1. For each variable A include a transition,


δ(q, , A) = {(q, b) | A b is a production of Q}

UNIT-IV 4. 10
Paavai Institutions Department of CSE

2. For each terminal a, include a transition

δ(q, a, a) = {(q, )}
Example:

Convert the grammar with following production to PDA accepted by empty stack:

S 0S1 | A

A 1A0 | S |

Solution:

P = ({q}, {0, 1}, {0, 1, A, S}, δ, q, S), where δ is given by:

δ(q, , S) = {(q, 0S1), (q, A)}

δ(q, , A) = {(q, 1A0), (q, S), (q, )}

δ(q, 0, 0) = {(q, )}

δ(q, 1, 1) = {(q, )}

From PDA to CFG:

Let P = (Q, Σ, Γ, δ, q0, Z0) be a PDA. An equivalent CFG is G = (V, Σ, R, S), where

V = {S, [pXq]}, where p, q Q and X Γ, productions of R consists of

1. For all states p, G has productions S [q0Z0 p]

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

[qXrk]a[rY1r1] [r1Y2r2] … [rk-1Ykrk]

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:

δ(q, i, Z) = {(q, XZ)}, δ(q, e, X) = {(q, )} and δ(q, , Z) = {(q, )}

Solution:

Equivalent productions are:

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:

G = ({S, A, B}, {i, e}, {S A, A iBA | , B e}, S)

Example:

Convert PDA to CFG. PDA is given by P = ({p,q}, {0,1}, {X,Z}, δ, q, Z)), Transition function δ
is defined by:

δ(q, 1, Z) = {(q, XZ)}

δ(q, 1, X) = {(q, XX)}


δ(q, , X) = {(q, )}

δ(q, 0, X) = {(p, X)}

δ(p, 1, X) = {(p, )}

δ(p, 0, Z) = {(q, Z)}

UNIT-IV 4. 12
Paavai Institutions Department of CSE

Solution:

Add productions for start variable

S[qZq] | [qZp]

For δ(q, 1, Z)= {(q, XZ)}

[qZq]1[qXq][qZq]

[qZq]1[qXp][pZq]

[qZp]1[qXq][qZp]

[qZp]1[qXp][pZp]

For δ(q, 1, X)= {(q, XX)}

[qXq]1[qXq][qXq]

[qXq]1[qXp][pXq]

[qXp]1[qXq][qXp]

[qXp]1[qXp][pXp]

For δ(q, , X) = {(q, )}

[qXq]

For δ(q, 0, X) = {(p, X)}

[qXq]0[pXq]

[qXp]0[pXp]
For δ(p, 1, X) = {(p, )}

UNIT-IV 4. 13
Paavai Institutions Department of CSE

[pXp] = 1

For δ(p, 0, Z) = {(q, Z)}

[pZq]= 0[qZq]

[pZp]= 0[qZp]

Renaming the variables [qZq] to A, [qZp] to B, [pZq] to C, [pZp] to D, [qXq] to E [qXp] to F,


[pXp] to G and [pXq] to H, the equivalent CFG can be defined by:

G = ({S, A, B, C, D, E, F, G, H}, {0,1}, R, S). The productions of R also are to be


renamed accordingly.

Deterministic Pushdown Automata

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.

 Z = {z1, ... zn} is a finite set of states.

 = {s1, ... , sp} is a finite set of stack symbols. In this case .

 R ((X {})×Z×)×(Z×)) is the transition relation.

 zA is the initial state.

 SA is the initial stack symbol.

 ZF K is a distinguished set of final states.

UNIT-IV 4. 14
Paavai Institutions Department of CSE

QUESTION BANK
PART-A

1. Give an example of PDA.


2. Define the acceptance of a PDA by empty stack. Is it true that the language accepted by a PDA by empty
stack or by that of final state is different languages?
3. What is additional feature PDA has when compared with NFA? Is PDA superior over NFA in the sense of
language acceptance? Justify your answer.
4. Explain what actions take place in the PDA by the transitions (moves) a. δ(q,a,Z)={(p1,γ1),(p2,
γ2),…..(pm, γm)} and δ(q, ε,Z)={(p1,γ1),(p2, γ2),…..(pm,γm)}.
5. What are the different ways in which a PDA accepts the language? Define them. Is a true that non
deterministic PDA is more powerful than that of deterministic PDA? Justify your answer.
6. Explain acceptance of PDA with empty stack.
7. Is it true that deterministic push down automata and non-deterministic push
8. Down automata are equivalent in the sense of language of acceptances? Justify your answer.
9. Define instantaneous description of a PDA.
10. Give the formal definition of a PDA.
11. Define the languages generated by a PDA using final state of the PDA and empty stack of that PDA.
12. Define the language generated by a PDA using the two methods of accepting a
language.
13. Define the language recognized by the PDA using empty stack.
14. For the Grammar G defined by the productions
S → A/ B
A → 0A/ ε
B → 0B/ 1B/ ε
15. Find the parse tree for the yields (i) 1001 (ii) 00101
16. Construct the Grammar with the productions
E → E+E
E→ id Check whether the yield id + id + id is having the parse tree with root E or not.
17. What is ambiguous and unambiguous Grammar?
18. List out the applications of the pumping lemma for CFG.
19. State the pumping lemma for context-free languages.
20. Use the CFL pumping lemma to show each of these languages not to be context-free
{ aibjck| i<j<k}

21. Show that


E→E+E/E*E/( E ) / id is ambiguous.
S→aS/ aSbS/ ε is ambiguous and find the unambiguous grammar.
22. Define the Instantaneous Descriptions ( ID )

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

You might also like