You are on page 1of 52

Chapter-Six

Push Down Automata (PDA)


Outline

 Introduction to Push down Automata

 Nondeterministic Push down Automata

 Equivalence of CFG and PDA


Push Down Automata (Introduction)

 A PDA 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.
– it is more powerful than FSM
– FSM has a very limited memory but PDA has more memory
– Basically a PDA is:

"Finite state machine" + "a stack"


Cont…

 What is stack?

– A stack is a way we arrange elements one on top of


another.

– i.e the stack head scans the top symbol of the stack.

 A stack does two operations:

a. Push: a new element is added at the top of the stack.

b. Pop: the top element of the stack is read and removed.


Components of PDA

 A pushdown automaton has three components:

a) an input tape,

b) a control unit, and

c) a stack with infinite size.


 A PDA may or may not read an input symbol, but it has to
read the top of the stack in every transition
Cont…
Cont…

Note: Finite State Control

 Reads input symbol and push or pop based on the input

 finally makes transitions based on input, top of stack


Formal Definition of Pushdown Automata
 A PDA can be formally described as a 7-tuple (Q, Σ, Г, δ, q0, Z0, F):

 Q= A finite number of states


 Σ = A finite set of input alphabet
 Г =A finite stack symbols
 δ =the transition function: δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*

 q0 = the initial state (q0 ∈ Q)


 Z 0 or $= is the initial stack top symbol (z0 ∈ Г)
 F = is a set of accepting states (F ∈ Q)
Consider the various parts of δ:

Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*


– Q on the LHS means that at each step in a computation, a
PDA must consider its’ current state.
– Г on the LHS means that at each step in a computation, a
PDA must consider the symbol on top of its’ stack.
– Σ U {ε} on the LHS means that at each step in a
computation, a PDA may or may not consider the current
input symbol, i.e., it may have epsilon transitions.
Cont…

– “Finite subsets” on the RHS means that at each step in a


computation, a PDA may have several options.

– Q on the RHS means that each option specifies a new state.

– Г* on the RHS means that each option specifies zero or


more stack symbols that will replace the top stack symbol,
but in a specific sequence.
PDA Transition Function

 δ = transition function, which takes the triple: δ(q, a, X)


where

 q = state in Q

 a = input symbol in 

 X = stack symbol in Γ
Cont…

 The output of δ is the finite set of pairs (p, γ) where p is a new


state and γ is a new string of stack symbols that replaces X at
the top of the stack.
 If γ = ε then we pop the stack
 if γ = X the stack is unchanged
 if γ = YZ then X is replaced by Z and Y is pushed on the
stack. Note the new stack top is to the left end.
 If X = ε then we push on γ
PDA transition Example

 The following diagram shows a transition in a PDA from a


state q1 to state q2, labeled as a, b → c :
Cont…

 This means at state q1, if we encounter an input string ‘a’ and


top symbol of the stack is ‘b’, then we pop ‘b’, push ‘c’ on top
of the stack and move to state q2.
Examples
Cont…
Cont…
Cont…
NPDA: Non-Deterministic PDA
NPDA: Non-Deterministic PDA
Example: Construct a NPDA that accepts
Solution:
Execution Example: Time 0
Execution Example: Time 1
Execution Example: Time 2
Execution Example: Time 3
Execution Example: Time 4
Execution Example: Time 5
Execution Example: Time 6
Execution Example: Time 7
Execution Example: Time 8
The Language of PDA

 A string is accepted if there is a computation such that:


 All the input is consumed

 The last state is a final state

 At the end of the computation,

 we do not care about the stack contents


Cont…

• The input string aaabbb is accepted by the NPDA


In general,
Another NPDA example
Execution Example: Time 0
Execution Example: Time 1
Execution Example: Time 2
Execution Example: Time 3
Execution Example: Time 4
Execution Example: Time 5
Execution Example: Time 6
Rejection Example: Time 0
Rejection Example: Time 1
Rejection Example: Time 2
Rejection Example: Time 3
Rejection Example: Time 4
Rejection Example: Time 5
Equivalence of CFG and PDA

 Theorem: A language is context free iff some pushdown


automata recognize it.
 Proof:
Part I: Given a CFG, show how to construct a PDA that
recognizes it
Part II: Given a PDA, show how to construct a CFG that
recognizes the same language.
Part I: NPDAs Accept Context-Free Language
Cont…
Cont…
Converting CFG to NPDAs
Cont…

You might also like