You are on page 1of 17

Theory of Computation

Pushdown Automata

Dr. Nagendra Pratap Singh


Assistant Professor
Department of CSE
NIT Hamirpur (H.P.)
Basic Structure of PDA
A pushdown automaton is a way to implement a context-free grammar in a similar way we design DFA for a
regular grammar. A DFA can remember a finite amount of information, but a PDA can remember an infinite
amount of information.
Basically PDA is Combination of “Finite State Machine + Stack”
Basic Model of a Pushdown Automata is shown in fig.-1 Fig.-1 Basic Model of a Pushdown Automata
PDA has Three Components:-
• An I/P Tape
• Control Unit
• An infinite size STACK having two operations
Push and Pop
Definition of PDA:
A PDA can be formally defined by a 7-tuple (Q, ∑, S, δ, q0, Z0, F) :
Q is a finite nonempty set of states.
∑ is a finite nonempty set of input alphabet.
S is a finite nonempty set of stack symbols or pushdown symbols.
δ is the transition function mapping from Q × (∑ ∪ {ε}) × S to Q × S*
i.e. δ: Q × (∑ ∪ {ε}) × S Q × S*
q0 is the initial state (q0 ∈ Q)
Z0 is the special pushdown symbol/initial stack symbol (Z0 ∈ S)
F is a set of accepting states (F ∈ Q)
PDA is known as Deterministic PDA (DPDA) if:
The transition function mapping from Q × (∑ ∪ {ε}) × S to Q × S*
i.e. δ: Q × (∑ ∪ {ε}) × S Q × S*
PDA is known as Nondeterministic PDA (NPDA) if:
The transition function mapping from Q × (∑ ∪ {ε}) × S to Q × S*
i.e. δ: Q × (∑ ∪ {ε}) × S 2Q × S*
Example-1: Design a PDA for 𝑎𝑛 𝑏𝑛 i.e. equal number of a’s and equal number of b’s where n
number of a’s is followed by n number of b’s.
Solution: δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 ) δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 )
δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎) δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎)
𝑜𝑟 δ(𝑞0 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , b, 𝑎) → (𝑞0 , Λ)
δ(𝑞0 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 ) δ(𝑞1 , b, 𝑎) → (𝑞1 , Λ)
(a) δ(𝑞1 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 )
(b)
δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 ) δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 )
δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎) δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎)
δ(𝑞0 , b, 𝑎) → (𝑞0 , Λ) δ(𝑞0 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , Λ, Λ) → (𝑞𝑓 , 𝑍0 ) δ(𝑞1 , b, 𝑎) → (𝑞1 , Λ)
(c) δ(𝑞1 , Λ, Λ) → (𝑞𝑓 , 𝑍0 )
(d)
Where 𝑞0 initial state, a is a first symbol of input tape, 𝑍0 is an initial symbol of stack, and 𝑞𝑓 is a
final state or accepting state.
The transition function δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 ) represents a push operation.
The transition function δ(𝑞0 , b, 𝑎) → (𝑞0 , Λ) represents a pop operation
The transition function δ(𝑞0 , b, 𝑎) → (𝑞1 , Λ) indicates a change of state and pop operation.
There are two different ways to define PDA acceptability.

1. Final State Acceptability: In final state acceptability, a PDA accepts a string when, after reading the
entire string, the PDA is in a final state. From the starting state, we can make moves that end up in a
final state with any stack values. The stack values are irrelevant as long as we end up in a final state.

For a PDA (Q, ∑, S, δ, q0, Z0, F), the language accepted by the set of final states F is −
L(PDA) = {w | (q0, w, Z0) →* (qf , ε, Z0), q ∈ F} for any input stack string Z0. (see Solution-1 (a) and (b))

2. Empty Stack Acceptability: Here a PDA accepts a string when, after reading the entire string, the
PDA has emptied its stack.
For a PDA (Q, ∑, S, δ, q0, Z0, F), the language accepted by the empty stack is −
L(PDA) = {w | (q0, w, Z0) →* (q, ε, ε), q ∈ Q}. (see Solution-1 (c) and (d))

Note: Here, we use final state acceptability.


Transition Diagram of the Solution-1 (a), (b), (c) and (d) is given in fig.-2 (a), (b), (c) and (d) respectively)

fig.-2 (a) fig.-2 (b)

fig.-2 (c) fig.-2 (d)


Example-2: Design a PDA for 𝑏𝑛 𝑎𝑛 i.e. equal number of a’s and equal number of b’s
where n number of b’s is followed by n number of a’s.
Solution: δ(𝑞 , b, 𝑍 ) → (𝑞 , b𝑍 ) δ(𝑞0 , b, 𝑍0 ) → (𝑞0 , b𝑍0 )
0 0 0 0
δ(𝑞0 , b, 𝑏) → (𝑞0 , b𝑏)
δ(𝑞0 , b, 𝑏) → (𝑞0 , b𝑏)
𝑜𝑟 δ(𝑞0 , a, 𝑏) → (𝑞1 , Λ)
δ(𝑞0 , a, 𝑏) → (𝑞0 , Λ)
δ(𝑞1 , a, 𝑏) → (𝑞1 , Λ)
δ(𝑞0 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 )
δ(𝑞1 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 )
(a)
(b)

Transition Diagrams are as follows:

(a) (b)
Example-3: Design a PDA that accepts an equal number of a’s and equal number of b’s
where, either n number of a’s followed by n number of b’s or n number of b’s followed
by n number of a’s.
Solution: δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 ) δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 )
δ(𝑞0 , b, 𝑍0 ) → (𝑞0 , b𝑍0 ) δ(𝑞0 , b, 𝑍0 ) → (𝑞0 , b𝑍0 )
δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎) δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎)
δ(𝑞0 , b, 𝑏) → (𝑞0 , b 𝑏) 𝑜𝑟 δ(𝑞0 , b, 𝑏) → (𝑞0 , b 𝑏)
δ(𝑞0 , b, 𝑎) → (𝑞0 , Λ) δ(𝑞0 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , a, 𝑏) → (𝑞0 , Λ) δ(𝑞1 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 ) δ(𝑞0 , a, 𝑏) → (𝑞1 , Λ)
δ(𝑞1 , a, 𝑏) → (𝑞1 , Λ)
(a)
δ(𝑞1 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 )
(b)
Transition Diagrams are as follows:

(a) (a)
Example-4: Design a PDA which accepts the language: L= {w ∈ {a, b}* : w has equal number of a’s and b’s}.
Solution: δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 )
δ(𝑞0 , a, 𝑍0 ) → (𝑞0 , a𝑍0 ) δ(𝑞0 , b, 𝑍0 ) → (𝑞0 , b𝑍0 )
δ(𝑞0 , b, 𝑍0 ) → (𝑞0 , b𝑍0 ) δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎)
δ(𝑞0 , a, 𝑎) → (𝑞0 , a𝑎) δ(𝑞0 , b, 𝑏) → (𝑞0 , b 𝑏)
δ(𝑞0 , b, 𝑏) → (𝑞0 , b 𝑏) δ(𝑞0 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , b, 𝑎) → (𝑞0 , Λ) δ(𝑞1 , b, 𝑎) → (𝑞1 , Λ)
δ(𝑞0 , a, 𝑏) → (𝑞0 , Λ) δ(𝑞0 , a, 𝑏) → (𝑞1 , Λ)
δ(𝑞0 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 ) δ(𝑞1 , a, 𝑏) → (𝑞1 , Λ)
δ(𝑞1 , Λ, 𝑍0 ) → (𝑞𝑓 , 𝑍0 )
(a)
(b)
Transition Diagrams are as follows:

(a) (b)
Example-5: Design a PDA which accepts the language: L= {𝑎𝑛 𝑏𝑚 | 𝑚, 𝑛 ≥ 1 𝑎𝑛𝑑 𝑛 ≠ 𝑚}.

Solution:
Example-6: Design a PDA which accepts the language: L= {𝑎𝑚+𝑛 𝑏𝑚 𝑐 𝑛 | 𝑚, 𝑛 ≥ 1}.

Solution:
Example-7: Design a PDA which accepts the language: L= {𝑎𝑛 𝑏𝑚+𝑛 𝑐 𝑚 | 𝑚, 𝑛 ≥ 1}.

Solution:
Example-8: Design a PDA which accepts the language: L= {𝑎𝑛 𝑏2𝑛 | 𝑛 ≥ 1}.
Solution:
Example-9: Design a PDA which accepts the language: L= {𝑎𝑛 𝑏𝑛 𝑐 𝑚 | 𝑚, 𝑛 ≥ 1}.

Solution:
Example-10: Design a PDA which accepts the language: L= {𝑤𝑐𝑤 𝑅 | 𝑤 ∈ {𝑎, 𝑏}+ }.
Solution:
Example-11: Design a PDA which accepts the language: L= {𝑤𝑤 𝑅 | 𝑤 ∈ {𝑎, 𝑏}+ }.
Solution:
Important Point:
• PDA is a type of machine in which stack is use as a memory so it able to remember strings but in
Finite State Machine (FSM) does not have memory to remember arbitrarily strings.
• PDA is more powerful than the FSM.
Justification: Any language which can be acceptable by FSM can also be acceptable by PDA. PDA also
accepts a class of language which even cannot be accepted by FSM. Thus PDA is much more powerful
than FSM.
• NPDA (Non deterministic Pushdown Automata) and DPDA (Deterministic Pushdown Automata) are
not equivalent in power. NPDA is more powerful than DPDA which means for every language for
which a DPDA exist, there exist an NPDA but there are some languages that are accepted by NPDA
but are not accepted by DPDA.
• The two stack pushdown automata is equivalent to the Turing machines if we are only talking about
computability and not time complexity.

You might also like