0% found this document useful (0 votes)
104 views82 pages

Module 4 PDA - Turing

The document provides an overview of Push Down Automata (PDA), detailing its structure, operations, and the hierarchy of languages it recognizes, specifically context-free languages. It explains the transition functions, stack operations, and provides examples of PDA in action, illustrating how it accepts or rejects specific strings. Additionally, it touches on Turing Machines and their significance in the hierarchy of languages.

Uploaded by

prem345472
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views82 pages

Module 4 PDA - Turing

The document provides an overview of Push Down Automata (PDA), detailing its structure, operations, and the hierarchy of languages it recognizes, specifically context-free languages. It explains the transition functions, stack operations, and provides examples of PDA in action, illustrating how it accepts or rejects specific strings. Additionally, it touches on Turing Machines and their significance in the hierarchy of languages.

Uploaded by

prem345472
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 82

Module 4

Push Down Automata


(PDA)

06/23/2025 1
Hierarchy of Languages
Recursively Enumerable Language
(Language for Turing Machine)

Context Sensitive Language


(Language for Low Bound Automata)

Context Free Language


(Language for Push Down Automata)

Regular Language
(Language for Finite
Automata)

06/23/2025 2
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}*}
06/23/2025 3
PDA Block Diagram
1) Read input symbol
Input Symbol reading 2) Perform Stack Operations
-PUSH()
Top of the stack -POP()
-Empty()
Control Unit -Read TOP
3) Make changes in states
STACK
4) Procedure is repeated until string
is scanned completely
06/23/2025 4
STACK Operations
There are THREE stack operations
1) POP() Operation 2) PUSH() Operation 3) NOP() Operation
deletes topmost inserts element at top No deletion, no
element in Stack in Stack insertion at top
TOP TOP
TOP TOP
TOP TOP
a
a a a
b b b
b b b
a a a a a a
z0 z0 z0 z0 z0 az0
Before After Before After Before After
POP() POP() PUSH() PUSH() NOP() NOP()
operation Operation operation Operation operation Operation
06/23/2025 5
Transition Function in PDA

Transition Function in PDA depends upon


1) Current State (Qi)
I/P symbol, Stack TOP /Stack Content
2) Current input (a) Qi Qj

3) TOP of stack (b) TOP


TOP
a
Input String : a, b/ ab
b b
Z0
Qi
ba Qj Z0
Stack
Stack
before
after
PUSH(a)
Transition Diagram for PUSH(a) PUSH(a)

06/23/2025 6
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
q0Initial State
z0 ϵ ┌  Stack Start Symbol
F ϵ Q Set of Final States
: Q X (Σ ᴜ {ϵ} ) X ┌  Set of Finite subsets of Q X ┌ *
06/23/2025 7
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
06/23/2025 8
• 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) ?
06/23/2025 9
06/23/2025 10
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
06/23/2025 11
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
06/23/2025 12
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
06/23/2025 13
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
TOP
The number of times
TOP TOP
TOP a push(a) is equals to pop(a)
TOP
a a a Hence count of ‘a’ is equals
Z0 to count of ‘b’
Initially Stack Z0 Z0 Z0 Z0
is empty() push(a) pop(a) pop(a)
push(a)
06/23/2025 14
PDA Example 1 continue..
Now PDA is M=(Q,Σ, ┌ , ,q0,z0,F)
q0Start State
qf Accepting State a, z0/az0 b, a/ϵ
z0Stack Initial Symbol a, a/aa
Σ={a, b}
Transition Function () b, a/ϵ ϵ, z0/z0
q0 q1 qf
1. (q0, a, z0)= (q0, az0)
2. (q0, a, a)= (q0, aa) Transition Diagram
3. (q0, b, a)= (q1, ϵ)
4. (q1, b, a)= (q1, ϵ)
5. (q1, ϵ,z0)= (qf, z0)
┌ = {z0,a}Stack Symbols
06/23/2025 15
PDA Example 1 continue..
Sample Accepting String : aabb Sample Rejecting String : abab
(q0, aabb, z0) (q0, abab, z0)
|-- (q0, abb,az0) -----push(a) |-- (q0, bab,az0) ----push(a)
|--(q0, bb, aaz0) -----push(a) |-- (q1, ab, z0) ----pop(a)
|--(q1, b, az0) -----pop(a)
|--(q1, ϵ,z0) -----pop(a) String is not processed completely
|--(qf, z0) but stack is empty.
Therefore, abab is rejected
Reached Final State with empty
stack
Therefore, aabb is accepted
06/23/2025 16
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
TOP Scan first symbol & push() into
TOP
stack, scan next symbol, push()
TOP TOP
a into stack, repeat push() until u
TOP reach middle of string, after mid
Z0 b b b
if scanning symbol is matching
Initially Stack Z0 Z0 Z0 Z0
with top of stack, do pop()
is empty() push(a) pop(a) pop(b)
push(b)
06/23/2025 17
PDA Example2 continue..
Now PDA is M=(Q,Σ, ┌, ,q0,z0,F)
a, z0/az0
q0Start State qf Accepting State b, z0/bz0
z0Stack Initial Symbol Σ={a, b} a, a/aa
Transition Function () b, b/bb a, a/ϵ
a, b/ab b, b/ϵ
1. (q0, a, z0)= (q0, az0)------ push(a)
b, a/ba
2. (q0, b, z0)= (q0, bz0)------push(b)
3. (q0, a, b)= (q0, ab)--------push(a)
4. (q0, b, a)= (q0, ba)--------push(b) ϵ, z0/z0
q0 q1 qf
5. (q0, a, a)={ (q0, aa),(q1, ϵ)}
6. (q0, b, b)= {(q0 , bb),(q1, ϵ)}
a, a/ϵ Transition Diagram
7. (q1, a, a)= (q1, ϵ)
b, b/ϵ
8. (q1, b, b)= (q1, ϵ)

9. (q1, ϵ,z0)= (qf, z0) ┌ = {z0,b,a}Stack Symbols 18


PDA Example 2 continue..
Sample Accepting String : baab Sample Rejecting String : aaab
(q0, baab, z0) (q0, aaab, z0)
|- (q0, aab,bz0) ----push(b) (q0, aab,az0) ----push(a)
(q0, ab, ab0) ----push(a) (q0, ab, aaz0) ----push(a)
(q1, b, bz0) ----pop(a) (q1, b, az0) ----pop(a)
(q1, ϵ,z0) ----pop(b) (q1, b, az0)
(qf, z0)
Reached end of string without
Reached Final State with empty empty stack
stack Therefore, aaab is rejected
Therefore, baab is accepted
06/23/2025 19
TURING MACHINES

The ACM A.M. Turing Award,


often referred to as the “Nobel
Prize in Computing,” carries a
$1 million prize with financial
support provided by Google,
Inc. The award is named for
Alan M. Turing
Dabbala Rajagopal Reddy is the only Indian to win the ACM A.M. Turing Award ,
06/23/2025 for Computer speech recognition, robotics, human-computer interaction, and innovations in higher education
20
Hierarchy of Languages
Recursively enumerable
Recursively Enumerable Language
languages are also known as type
(Language for Turing Machine)
0 languages.

Context Sensitive Language


Context-sensitive languages are
(Language for Low Bound Automata) also known as type 1 languages.

Context Free Language Context-free languages are also


(Language for Push Down Automata)
known as type 2 languages.
Regular Language
(Language for Finite Regular languages are also
Automata)
known as type 3 languages.

06/23/2025 21
A Turing
Tape Machine
...... ......

Read-Write head
Control Unit

06/23/2025 22
The Tape
No boundaries -- infinite length
...... ......

Read-Write head

The head moves Left or Right


06/23/2025 23
...... ......

Read-Write head

The head at each transition (time step):

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
06/23/2025 24
Example:
Time 0
...... a b a c ......

Time 1
...... a b k c ......

1. Reads a
2. Writes k
06/23/2025
3. Moves Left 25
Time 1
...... a b k c ......

Time 2
...... a f k c ......

1. Reads b
2. Writes f
06/23/2025
3. Moves Right 26
The Input String
Input string Blank symbol

......   a b a c    ......

head

Head starts at the leftmost position


of the input string
06/23/2025 27
States & Transitions
Read Write
Move Left

q1 a  b, L q2

Move Right

q1 a  b, R q2
06/23/2025 28
Example:
Time 1
......   a b a c    ......

q1
current state

q1 a  b, R q2
06/23/2025 29
Time
......   a b1 a c    ......

q1

Time 2
......   a b b c    ......

q2

q1 a  b, R q2
06/23/2025 30
Exampl
e: Time 1
......   a b a c    ......

q1

Time 2
......   a b b c    ......

q2

q1 a  b, L q2
06/23/2025 31
Example:
Time 1
......   a b a c    ......

q1

Time 2
......   a b a c g   ......

q2

q1   g, R q2
06/23/2025 32
Standard Turing Machine Definition
 It is defined by seven tuples:
M=(Q,Σ,,,q0,B,F)
Where, Q Set of States
Σ Set of inputs
 Finite set of symbols called tape alphabets
q0Initial State
B ϵ  Special Symbol called Blank Character
F ϵ Q Set of Final States
:Q X  Q X X {L, R}

06/23/2025 33
Turing Machine:

Input Tape
alphabet alphabet
States

M (Q, , ,  , q0 , , F )

Transition Accept
function states
Initial blank
06/23/2025 state 34
Turing Machine Example 1 n n
Turing machine for the language {a b }
n 1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L
y  y, R a  x, R b  y, L
q3 q0 q1 q2
06/23/2025
x  x, R 35
Basic Idea:
Match a’s with b’s:
Store String on Tape with head at its start
Repeat:
replace leftmost a with x
find leftmost b and replace it with y
Until there are no more a’s or b’s

If there is a remaining a or b reject


06/23/2025 36
Time 0  a a b b  

q0

q0
06/23/2025 37
Time 1  x a b b  

q1

a  x, R
q0 q1
06/23/2025 38
Time 2  x a b b  

q1

a  a, R

a  x, R
q0 q1
06/23/2025 39
a  a, R

a  x, R b  y, L
q0 q1 q2

06/23/2025 40
Time 3  x a y b  

q2

a  a, R a  a, L

a  x, R b  y, L
qq00 q1 q2
06/23/2025 41
Time 4  x a y b  

𝑞0

a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 42
Time 5  x 𝑥 y b  

𝑞1

a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 43
Time 6  x x y b  

q1

y  y, R
a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 44
Time 7  x x y 𝑦  

𝑞2

y  y, R
a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 45
Time 8  x x y y  

q2

y  y, R y  y, L
a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 46
Time 9  x x y y  

𝑞0

y  y, R y  y, L
a  a, R a  a, L

a  x, R b  y, L
q0 q1 q2
06/23/2025
x  x, R 47
Time 10  x x y y  

𝑞3

y  y, R y  y, L
a  a, R a  a, L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
06/23/2025
x  x, R 48
Time 11  x x y y  

q3

y  y, R y  y, L
y  y, R a  a, R a  a, L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
06/23/2025
x  x, R 49
Time 12  x x y y  

𝑞4

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L
y  y, R a  x, R b  y, L
q3 q0 q1 q2
06/23/2025
x  x, R 50
Time 13  x x y y  

q4
Halt & Accept

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L
y  y, R a  x, R b  y, L
q3 q0 q1 q2
06/23/2025
x  x, R 51
TM Tuples:
Q={q0,q1,q2,q3,q4}
Σ={a, b}
Ꞅ={ , a, b, x, y}
q0= Initial State
= Black Character
F= q4-> Halting State/Accepting
State
ꝺ  Transition Fucntion

06/23/2025 52
Transition Table:
Σ a b x y
Q 
->q0 (q1,x,R) - - (q3,y,R) -

q1 (q1,a,R) (q2,y,L) - (q1,y,R) -

q2 (q2,a,L) - (q0,x,R) (q2,y,L) -

q3 - - - (q3,y,R) (q4,,L)

*q4 - - - - -

06/23/2025 53
Observation:

If we modify the
n n
machine for the language {a b }

we can easily construct


n n n
a machine for the language {a b c }

06/23/2025 54
Turing Machine Example 2
Design a Turing machine for {a nb nc n }
the language n 1

06/23/2025 55
Basic Idea:
Match a’s with b’s and c’s:
Store String on Tape with head at its start
Repeat:
replace leftmost a with x
find leftmost b and replace it with y
find leftmost c and replace it with z
Until there are no more a’s or b’s or c’s

06/23/2025 If there is a remaining a or b or c reject 56


Time 0  a a b b c c  

q0

q0
06/23/2025 57
Time 1  x a b b c c  

q1

a  x, R
q0 q1
06/23/2025 58
Time 2  x a b b c c  

q1

a  a, R

a  x, R
q0 q1
06/23/2025 59
Time 3  x a y b c c  
q2

a  a, R

a  x, R b  y, R
q0 q1 q2
06/23/2025 60
Time 4  x a y b c c  

q2

a  a, R b  b, R

a  x, R b  y, R
q0 q1 q2
06/23/2025 61
Time 5  x a y b z c  

q3

a  a, R b  b, R

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025 62
Time 6  x a y b z c  

q3

a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025 63
Time 7  x a y b z c  

q3

y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025 64
Time 8  x a y b z c  

q3

a  a, L
y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025 65
Time 9  x a y b z c  

q0

a  a, L
y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 66
Time 10  x x y b z c  

q1

a  a, L
y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 67
Time 11  x x y b z c  

q1

a  a, L
y  y, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 68
Time 12  x x y y z c  
q2

a  a, L
y  y, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 69
Time 13  x x y y z c  
q2

a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 70
Time 14  x x y y z z  

q3

a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 71
Time 15  x x y y z z  

q3
z  z, L
a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 72
Time 16  x x y y z z  

q3
z  z, L
a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 73
Time 17  x x y y z z  

q3
z  z, L
a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 74
Time 18  x x y y z z  

q0

z  z, L
a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

a  x, R b  y, R c  z, L q
q0 q1 q2 3

06/23/2025
x  x, R 75
Time 19  x x y y z z  

q4
z  z, L
a  a, L
y  y, R z  z, R y  y, L
a  a, R b  b, R b  b, L

y  y, R a  x, R b  y, R c  z, L q
q4 q0 q1 q2 3

06/23/2025
x  x, R 76
Time 20  x x y y z z  

q4
z  z, L
a  a, L
y  y, R z  z, R y  y, L
y  y, R a  a, R b  b, R b  b, L

y  y, R a  x, R b  y, R c  z, L q
q4 q0 q1 q2 3

06/23/2025
x  x, R 77
Time 21  x x y y z z  

q4

z  z, L
a  a, L
z  z, R y  y, R z  z, R y  y, L
y  y, R a  a, R b  b, R b  b, L

y  y, R a  x, R b  y, R c  z, L q
q4 q0 q1 q2 3

06/23/2025
x  x, R 78
Time 22  x x y y z z  
q4

z  z, L
a  a, L
z  z, R y  y, R z  z, R y  y, L
y  y, R a  a, R b  b, R b  b, L

y  y, R a  x, R b  y, R c  z, L q
q4 q0 q1 q2 3

06/23/2025
x  x, R 79
Time 23  x x y y z z  
q5

Halt & Accept z  z, L


a  a, L
z  z, R y  y, R z  z, R
q5 y  y, L
y  y, R a  a, R b  b, R b  b, L
  , L
y  y , R a  x, R b  y, R c  z, L q
q4 q0 q1 q2 3

06/23/2025
x  x, R 80
TM Tuples:
Q={q0,q1,q2,q3,q4,q5}
Σ={a, b, c}
Ꞅ={ , a, b, c, x, y, z}
q0= Initial State
= Blank Character
F= q5-> Halting State/Accepting
State
ꝺ  Transition Function

06/23/2025 81
Transition Table:
Σ a b c x y z
Q 

->q0 (q1,x,R) - - - (q4,y,R) - -

q1 (q1,a,R) (q2,y,R) - - (q1,y,R) - -

q2 - (q2,b,R) (q3,z,L) - - (q2,z,R) -

q3 (q3,a,L) (q3,b,L) - (q0,x,R) (q3,y,L) (q3,z,L) -

q4 (q4,y,R) (q4,z,R) 
(q4, ,L)

*q5 - - - - - - -
06/23/2025 82

You might also like