SlideShare a Scribd company logo
1 of 46
1
PUSH DOWN AUTOMATA
2
Pushdown Automata (PDA)
• Informally:
– A PDA is an NFA-ε with a stack.
– Transitions are modified to accommodate stack operations.
• Questions:
– What is a stack?
– How does a stack help?
• A DFA can “remember” only a finite amount of information, whereas a PDA can
“remember” an infinite amount of (certain types of) information, in one memory-stack
3
• Example:
{0n1n | 0=<n}
is not regular, but
{0n1n | 0≤n≤k, for some fixed k} is regular, for any
fixed k.
• For k=3:
L = {ε, 01, 0011, 000111}
0/1
q
0
q
7
0 q
1
1
1
q
2
1
q
5
0 q
3
1
1
q
4
0
1
0
0
0/1
q
6
0
4
• In a DFA, each state remembers a finite amount of information.
• To get {0n1n | 0≤n} with a DFA would require an infinite number of states
using the preceding technique.
• An infinite stack solves the problem for {0n1n | 0≤n} as follows:
– Read all 0’s and place them on a stack
– Read all 1’s and match with the corresponding 0’s on the stack
• Only need two states to do this in a PDA
• Similarly for {0n1m0n+m | n,m≥0}
Push down Automata
5
6
Formal Definition of a PDA
• A pushdown automaton (PDA) is a seven-tuple:
M = (Q, Σ, Г, δ, q0, z0, F)
Q A finite set of states
Σ A finite input alphabet
Г A finite stack alphabet
q0 The initial/starting state, q0 is in Q
z0 A starting stack symbol, is in Г // need not always remain at the bottom of stack
F A set of final/accepting states, which is a subset of Q
δ A transition function, where
δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*
7
• 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.
– “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.
8
• PDA transitions:
δ(q, a, z) = {(p1,γ1), (p2,γ2),…, (pm,γm)}
– Current state is q
– Current input symbol is a
– Symbol currently on top of the stack z
– Move to state pi from q
– Replace z with γi on the stack (leftmost symbol on top)
– Move the input head to the next input symbol
:
q
p
1
p
2
p
m
a/z/ γ1
a/z/ γ2
a/z/ γm
9
• Two types of PDA transitions:
δ(q, ε, z) = {(p1,γ1), (p2,γ2),…, (pm,γm)}
– Current state is q
– Current input symbol is not considered
– Symbol currently on top of the stack z
– Move to state pi from q
– Replace z with γi on the stack (leftmost symbol on top)
– No input symbol is read
:
q
p
1
p
2
p
m
ε/z/ γ1
ε/z/ γ2
ε/z/ γm
PDA - OPERATIONS
10
POP
PUSH
Skip /
Do nothing
Construct a PDA
• Language: 0n1n, n>=0
• Transition function
δ(q0, 0, z) = {(q0, 0z)}
δ(q0, 0,00) = {(q0, 00)}
δ(q0, 1, 0) = {(q1, λ)}
δ(q1, 1, 0) = (q1, λ)}
δ(q1, λ, Z) = {(q2, λ)}
11
Instantaneous description (ID): 0011
(q0, 0 011 λ, z ) push
|- (q0, 0 11 λ, 0z) push
|- (q0, 1 1 λ, 00z) pop
|- (q1, 1 λ, 0z ) pop
|- (q1, λ, z) no -operation
|- (q2, λ, z): accept (q2 final state)
Instantaneous description (ID): 011
(q0, 0 11, z) push
|- (q0, 1 1, 0z) pop
|- (q1, 1, z ) no rule – halt at q1
reject
PDA Construction
Problem 2 : L = = {0n c 1n | n ≥ 1}
12
PDA Construction
Problem 3 : L= { a m b n c n | m, n ≥ 0} -
empy stack PDA
13
PDA Construction
14
Problem 4 : L = { wcwR | w = (0+1)* }
PDA Construction
15
Problem 5: A = { w ∈ {0, 1} ∗ | w contains at least three 1s }
L={an b3n | n>=1 }
16
Exercise
• Construct PDA for acceptance by empty stack.
1. L={a2n bn | n>=0 }
1. L = {0n1n2m3m | n>=1, m>=1}
2. L={0n1m0n | m, n>=1}.
3. L= { a i b j c k | i, j, k ≥ 0 and i + j = k }
• Construct PDA for acceptance by Final state
1. L = { a n b n c m | m, n ≥ 1 }
1. L = {0n1m2m3n | n>=1, m>=1}
2. L={an b2n | n>=0 }
– L={an b3n | n>=1 }
1. L={a3n bn | n>=0 }
17
18
• Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language
accepted by empty stack, denoted LE(M), is the set
LE(M) = {w | (q0, w, z0) |—* (p, ε, ε) for some
p in Q}
• Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language
accepted by final state, denoted LF(M), is the set
LE(M)= {w | (q0, w, z0) |—* (p, ε, γ) for some p in F and γ in
Г*}
• Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language
accepted by empty stack and final state, denoted L(M), is the set
LE(M)= {w | (q0, w, z0) |—* (p, ε, ε) for some p in F}
Language Acceptance
Equivalence of CFG and PDA
19
CFG to PDA
20
Problem 1: CFG - PDA
Convert the grammar S-> aAA, A->aS/bS/a to a PDA that accepts the same language
by empty stack
Solution :
Let G be a CFG and G=(V,T,P,S) where V={S,A} T={a,b}
p: S->aAA, A->aS/bS/a.
To find the equivalent PDA
Q={q0}
∑=T={a,b}
Г=VUT={S,A,a,b}
F=Ø
Transition function for PDA:
– For each variable S,A
δ(q0,Є,S)={(q0,aAA)}
δ(q0,Є,A)={(q0,aS),(q0,bS),(q0,a)}
For each terminal a,b
δ(q0,a,a)={q0,Є}
δ(0,b,b)={q0,Є}
21
Problem 2: CFG - PDA
• Convert the grammar S-> 0S1/A, A->1A0/S/є to a PDA that accepts the same language by
empty stack.
Solution :
Let G be a CFG and G=(V,T,P,S) where V={S,A} T={a,b}
p: S->aAA, A->aS/bS/a.
To find the equivalent PDA
Q={q0}
∑=T={0,1}
Г=VUT={S,A,0,1}
F=Ø
Transition function for PDA:
– For each variable S,A
δ(q0,Є,S)={(q0,0S1), (q0,A)}
δ(q0,Є,A)={(q0,1A0),(q0,S),(q0, Є)}
For each terminal 0,1
δ(q0,0,0)={q0,Є}
δ(q0,1,1)={q0,Є}
22
Problem 3: CFG – PDA
Construct PDA for the given CFG, and test whether 0104 is acceptable by this PDA.
S → 0BB B → 0S | 1S | 0
23
Solution:
The PDA can be given as:
1.A = {(q), (0, 1), (S, B, 0, 1), δ, q, S, ?}
The production rule δ can be:
R1: δ(q, ε, S) = {(q, 0BB)}
R2: δ(q, ε, B) = {(q, 0S) | (q, 1S) | (q, 0)}
R3: δ(q, 0, 0) = {(q, ε)}
R4: δ(q, 1, 1) = {(q, ε)}
Testing 0104 i.e. 010000 against PDA:
δ(q, 010000, S) ⊢ δ(q, 010000, 0BB)
⊢ δ(q, 10000, BB) R1
⊢ δ(q, 10000,1SB) R3
⊢ δ(q, 0000, SB) R2
⊢ δ(q, 0000, 0BBB) R1
⊢ δ(q, 000, BBB) R3
⊢ δ(q, 000, 0BB) R2
⊢ δ(q, 00, BB) R3
⊢ δ(q, 00, 0B) R2
⊢ δ(q, 0, B) R3
⊢ δ(q, 0, 0) R2
⊢ δ(q, ε) R3
ACCEPT
Thus 0104 is accepted by the PDA.
24
CFG to PDA conversion
Formally, the given PDA is
M = (Q, Σ, Г, δ, q0, z0, F). Define CFG G=(V,
T, P, S), where
V=[p x q] for all p & q Є Q and x Є Σ,
T= Σ,
P=Set of Production rules constructed from δ
And S=Starting Symbol
Rules to construct P using δ
R1 – Production Rules for S
S 🡪 [q0 z0 p] for all p Є Q
R2 – Production Rules corresponding to the
transition move for pop operation
(q, a, z) = (p, ϵ)
[q z p] 🡪a
Cont…
R3 - Production Rules corresponding to the
transition move for push and read operation
(q, a, z) = (q’, z1z2…….zn)
[q z p] 🡪 a [q’ z1 q1] [q1 z2 q2] ………[qn zn p]
Convert the following PDA in to a CFG
27
Example 1
28
Rule 1 Rule 2
Rule 3
Cont…
29
Cont…
30
Example 2 PDA TO CFG
31
Consider the given PDA and convert it to pda
δ(p,0,z)=(p,A)
δ(0,0,a)=(p,AA)
δ (p,1,A)=(q, λ)
δ (q,1,A)=(q, λ)
Solution:
EQUIVELANCE OF CFG AND
PDA
32
Final State to Empty Stack PDA
33
(p0, w,X0) |- (q0, w, Z0X0) |-* (q, ε , αX0) |- ( p, ε ,ε )
Example : Design a PDA to check for well-formed parentheses
Empty Stack to Final State PDA
34
(p0, w,X0) |- (q0, w, Z0X0) |-* (q, ε , X0) |- ( pf, ε ,ε )
Example : Design a PDA to check for well-formed parentheses
Deterministic Pushdown automata
DPDA- definition
35
Example - DPDA
36
Is Npda more powerful
than DPDA?
• Power of NPDA is more than DPDA. It is
not possible to convert every NPDA to
corresponding DPDA. ... The languages
accepted by DPDA are called DCFL
(Deterministic Context Free Languages)
which are subset of NCFL (Non
Deterministic CFL) accepted by NPDA
37
Difference between DPDA and
NDPA
38
Closure Properties of Context
Free Grammar
Context-free languages are closed under −
•Union- If L1 and L2 are CFL’s then L1ꓴL2 is
also CFL.
•Concatenation- If L1 and L2 are CFL’s then
L1L2 is also CFL.
•Kleene Star- If L1 is CFL then L*1 is also
CFL.
Closure under Union
• Begin with two grammars: G1 = (V1, Σ , P1, S1) and G2
= (V2, Σ , P2, S2), generating CFL’s L1 and L2
respectively.
• The new CFG Gx is made as:
– Σ remains the same
– Sx is the new start variable
– Vx = V1 ∪ V2 ∪ {Sx}
– Px = P1 ∪ P2 ∪ {Sx → S1|S2}
• Explanation: All we have done is augment the variable
set with a new start state and then allowed the new start
state to map to either of the two grammars. So, we’ll
generate strings from either L1 or L2, i.e. L1 ꓴ L2
Example
• Let L1 = { anbn , n > 0}. Corresponding
grammar G1 will have P: S1 → aAb|ab
• Let L2 = { cmdm , m ≥ 0}. Corresponding
grammar G2 will have P: S2 → cBb| ε
• Union of L1 and L2, L = L1 ∪ L2 = { anbn } ∪
{ cmdm }
• The corresponding grammar G will have the
additional production S → S1 | S2
Closure under Concatenation
• Begin with two grammars: G1 = (V1, Σ , P1, S1) and G2 =
(V2, Σ , P2, S2), generating CFL’s L1 and L2 respectively.
• The new CFG Gy is made as:
– Σ remains the same
– Sy is the new start variable
– Vy = V1 ꓴ V2 ꓴ {Sy}
– Py = P1 ꓴ P2 ꓴ {Sx → S1S2}
• Explanation: Again, all we have done is to augment the
variable set with a new start state, and then allowed the
new start state to map to the concatenation of the two
original start symbols. So, we will generate strings that
begin with strings from L1 and end with strings from L2,
i.e. L1L2 .
Example
• Let L1 = { anbn , n > 0}. Corresponding
grammar G1 will have P: S1 → aAb|ab
• Let L2 = { cmdm , m ≥ 0}. Corresponding
grammar G2 will have P: S2 → cBb| ε
• Concatenation of the languages L1 and L2, L =
L1L2 = { anbncmdm }
• The corresponding grammar G will have the
additional production S → S1 S2
Clouser under Kleene Star
• Begin with two grammars: G1 = (V1, Σ , P1, S1) and
G2 = (V2, Σ , P2, S2), generating CFL’s L1 and L2
respectively.
• The new CFG Gz is made as:
– Σ remains the same
– Sz is the new start variable
– Vz = V1 ꓴ {Sz}
– Pz = P1 ꓴ {Sz → S1Sz | ε}
• Explanation: Again we have augmented the variable
set with a new start state, and then allowed the new
start state to map to either S1Sz or ε. This means we
can generate strings with zero or more strings made
from expanding the variable S1, i.e. L*1 .
Example
• Let L = { anbn , n ≥ 0}. Corresponding
grammar G will have P: S → aAb| ε
• Kleene Star L1 = { anbn }*
• The corresponding grammar G1 will have
additional productions S1 → SS1 | ε
Context-free languages are not closed under −
•Intersection − If L1 and L2 are context free
languages, then L1 ∩ L2 is not necessarily
context free.
•Intersection with Regular Language − If L1 is a
regular language and L2 is a context free
language, then L1 ∩ L2 is a context free
language.
•Complement − If L1 is a context free language,
then L1’ may not be context free.

More Related Content

What's hot

Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machinesAYESHA JAVED
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDAAshish Duggal
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithmMegha Sharma
 
AI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAndrew Ferlitsch
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)Sagar Kumar
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptarunsingh660
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR Zahid Parvez
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing ThesisHemant Sharma
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
Unit3:Informed and Uninformed search
Unit3:Informed and Uninformed searchUnit3:Informed and Uninformed search
Unit3:Informed and Uninformed searchTekendra Nath Yogi
 

What's hot (20)

NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Informed search
Informed searchInformed search
Informed search
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machines
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
 
AI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAI - Local Search - Hill Climbing
AI - Local Search - Hill Climbing
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing Thesis
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Unit3:Informed and Uninformed search
Unit3:Informed and Uninformed searchUnit3:Informed and Uninformed search
Unit3:Informed and Uninformed search
 

Similar to Automata theory - Push Down Automata (PDA)

Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).pptssuser47f7f2
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.pptRohitPaul71
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdfshruti533256
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automataeugenesri
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automataparmeet834
 
PushdownAutomata.ppt
PushdownAutomata.pptPushdownAutomata.ppt
PushdownAutomata.pptRSRS39
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Srimatre K
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsRushabh2428
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguagesissbp
 
Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata parmeet834
 

Similar to Automata theory - Push Down Automata (PDA) (20)

Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).ppt
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.ppt
 
Finite automata
Finite automataFinite automata
Finite automata
 
PDA (1) (1).pptx
PDA (1) (1).pptxPDA (1) (1).pptx
PDA (1) (1).pptx
 
Pda
PdaPda
Pda
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
 
Dfa
DfaDfa
Dfa
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Push down automata
Push down automataPush down automata
Push down automata
 
PushdownAutomata.ppt
PushdownAutomata.pptPushdownAutomata.ppt
PushdownAutomata.ppt
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Introduction_to_PDA.pptx
Introduction_to_PDA.pptxIntroduction_to_PDA.pptx
Introduction_to_PDA.pptx
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
 
automata problems
automata problemsautomata problems
automata problems
 
Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata
 

More from Akila Krishnamoorthy

More from Akila Krishnamoorthy (13)

Automata Theory - Turing machine
Automata Theory - Turing machineAutomata Theory - Turing machine
Automata Theory - Turing machine
 
Automata theory - RE to DFA Conversion
Automata theory - RE to DFA ConversionAutomata theory - RE to DFA Conversion
Automata theory - RE to DFA Conversion
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
 
Automata theory - NFA ε to DFA Conversion
Automata theory - NFA ε to DFA ConversionAutomata theory - NFA ε to DFA Conversion
Automata theory - NFA ε to DFA Conversion
 
Automata theory - NFA to DFA Conversion
Automata theory - NFA to DFA ConversionAutomata theory - NFA to DFA Conversion
Automata theory - NFA to DFA Conversion
 
Automata theory -- NFA and DFA construction
Automata theory -- NFA and DFA  constructionAutomata theory -- NFA and DFA  construction
Automata theory -- NFA and DFA construction
 
Intro to automata theory
Intro to automata theoryIntro to automata theory
Intro to automata theory
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfa
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Slr parser
Slr parserSlr parser
Slr parser
 
CLR AND LALR PARSER
CLR AND LALR PARSERCLR AND LALR PARSER
CLR AND LALR PARSER
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Keypoints c strings
Keypoints   c stringsKeypoints   c strings
Keypoints c strings
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 

Automata theory - Push Down Automata (PDA)

  • 2. 2 Pushdown Automata (PDA) • Informally: – A PDA is an NFA-ε with a stack. – Transitions are modified to accommodate stack operations. • Questions: – What is a stack? – How does a stack help? • A DFA can “remember” only a finite amount of information, whereas a PDA can “remember” an infinite amount of (certain types of) information, in one memory-stack
  • 3. 3 • Example: {0n1n | 0=<n} is not regular, but {0n1n | 0≤n≤k, for some fixed k} is regular, for any fixed k. • For k=3: L = {ε, 01, 0011, 000111} 0/1 q 0 q 7 0 q 1 1 1 q 2 1 q 5 0 q 3 1 1 q 4 0 1 0 0 0/1 q 6 0
  • 4. 4 • In a DFA, each state remembers a finite amount of information. • To get {0n1n | 0≤n} with a DFA would require an infinite number of states using the preceding technique. • An infinite stack solves the problem for {0n1n | 0≤n} as follows: – Read all 0’s and place them on a stack – Read all 1’s and match with the corresponding 0’s on the stack • Only need two states to do this in a PDA • Similarly for {0n1m0n+m | n,m≥0}
  • 6. 6 Formal Definition of a PDA • A pushdown automaton (PDA) is a seven-tuple: M = (Q, Σ, Г, δ, q0, z0, F) Q A finite set of states Σ A finite input alphabet Г A finite stack alphabet q0 The initial/starting state, q0 is in Q z0 A starting stack symbol, is in Г // need not always remain at the bottom of stack F A set of final/accepting states, which is a subset of Q δ A transition function, where δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*
  • 7. 7 • 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. – “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.
  • 8. 8 • PDA transitions: δ(q, a, z) = {(p1,γ1), (p2,γ2),…, (pm,γm)} – Current state is q – Current input symbol is a – Symbol currently on top of the stack z – Move to state pi from q – Replace z with γi on the stack (leftmost symbol on top) – Move the input head to the next input symbol : q p 1 p 2 p m a/z/ γ1 a/z/ γ2 a/z/ γm
  • 9. 9 • Two types of PDA transitions: δ(q, ε, z) = {(p1,γ1), (p2,γ2),…, (pm,γm)} – Current state is q – Current input symbol is not considered – Symbol currently on top of the stack z – Move to state pi from q – Replace z with γi on the stack (leftmost symbol on top) – No input symbol is read : q p 1 p 2 p m ε/z/ γ1 ε/z/ γ2 ε/z/ γm
  • 11. Construct a PDA • Language: 0n1n, n>=0 • Transition function δ(q0, 0, z) = {(q0, 0z)} δ(q0, 0,00) = {(q0, 00)} δ(q0, 1, 0) = {(q1, λ)} δ(q1, 1, 0) = (q1, λ)} δ(q1, λ, Z) = {(q2, λ)} 11 Instantaneous description (ID): 0011 (q0, 0 011 λ, z ) push |- (q0, 0 11 λ, 0z) push |- (q0, 1 1 λ, 00z) pop |- (q1, 1 λ, 0z ) pop |- (q1, λ, z) no -operation |- (q2, λ, z): accept (q2 final state) Instantaneous description (ID): 011 (q0, 0 11, z) push |- (q0, 1 1, 0z) pop |- (q1, 1, z ) no rule – halt at q1 reject
  • 12. PDA Construction Problem 2 : L = = {0n c 1n | n ≥ 1} 12
  • 13. PDA Construction Problem 3 : L= { a m b n c n | m, n ≥ 0} - empy stack PDA 13
  • 14. PDA Construction 14 Problem 4 : L = { wcwR | w = (0+1)* }
  • 15. PDA Construction 15 Problem 5: A = { w ∈ {0, 1} ∗ | w contains at least three 1s }
  • 16. L={an b3n | n>=1 } 16
  • 17. Exercise • Construct PDA for acceptance by empty stack. 1. L={a2n bn | n>=0 } 1. L = {0n1n2m3m | n>=1, m>=1} 2. L={0n1m0n | m, n>=1}. 3. L= { a i b j c k | i, j, k ≥ 0 and i + j = k } • Construct PDA for acceptance by Final state 1. L = { a n b n c m | m, n ≥ 1 } 1. L = {0n1m2m3n | n>=1, m>=1} 2. L={an b2n | n>=0 } – L={an b3n | n>=1 } 1. L={a3n bn | n>=0 } 17
  • 18. 18 • Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language accepted by empty stack, denoted LE(M), is the set LE(M) = {w | (q0, w, z0) |—* (p, ε, ε) for some p in Q} • Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language accepted by final state, denoted LF(M), is the set LE(M)= {w | (q0, w, z0) |—* (p, ε, γ) for some p in F and γ in Г*} • Definition: Let M = (Q, Σ, Г, δ, q0, z0, F) be a PDA. The language accepted by empty stack and final state, denoted L(M), is the set LE(M)= {w | (q0, w, z0) |—* (p, ε, ε) for some p in F} Language Acceptance
  • 19. Equivalence of CFG and PDA 19
  • 21. Problem 1: CFG - PDA Convert the grammar S-> aAA, A->aS/bS/a to a PDA that accepts the same language by empty stack Solution : Let G be a CFG and G=(V,T,P,S) where V={S,A} T={a,b} p: S->aAA, A->aS/bS/a. To find the equivalent PDA Q={q0} ∑=T={a,b} Г=VUT={S,A,a,b} F=Ø Transition function for PDA: – For each variable S,A δ(q0,Є,S)={(q0,aAA)} δ(q0,Є,A)={(q0,aS),(q0,bS),(q0,a)} For each terminal a,b δ(q0,a,a)={q0,Є} δ(0,b,b)={q0,Є} 21
  • 22. Problem 2: CFG - PDA • Convert the grammar S-> 0S1/A, A->1A0/S/є to a PDA that accepts the same language by empty stack. Solution : Let G be a CFG and G=(V,T,P,S) where V={S,A} T={a,b} p: S->aAA, A->aS/bS/a. To find the equivalent PDA Q={q0} ∑=T={0,1} Г=VUT={S,A,0,1} F=Ø Transition function for PDA: – For each variable S,A δ(q0,Є,S)={(q0,0S1), (q0,A)} δ(q0,Є,A)={(q0,1A0),(q0,S),(q0, Є)} For each terminal 0,1 δ(q0,0,0)={q0,Є} δ(q0,1,1)={q0,Є} 22
  • 23. Problem 3: CFG – PDA Construct PDA for the given CFG, and test whether 0104 is acceptable by this PDA. S → 0BB B → 0S | 1S | 0 23 Solution: The PDA can be given as: 1.A = {(q), (0, 1), (S, B, 0, 1), δ, q, S, ?} The production rule δ can be: R1: δ(q, ε, S) = {(q, 0BB)} R2: δ(q, ε, B) = {(q, 0S) | (q, 1S) | (q, 0)} R3: δ(q, 0, 0) = {(q, ε)} R4: δ(q, 1, 1) = {(q, ε)} Testing 0104 i.e. 010000 against PDA: δ(q, 010000, S) ⊢ δ(q, 010000, 0BB) ⊢ δ(q, 10000, BB) R1 ⊢ δ(q, 10000,1SB) R3 ⊢ δ(q, 0000, SB) R2 ⊢ δ(q, 0000, 0BBB) R1 ⊢ δ(q, 000, BBB) R3 ⊢ δ(q, 000, 0BB) R2 ⊢ δ(q, 00, BB) R3 ⊢ δ(q, 00, 0B) R2 ⊢ δ(q, 0, B) R3 ⊢ δ(q, 0, 0) R2 ⊢ δ(q, ε) R3 ACCEPT Thus 0104 is accepted by the PDA.
  • 24. 24 CFG to PDA conversion Formally, the given PDA is M = (Q, Σ, Г, δ, q0, z0, F). Define CFG G=(V, T, P, S), where V=[p x q] for all p & q Є Q and x Є Σ, T= Σ, P=Set of Production rules constructed from δ And S=Starting Symbol
  • 25. Rules to construct P using δ R1 – Production Rules for S S 🡪 [q0 z0 p] for all p Є Q R2 – Production Rules corresponding to the transition move for pop operation (q, a, z) = (p, ϵ) [q z p] 🡪a
  • 26. Cont… R3 - Production Rules corresponding to the transition move for push and read operation (q, a, z) = (q’, z1z2…….zn) [q z p] 🡪 a [q’ z1 q1] [q1 z2 q2] ………[qn zn p]
  • 27. Convert the following PDA in to a CFG 27 Example 1
  • 28. 28 Rule 1 Rule 2 Rule 3
  • 31. Example 2 PDA TO CFG 31 Consider the given PDA and convert it to pda δ(p,0,z)=(p,A) δ(0,0,a)=(p,AA) δ (p,1,A)=(q, λ) δ (q,1,A)=(q, λ) Solution:
  • 32. EQUIVELANCE OF CFG AND PDA 32
  • 33. Final State to Empty Stack PDA 33 (p0, w,X0) |- (q0, w, Z0X0) |-* (q, ε , αX0) |- ( p, ε ,ε ) Example : Design a PDA to check for well-formed parentheses
  • 34. Empty Stack to Final State PDA 34 (p0, w,X0) |- (q0, w, Z0X0) |-* (q, ε , X0) |- ( pf, ε ,ε ) Example : Design a PDA to check for well-formed parentheses
  • 37. Is Npda more powerful than DPDA? • Power of NPDA is more than DPDA. It is not possible to convert every NPDA to corresponding DPDA. ... The languages accepted by DPDA are called DCFL (Deterministic Context Free Languages) which are subset of NCFL (Non Deterministic CFL) accepted by NPDA 37
  • 38. Difference between DPDA and NDPA 38
  • 39. Closure Properties of Context Free Grammar Context-free languages are closed under − •Union- If L1 and L2 are CFL’s then L1ꓴL2 is also CFL. •Concatenation- If L1 and L2 are CFL’s then L1L2 is also CFL. •Kleene Star- If L1 is CFL then L*1 is also CFL.
  • 40. Closure under Union • Begin with two grammars: G1 = (V1, Σ , P1, S1) and G2 = (V2, Σ , P2, S2), generating CFL’s L1 and L2 respectively. • The new CFG Gx is made as: – Σ remains the same – Sx is the new start variable – Vx = V1 ∪ V2 ∪ {Sx} – Px = P1 ∪ P2 ∪ {Sx → S1|S2} • Explanation: All we have done is augment the variable set with a new start state and then allowed the new start state to map to either of the two grammars. So, we’ll generate strings from either L1 or L2, i.e. L1 ꓴ L2
  • 41. Example • Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have P: S1 → aAb|ab • Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have P: S2 → cBb| ε • Union of L1 and L2, L = L1 ∪ L2 = { anbn } ∪ { cmdm } • The corresponding grammar G will have the additional production S → S1 | S2
  • 42. Closure under Concatenation • Begin with two grammars: G1 = (V1, Σ , P1, S1) and G2 = (V2, Σ , P2, S2), generating CFL’s L1 and L2 respectively. • The new CFG Gy is made as: – Σ remains the same – Sy is the new start variable – Vy = V1 ꓴ V2 ꓴ {Sy} – Py = P1 ꓴ P2 ꓴ {Sx → S1S2} • Explanation: Again, all we have done is to augment the variable set with a new start state, and then allowed the new start state to map to the concatenation of the two original start symbols. So, we will generate strings that begin with strings from L1 and end with strings from L2, i.e. L1L2 .
  • 43. Example • Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have P: S1 → aAb|ab • Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have P: S2 → cBb| ε • Concatenation of the languages L1 and L2, L = L1L2 = { anbncmdm } • The corresponding grammar G will have the additional production S → S1 S2
  • 44. Clouser under Kleene Star • Begin with two grammars: G1 = (V1, Σ , P1, S1) and G2 = (V2, Σ , P2, S2), generating CFL’s L1 and L2 respectively. • The new CFG Gz is made as: – Σ remains the same – Sz is the new start variable – Vz = V1 ꓴ {Sz} – Pz = P1 ꓴ {Sz → S1Sz | ε} • Explanation: Again we have augmented the variable set with a new start state, and then allowed the new start state to map to either S1Sz or ε. This means we can generate strings with zero or more strings made from expanding the variable S1, i.e. L*1 .
  • 45. Example • Let L = { anbn , n ≥ 0}. Corresponding grammar G will have P: S → aAb| ε • Kleene Star L1 = { anbn }* • The corresponding grammar G1 will have additional productions S1 → SS1 | ε
  • 46. Context-free languages are not closed under − •Intersection − If L1 and L2 are context free languages, then L1 ∩ L2 is not necessarily context free. •Intersection with Regular Language − If L1 is a regular language and L2 is a context free language, then L1 ∩ L2 is a context free language. •Complement − If L1 is a context free language, then L1’ may not be context free.