2. 04/29/2025 2
Hierarchy of Languages
Regular Language
(Language for Finite
Automata)
Context Free Language
(Language for Push Down Automata)
Context Sensitive Language
(Language for Low Bound Automata)
Recursively Enumerable Language
(Language for Turing Machine)
3. 04/29/2025 3
Push Down Automata(PDA)
It is a Finite Automata with STACK
An added stack provides memory and increases the capacity
of machine
A context free grammar is recognized by PDA
Hence the language accepted by PDA is context free
language
Ex: L(G)={ : n >=0}
L(G)={w : w ϵ {a, b}*}
4. 04/29/2025 4
PDA Block Diagram
1) Read input symbol
2) Perform Stack Operations
-PUSH()
-POP()
-Empty()
-Read TOP
3) Make changes in states
4) Procedure is repeated until string
is scanned completely
Input Symbol reading
Control Unit
Top of the stack
STACK
5. 04/29/2025 5
STACK Operations
1) POP() Operation
deletes topmost
element in Stack
2) PUSH() Operation
inserts element at top
in Stack
a
b
a
z0
a
b
a
z0
3) NOP() Operation
No deletion, no
insertion at top
There are THREE stack operations
a
b
a
z0
a
b
a
az0
b
a
z0
b
a
z0
Before
POP()
operation
After
POP()
Operation
TOP
TOP
TOP
TOP
TOP
TOP
Before
PUSH()
operation
Before
NOP()
operation
After
PUSH()
Operation
After
NOP()
Operation
6. 04/29/2025 6
Transition Function in PDA
Transition Function in PDA depends upon
1) Current State (Qi)
2) Current input (a)
3) TOP of stack (b)
Input String :
ba
Qi Qj
I/P symbol,
Qi Qj
a,
a
b
Z0
b
Z0
Transition Diagram for PUSH(a)
Stack
before
PUSH(a)
Stack
after
PUSH(a)
TOP
TOP
Stack TOP/Stack Content
b/ ab
7. 04/29/2025 7
Non-deterministic PDA Definition
It is defined by seven tuples:
M=(Q,Σ, ┌, ,q0,z0,F)
Where, Q Set of States
Σ Set of input
┌ Finite set of stack symbols
q0Initial State
z0 ϵ ┌ Stack Start Symbol
F ϵ Q Set of Final States
: Q X (Σ ᴜ {ϵ} ) X ┌ Set of Finite subsets of Q X ┌ *
8. 04/29/2025 8
Transitions
• Transition Function accepts three parameters namely state, input symbol
and stack symbol and returns a new state after changing the top of the stack
δ(state, input symbol, stack symbol)=(next state, stack symbol)
• Eg 1: δ(P, a , z) = (Q, az)
Means PDA in current state P and after reading a with z on top of the stack
PDA enters into new state Q pushing a on to the stack
• Eg 2: δ(P, a , z) = (Q, ∈)
Means PDA in current state P and after reading a with z on top of the stack
PDA enters into new state Q popping z out of the stack
9. 04/29/2025 9
• Eg 3: δ(P, a , z) = (Q, a)
• Means PDA in current state P and after reading a with z on top of the stack PDA
enters into new state Q and z is popped out and a is pushed in
• Eg 4: δ(P, ∈ , b) = (P, ∈ )
Means PDA in current state P and without accepting any input symbol and b on top
of the stack, b is popped out from the stack and PDA remains in the same state P
Practice
δ(A, 1 , z) = (A, 1) ?
δ(Q, ∈ , 0) = (Q, ∈) ?
δ(P, b , z) = (R, bz) ?
11. 04/29/2025 11
Transition Function in PDA
Transition Function is based on
i) Current State
ii) Input Symbol (including ϵ)
iii) Top of the stack
a) Read input with NOP() operation on Stack:
(q1, b, a) = (q2, a)
q1 Current state
b Current Input
a Top of the stack
q2 Next State
12. 04/29/2025 12
Transition Function in PDA continue..
b) Read input with POP() operation on Stack:
(q1, b, a) = (q2, ϵ)
q1 Current state
b Current Input
a Top of the stack
q2 Next State
c) Read input with PUSH() operation on Stack:
(q1, a, b) = (q2, ab)
q1 Current state
a Current Input
b Top of the stack
q2 Next State
13. 04/29/2025 13
Instantaneous Description of PDA
• Current configuration of PDA at any given instant is the instantaneous description
(ID)
ID is defined as triplet (q,w,α)
q current state
w remaining string to be processed
α is the current contents of the stack
Eg. If string is aabb
(q0,aabb,z0)
Ⱶ (q0,abb,az0)
Ⱶ (q0,bb,aaz0) etc
14. 04/29/2025 14
PDA Example 1
1) Obtain PDA to accept language L(G)={ : n>=1, Σ={a, b}* }
Solution:
Accepting Strings={ab, aabb, aaabbb, aaaabbbb,……}
Rejecting Strings={a,b,aab,baa,abab,aabbb,……}
Let sample String is aabb
Z0
Initially Stack
is empty()
TOP
a
Z0
push(a)
TOP
a
a
Z0
push(a)
TOP
a
Z0
pop(a)
TOP
Z0
pop(a)
TOP
The number of times
push(a) is equals to pop(a)
Hence count of ‘a’ is equals
to count of ‘b’
15. 04/29/2025 15
PDA Example 1 continue..
Now PDA is M=(Q,Σ, ┌ , ,q0,z0,F)
q0Start State
qf Accepting State
z0Stack Initial Symbol
Σ={a, b}
Transition Function ()
1. (q0, a, z0)= (q0, az0)
2. (q0, a, a)= (q0, aa)
3. (q0, b, a)= (q1, ϵ)
4. (q1, b, a)= (q1, ϵ)
5. (q1, ϵ,z0)= (qf, z0)
┌ = {z0,a}Stack Symbols
q0
a, z0/az0
a, a/aa
ϵ, z0/z0
qf
Transition Diagram
q1
b, a/ϵ
b, a/ϵ
16. 04/29/2025 16
PDA Example 1 continue..
Sample Accepting String : aabb
(q0, aabb, z0)
|-- (q0, abb,az0) -----push(a)
|--(q0, bb, aaz0) -----push(a)
|--(q1, b, az0) -----pop(a)
|--(q1, ϵ,z0) -----pop(a)
|--(qf, z0)
Reached Final State with empty
stack
Therefore, aabb is accepted
Sample Rejecting String : abab
(q0, abab, z0)
|-- (q0, bab,az0) ----push(a)
|-- (q1, ab, z0) ----pop(a)
String is not processed completely
but stack is empty.
Therefore, abab is rejected
17. 04/29/2025 17
PDA Example2
3) Obtain NPDA to accept language L(G)={w : w ϵ {a, b}*}
Solution:
Accepting Strings={aa , bb , abba , baab , abbbba , abaaba , ……}
Rejecting Strings={a, b , aba , bab ,aab , baa , abab, aabbb,……}
Let sample String is baab
Z0
Initially Stack
is empty()
TOP
b
Z0
push(b)
TOP
b
Z0
pop(a)
TOP
push(a)
TOP
Scan first symbol & push() into
stack, scan next symbol, push()
into stack, repeat push() until u
reach middle of string, after mid
if scanning symbol is matching
with top of stack, do pop()
Z0
TOP
pop(b)
a
b
Z0
18. 18
PDA Example2 continue..
Now PDA is M=(Q,Σ, ┌, ,q0,z0,F)
q0Start State qf Accepting State
z0Stack Initial Symbol Σ={a, b}
Transition Function ()
1. (q0, a, z0)= (q0, az0)------ push(a)
2. (q0, b, z0)= (q0, bz0)------push(b)
3. (q0, a, b)= (q0, ab)--------push(a)
4. (q0, b, a)= (q0, ba)--------push(b)
5. (q0, a, a)={ (q0, aa),(q1, ϵ)}
6. (q0, b, b)= {(q0 , bb),(q1, ϵ)}
7. (q1, a, a)= (q1, ϵ)
8. (q1, b, b)= (q1, ϵ)
9. (q1, ϵ,z0)= (qf, z0) ┌= {z0,b,a}Stack Symbols
q1
a, a/ϵ
b, b/ϵ
ϵ, z0/z0
qf
Transition Diagram
q0
a, z0/az0
b, z0/bz0
a, a/aa
b, b/bb
a, b/ab
b, a/ba
a, a/ϵ
b, b/ϵ
19. 04/29/2025 19
PDA Example 2 continue..
Sample Accepting String : baab
(q0, baab, z0)
|- (q0, aab,bz0) ----push(b)
(q0, ab, ab0) ----push(a)
(q1, b, bz0) ----pop(a)
(q1, ϵ,z0) ----pop(b)
(qf, z0)
Reached Final State with empty
stack
Therefore, baab is accepted
Sample Rejecting String : aaab
(q0, aaab, z0)
(q0, aab,az0) ----push(a)
(q0, ab, aaz0) ----push(a)
(q1, b, az0) ----pop(a)
(q1, b, az0)
Reached end of string without
empty stack
Therefore, aaab is rejected