Unit 4
Unit 4
❑ Deterministic PDA
❑ Non-Deterministic PDA
❑ Application of PDA.
TCS : UNIT 4 1
UNIT 4 : PUSHDOWN AUTOMATA (PDA)
CHOMSKY HIERARCHY
TCS : UNIT 4 2
PUSHDOWN AUTOMATA (PDA)
❖ Pushdown Automata is a finite automata with extra memory called stack which helps Pushdown
automata to recognize Context Free Languages.
❖ A Pushdown Automata (PDA) can be defined as ( represented by 7 elements or tuples):
P = (Q, Σ, Γ, δ, q0, Z0, F)
➢Q is the set of states
➢∑ is the set of input symbols
➢Γ is the set of pushdown symbols (which can be pushed and popped from stack)
➢ q0 is the initial state
➢ Z0 is the initial pushdown symbol (which is initially present in stack)
➢F is the set of final states
➢δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*
In a given state, PDA will read input symbol and stack symbol (top of the stack) and
move to a new state and change the symbol of stack.
TCS : UNIT 4 3
A Pushdown Automata (PDA) is a way to implement context-free Grammar in a similar way.
We design Finite Automata for Regular Grammar.
1. It is more powerful than FSM.
2. FSM has very limited memory but PDA has more memory.
3. PDA= Finite State Machine + Stack
This stack has infinite memory and that facilitates the higher power of Pushdown automata.
This helps PDA to behave more powerful than Finite-state Machine.
A Pushdown Automata has three Components: Є
1. An input tape
2. A finite Control Unit.
3. A stack with infinite size.
TCS : UNIT 4 4
ASSIGNMENT 4: Q1
Example : Design the pushdown automata for language {an b2n | n > 0}
OR
Design the pushdown automata for language {0n 12n | n > 0}
Soln: language = L = {0n 12n | n > 0}
δ: Q x {Σ ∪ ∈} x Γ into Q x Γ*
0 0 1 1 1 1 Є
0
0
Initial
Z0
Symbol
Stack
TCS : UNIT 4 5
0 0 1 1 1 1 Є
0 δ = Q x {Σ ∪ ∈} x Γ into Q x Γ*
Z0 δ(q0, 0, Z0 ) ➔ ( q0, 0 Z0 )
δ(q0, 0, 0 ) ➔ ( q0, 0 0 )
δ(q0, 1, 0 ) ➔ ( q1, 0 )
δ(q1, 1, 0 ) ➔ ( q2, Є)
δ(q2, 1, 0 ) ➔ (q1, 0 )
δ(q2, Є, Z0 ) ➔ ( qf, Z0 )
Z0
TCS : UNIT 4 6
Example : Define the pushdown automata for language {an bn | n > 0}
OR
Define the pushdown automata for language {0n 1n | n > 0}
Soln: language = L = {an bn | n > 0}
a a a b b b Є
a
a a
a a
Initial Z0 Z0
Symbol
Stack
TCS : UNIT 4 7
δ = Q x {Σ ∪ ∈} x Γ into Q x Γ*
TCS : UNIT 4 8
Example : Design the pushdown automata for language accepting equal number of a’s and b’s.
Soln: Symbols = (a, b) language = L = string contains number of a’s equal to number of b’s
a b a a b b b b a a Є
Here stack is used to store both a’s & b’s but it will store only
excess of a’s over b’s or excess of b’s over a’s as per input
string
b a b b a a a a b b Є
TCS : UNIT 4 9
q 1, Z0 )
TCS : UNIT 4 10
Example : Define the pushdown automata for language
Soln: Symbols = (0, 1) language = L = string w contains number of 0’s equal to number of 1’s
0 1 0 0 1 1 Є
TCS : UNIT 4 11
Example : Construct the pushdown automata for language
L(M) = { wcwR | w {a,b}* } where wR is reverse of w & c is a constant
Soln: Symbols = (a, b)
language = L = if w has n symbols then length of the string will be 2n + 1 such that first n
symbols should match with last n symbols in reverse order.
a b b c b b a Є
Hint: Some string will come followed by one 'c', followed by reverse of the string before 'c’.
So we get to know that 'c' will work as an alarm to starting popping STACK.
So we will pop every 'a' with 'a' and every 'b' with 'b’. b
STEPS: b
a
1. Initially every a's and b’s, push them into STACK till ‘c’ comes.
Z
2. When 'c' comes do nothing.
3. Starting popping STACK: 'a' for 'a' and 'b' for 'b'.
TCS : UNIT 4 12
Solution Explanation :
Lets see, how this DPDA is working: For example take one input string: "abbcbba"
a b b c b b a Є
δ(q0, c, a) = (q1, a)
δ(q0, c, b) = (q1, b)
δ(q1, b, b) = (q1, ε)
δ(q1, a, a) = (q1, ε)
δ(q1, ε, Z) = (qf, Z)
TCS : UNIT 4 14
DPDA & NPDA
DPDA: For every input with the current state, there is
only one move.
M = (Q,∑,Γ,q0, Z,F ,δ)
δ: Q *{∑∪∈}* Γ→Q*Γ
TCS : UNIT 4 15
Why NPDA is more powerful than DPDA?
➢ NDPA is more powerful than DPDA because we can add more transitions to it.
➢ It is possible for every language to add a transition.
➢ For some languages, we can construct DPDA there exist an NPDA but there are some
languages that are accepted by NPDA but are not by DPDA. This is said to be powerful when
it accepts more sets of languages than other automata.
➢ In fact, it is more powerful than DFA(Deterministic finite automata) and NFA(Non-
deterministic finite automata) also because, In the case of DFA and NFA, they are equivalent
in power. So for every language accepted by DFA there exist an NFA and Vice-Versa. There is
not any language for which we construct NFA but not DFA. Hence, we can’t convert NPDA to
DPDA always and we can convert NFA to equivalent DFA always.
TCS : UNIT 4 16
NDPA(Non-deterministic Pushdown
S. No DPDA(Deterministic Pushdown Automata)
Automata)
1. It is less powerful than NPDA. It is more powerful than DPDA.
It is possible to convert every DPDA to a It is not possible to convert every NPDA to
2.
corresponding NPDA. a corresponding DPDA.
The language accepted by DPDA is a subset The language accepted by NPDA is not a
3.
of the language accepted by NDPA. subset of the language accepted by DPDA.
TCS : UNIT 4 17
EXPRESSIVE POWER OF VARIOUS AUTOMATA:
The Expressive Power of any machine can be determined from the class or set of Languages accepted by
that particular type of Machine. Here is the increasing sequence of expressive power of machines :
As we can observe that FA is less powerful than any other machine. It is important to note that DFA
and NFA are of same power because every NFA can be converted into DFA and every DFA can be
converted into NFA .
The Turing Machine i.e. TM is more powerful than any other machine.
i) Finite Automata (FA) equivalence:
Finite Automata ≡ PDA with finite Stack ≡ TM with finite tape ≡ TM with unidirectional tape ≡ TM with
read only tape
(ii) Pushdown Automata (PDA) equivalence:
PDA ≡ Finite Automata with Stack
TCS : UNIT 4 18
(iii) Turing Machine (TM) equivalence:
Turing Machine ≡ PDA with additional Stack ≡ FA with 2 Stacks
TCS : UNIT 4 20