TOC Lecture 13
TOC Lecture 13
Pushdown Automata
Introduction
• A Pushdown Automata (PDA) is a way to implement a Context Free
Grammar in a similar way we design Finite Automata for Regular
Grammar.
• FSM has very limited memory but PDA has more memory.
= transition function
q0 = initial state
Pushdown Automata
a,b/c
q0 q1
Symbol on top
This symbol is
Input of the Stack.
pushed onto
symbol. This symbol is
the stack.
popped.
PDA: Graphical Notation
0
0, 1 / 01
q0 q1 1 1
Push 0
z0 z0
0, 1 /
q0 q1 1
Pop
z0 z0
0, 1 / 1
q0 q1 1
Neither
1
z0 z0
Push
nor Pop
PDA: Graphical Notation
0, 1 / 0
q0 q1 1 0
Pop 1
z0 z0
Push 0
0, 1 / 00 0
q0 q1 1 0
Pop 1
z0 z0
Push 00
a
a a a
z0 z0 z0 z0 z0
1 q0 aabb$ z0 q0
2 q0 aabb$ δ(q0, a, z0) = (q0, a z0) a z0 q0
3 q0 aabb$ δ(q0, a, a) = (q0, a a) a a z0 q0
4 q0 aabb$ δ(q0, b, a) = (q1, ) a z0 q1
5 q1 aabb$ δ(q1, b, a) = (q1, ) z0 q1
6 q1 aabb$ δ(q1, $, z0) = (q2, ) q2
PDA: Transition Diagram
• Design a pushdown automata for language {an bn | n > 0}
Instantaneous Description
a, z0 / az0
a, a / aaz0 b, a / (q0, aabb$, z0) ⊢ (q0, abb$, az0)
⊢ (q0, bb$, aaz0)
⊢ (q0, b$, az0)
$, z0 /
q0 q1 q2 ⊢ (q0, $, z0)
⊢ (q0, , )
PDA: Instantaneous Description (ID)
• ID is an informal notation of how a PDA computes an input string
and make a decision that string is accepted or rejected.
• Turnstile Notation:
⊢ sign describes the turnstile notation and represents one move.
⊢* sign describes a sequence of moves.
• Example: ( p , b , T ) ⊢ ( q , w , α )
Question
• Design a PDA that accepts L = {wcwR | w {0 + 1}*}
• Solution:
a, z0 / az0 a, a /
b, z0 / bz0 b, b /
c, a / a
c, b / b $, z0 /
q0 q1 q2
a, a / aa
a, b / ab
b, a / ba
b, b / bb
PDA: Acceptance
1. Acceptance by Final State: The PDA is said to accept its input by
the final state if it enters any final state in zero or more moves
after reading the entire input.
– Let P = (Q, ∑, Γ, δ, q0, z0, F) be a PDA. The language acceptable by
the final state can be defined as:
q2 q2
q1 q1
q3 q3
q2 q2
q1 q1
q3 q3
Example
• Design an NPDA for the language L = {wwR | w {0 + 1}+}
• Solution:
a, z0 / az0 a, a /
b, z0 / bz0 b, b /
a, a /
b, b / $, z0 /
q0 q1 q2
a, a / aa
a, b / ab
b, a / ba
b, b / bb
DPDA Vs. NPDA
• The languages accepted by DPDA are called Deterministic
Context Free Languages (DCFL).