Unit 3 - Pda
Unit 3 - Pda
Unit 3 - Pda
PUSHDOWN AUTOMATA
Pushdown Automata Definition
Pushdown automata is a way to implement a CFG in
which it can remember an infinite amount of information.
Pushdown automata is simply an NFA augmented with an
"external stack memory".
Pushdown automata can store an unbounded amount of
information on the stack.
It can access a limited amount of information on the
stack.
A PDA can push an element onto the top of the stack and
pop off an element from the top of the stack.
To read an element into the stack, the top elements must
be popped off and are lost.
Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 2
Cont..
PDA is more capable than Finite state machines and
less capable than Turing Machines.
A PDA differs from finite state machine in two ways:
◦ It can use the top of the stack to decide which transition to
take
◦ It can manipulate the stack contents during the transition
Note:
A PDA is more powerful than FA. Any language
which can be acceptable by FA can also be acceptable
by PDA.
PDA also accepts a class of language which even
cannot be accepted by FA. Thus PDA is much more
superior to FA. Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 3
Pushdown Automata - Components
PDA = (ε-NFA)+stack.
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.
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.
Pop Idle
a , a / aa c,a/ε
a , Z0 / aZ0 c,a/ε ε , Z0 / Z0
q0 q1 q3 q3
b,a/a
c,a/ε
q2
b,a/a
a , Z0 / aZ0 b,a/ε ε , Z0 / Z0
q0 q1 q2 q3
Transition Function:
δ(q0, a, Z0) = (q1, aZ0)
δ(q1, a, a) =(q1, aa)
δ(q1, b, a) =(q2, ∈)
δ(q2, b, a) =δ(q2, ∈)
δ(q2, ∈, Z0) =δ(q3, ∈) Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 19
Problem 3
The PDA should satisfy the two conditions. shown
in the definition to be deterministic.
◦ δ(q0, a, Z0) has only one element. In this case, for each
q∈Q, a∈∑ , and Z0∈Γ, there exists only one definition
for all the traansitions so the first condition is satisfied.
◦ To satisfy the second condition consider the transition
δ(q0, a, Z0) = (q1, aZ0) whis in non empty so that δ(q0, ∈,
Z0) is empty.
◦ Similarly for all other transitions also the second
coondition is satisfied.
Therefore the given language L = {anbn | n>=1} is
deterinistic PDA. Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 20
Non-Deterministic PDA
The non-deterministic pushdown automata is
very much similar to NFA.
The CFG which accepts deterministic PDA
accepts non-deterministic PDAs as well.
Similarly,there are some CFGs which can be
accepted only by NPDA and not by DPDA.
Thus NPDA is more powerful than DPDA.
a , a / aa b,a/ε
a , Z0 / aZ0 b,a/ε ε , Z0 / Z0
q0 q1 q2 q3
ε , Z0 / Z0
a , Z0 / aa
a , Z0 / aZ0 b,a/ε
q0 q1 q2
ε,a/ε
0 / Z0
ε
,Z
0/
ε, Z
Z0
q3
a , Z0 / aZ0
a , a / aa
b,a/ε
b , Z0 / bZ0
b , b /bb
a,b/ε
ε , Z0 / Z0
q0 q1
For every ‘b’ in the tape, pop ‘b’ from the stack
Step 4: If the tape is empty and the stack is Z then accept
the string.
Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 29
PDA for the language of palindrome
1.
2.
T= {0,1}
S – Start Symbol
pair of states from Q along with each stack symbol. Here there
are only two states whose pairs are [q,q], [q,p], [p,q], [p,p] and
[p,X,q], [p,X,p].
Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 43
Productions for start Symbool S
◦ P1: S → [q,Z0,q]
◦ P2: S → [q,Z0,p]
Note: q- initial state Z0- initial stack symbol,
q,p – all states in Q.
δ(q,1,Z0) = (q,XZ0) (push operation)
Same state
◦ P13: [q,X,q] →ɛ
Prepared by S.S.KIRUHTIKA, AP/CSE,
SRM IST, RAMAPURAM 45
δ(p,1,X) = (p, ɛ)
◦ P14: [p,X,p] →1
δ(p,0,Z0) = (q,Z0)
◦ P15: [p,Z0,q] →0[q,Z0,q]
◦ P16: [p,Z0,p] →0[q,Z0,p]
Thus the PDA has been converted to CFG with 16
productions.