Download - Pushdown automata
![Page 1: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/1.jpg)
Pushdown Pushdown AutomataAutomataPDAsPDAs
![Page 2: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/2.jpg)
Pushdown Automaton -- Pushdown Automaton -- PDAPDA Input String
Stack
States
![Page 3: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/3.jpg)
Initial Stack SymbolInitial Stack Symbol
Stack
$
Stack
z
bottomspecial symbol
![Page 4: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/4.jpg)
The StatesThe States
q1 q2a, b c
Inputsymbol
Popsymbol
Pushsymbol
![Page 5: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/5.jpg)
q1 q2a, b c
a
b top
input
stack
a
Replaceeh
$eh
$
c
![Page 6: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/6.jpg)
q1 q2a, c
a a
Pushb
eh
$eh
$
bc
top
input
stack
![Page 7: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/7.jpg)
q1 q2a, b
a a
Popb
eh
$eh
$
top
input
stack
![Page 8: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/8.jpg)
q1 q2a,
a a
No Changeb
eh
$eh
$
btop
input
stack
![Page 9: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/9.jpg)
Non-DeterminismNon-Determinism
q1
q2a, b c
q3a, b c
q1 q2, b c
transition
These are allowed transitions in a Non-deterministic PDA (NPDA)
![Page 10: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/10.jpg)
NPDA: Non-NPDA: Non-Deterministic PDADeterministic PDA
Example:
,
a, a
b, a q0 q1 q2 q3
b, a
, $ $
![Page 11: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/11.jpg)
a, a
b, a 0q q1 q2 q3
Execution Example:
Input
a a a b b b
currentstate
b, a
Time 0
, , $ $
Stack
$
![Page 12: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/12.jpg)
a, a
b, a q0 q1 q2 q3
Input
a a a b b b
b, a
Time 1
, , $ $
Stack
$
![Page 13: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/13.jpg)
a, a
b, a q0 q1 q2 q3
Input
Stack
a a a b b b
$
a
b, a
Time 2
, , $ $
![Page 14: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/14.jpg)
a, a
b, a q0 q1 q2 q3
Input
Stack
a a a b b b$
aa
b, a
Time 3
, , $ $
![Page 15: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/15.jpg)
a, a
b, a q0 q1 q2 q3
Input
Stack
a a a b b b
$
aaa
b, a
Time 4
, , $ $
![Page 16: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/16.jpg)
a, a
b, a q0 q1 q2 q3
Input
a a a b b b
Stack
$
aaa
b, a
Time 5
, , $ $
![Page 17: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/17.jpg)
a, a
b, a q0 q1 q2 q3
Input
a a a b b b$
a
Stack
b, a
Time 6
, , $ $
a
![Page 18: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/18.jpg)
a, a
b, a q0 q1 q2 q3
Input
a a a b b b$
Stack
b, a
Time 7
, , $ $
a
![Page 19: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/19.jpg)
a, a
b, a q0 q1 q2 q3
Input
a a a b b b
b, a
Time 8
accept, , $ $
$
Stack
![Page 20: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/20.jpg)
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
The Language of PDA
![Page 21: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/21.jpg)
Formal DefinitionFormal DefinitionNon-Deterministic Pushdown Automaton NPDA
),,,δ,Γ,Σ,( 0 FzqQM
States
Inputalphabet
Stackalphabet
Transitionfunction
Finalstates
Stackstartsymbol
Initialstate
![Page 22: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/22.jpg)
Instantaneous Instantaneous DescriptionDescription
),,( suq
Currentstate Remaining
input
Currentstackcontents
![Page 23: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/23.jpg)
Acceptance by Final Acceptance by Final StateState
L(M)= set of all strings w such that starting L(M)= set of all strings w such that starting from initial ID machine consumes w from from initial ID machine consumes w from input and enters an accepting state.input and enters an accepting state.
The contents of the stack at that time is The contents of the stack at that time is irrelevant.irrelevant.
{w | (q0, w, Z){w | (q0, w, Z)** (q, (q, , , ))For some final state q of F and any stack For some final state q of F and any stack
staring staring ..
![Page 24: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/24.jpg)
Acceptance by empty Acceptance by empty stack stack
N(M) = (w | (q0,w,Z) N(M) = (w | (q0,w,Z) * * (q,(q, ,, ))
That is N(M) is the set of all strings w such That is N(M) is the set of all strings w such that M can consume w and at the same that M can consume w and at the same time empties its stack.Here we do not time empties its stack.Here we do not care whether q is a final state or not.care whether q is a final state or not.
![Page 25: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/25.jpg)
The input stringis accepted by the NPDA:
aaabbb
a, a
b, a q0 q1 q2 q3
b, a
, , $ $
![Page 26: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/26.jpg)
}0:{ nbaL nn
is the language accepted by the NPDA:
a, a
b, a q0 q1 q2 q3
b, a
In general,
, , $ $
![Page 27: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/27.jpg)
Another NPDA exampleAnother NPDA example
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
NPDA M
}{)( RwwML
![Page 28: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/28.jpg)
Execution Example:
Input
Time 0
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
a ab b
![Page 29: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/29.jpg)
Input
a ab
Time 1
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
![Page 30: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/30.jpg)
Input
Time 2
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
![Page 31: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/31.jpg)
Input
Time 3
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
Guess the middle of string
![Page 32: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/32.jpg)
Input
Time 4
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
![Page 33: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/33.jpg)
Input
Time 5
Stack
$
, $ $1q q2
bb
aa
,
,
, q0
bb
aa
,
,
a ab b a
![Page 34: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/34.jpg)
Input
Time 6
Stack
$
, $ $q1
bb
aa
,
,
, q0
bb
aa
,
,
a ab b
accept
q2
![Page 35: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/35.jpg)
Rejection Example:
Input
Time 0
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
a b b b
![Page 36: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/36.jpg)
Input
Time 1
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
![Page 37: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/37.jpg)
Input
Time 2
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
a b b b
![Page 38: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/38.jpg)
Input
Time 3
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
Guess the middle of string
a b b b
![Page 39: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/39.jpg)
Input
Time 4
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
a b b b
![Page 40: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/40.jpg)
Input
Time 5
Stack
$
, $ $1q q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
There is no possible transition.
Input is not consumed
![Page 41: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/41.jpg)
Another computation on same string:
Input Time 0
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
a b b b
![Page 42: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/42.jpg)
Input
Time 1
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
![Page 43: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/43.jpg)
Input
Time 2
Stack
$
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
a b b b
![Page 44: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/44.jpg)
Input
Time 3
Stack
$ab
a b b b
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
b
![Page 45: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/45.jpg)
Input
Time 4
Stack
a b b b
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
$abbb
![Page 46: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/46.jpg)
Input
Time 5
Stack
a b b b
$abbb
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
No final state is reached
![Page 47: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/47.jpg)
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
There is no computation that accepts string abbb
)(MLabbb
![Page 48: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/48.jpg)
Pushing StringsPushing Strings
q1 q2a, b w
Inputsymbol
Popsymbol
Pushstring
![Page 49: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/49.jpg)
q1 q2a, b cdf
a
b top
input
stack
a
Push
eh h
e
cdf
pushedstring
Example:
$ $
![Page 50: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/50.jpg)
Another NPDA exampleAnother NPDA example
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
NPDA M
}:{)( ba nnwML
![Page 51: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/51.jpg)
Time 0
Input
a ab b b
currentstate
a
$
Stack
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
Execution Example:
![Page 52: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/52.jpg)
Time 1
Input
a ab b ba
$
Stack
0
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
![Page 53: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/53.jpg)
Time 3
Input
a bb b a
$
Stack
a
$
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
0
![Page 54: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/54.jpg)
Time 4
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
![Page 55: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/55.jpg)
Time 5
Input
a bb b a
$
Stack
a
11
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
![Page 56: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/56.jpg)
Time 6
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
1
![Page 57: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/57.jpg)
Time 7
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
![Page 58: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/58.jpg)
Time 8
Input
a bb b a a
$
Stack
$$, q1 q2
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
accept
![Page 59: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/59.jpg)
Formalities for Formalities for NPDAsNPDAs
![Page 60: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/60.jpg)
q1 q2a, b w
)},{(),,( 21 wqbaq
Transition function:
![Page 61: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/61.jpg)
q1
q2wba ,
q3wba ,
)},(),,{(),,( 321 wqwqbaq
Transition function:
![Page 62: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/62.jpg)
Formal DefinitionFormal DefinitionNon-Deterministic Pushdown Automaton NPDA
),,,δ,Γ,Σ,( 0 FzqQM
States
Inputalphabet
Stackalphabet
Transitionfunction
Finalstates
Stackstartsymbol
Initialstate
![Page 63: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/63.jpg)
Instantaneous Instantaneous DescriptionDescription
),,( suq
Currentstate Remaining
input
Currentstackcontents
![Page 64: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/64.jpg)
a, a
b, a q0 q1 q2 q3
Input
Stack
a a a b b b$
aa
b, a
Time 4:
, , $ $
Example: Instantaneous Description
$),,( 1 aaabbbq
a
![Page 65: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/65.jpg)
a, a
b, a q0 q1 q2 q3
Input
Stack
a a a b b b$
aa
b, a
Time 5:
, , $ $
Example: Instantaneous Description
$),,( 2 aabbq
a
![Page 66: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/66.jpg)
We write:
$),,($),,( 21 aabbqaaabbbq
Time 4 Time 5
![Page 67: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/67.jpg)
a, a
b, a q0 q1 q2 q3
b, a
, , $ $
,$),(,$),($),,($),,(
$),,($),,($),,(
,$),(,$),(
3222
111
10
qqabqaabbq
aaabbbqaaabbbqaaabbbq
aaabbbqaaabbbq
A computation:
![Page 68: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/68.jpg)
,$),(,$),($),,($),,(
$),,($),,($),,(
,$),(,$),(
3222
111
10
qqabqaabbq
aaabbbqaaabbbqaaabbbq
aaabbbqaaabbbq
For convenience we write:
,$),(,$),( 30 qaaabbbq
![Page 69: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/69.jpg)
Formal DefinitionFormal DefinitionLanguage of NPDA :M
)}',,(),,(:{)( 0 sqswqwML f
Initial state Final state
![Page 70: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/70.jpg)
Example:,$),(,$),( 30 qaaabbbq
a, a
b, a q0 q1 q2 q3
b, a
, , $ $
NPDA :M
)(MLaaabbb
![Page 71: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/71.jpg)
,$),(,$),( 30 qbaq nn
a, a
b, a q0 q1 q2 q3
b, a
, , $ $
NPDA :M
)(MLba nn
![Page 72: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/72.jpg)
a, a
b, a q0 q1 q2 q3
b, a
, , $ $
NPDA :M
}0:{)( nbaML nnTherefore:
![Page 73: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/73.jpg)
NPDAs Accept NPDAs Accept Context-Free Context-Free LanguagesLanguages
![Page 74: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/74.jpg)
Context-Free
Languages(Grammars)
LanguagesAccepted
byNPDAs
Theorem:
![Page 75: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/75.jpg)
Context-Free
Languages(Grammars)
LanguagesAccepted
byNPDAs
Proof - Step 1:
Convert any context-free grammar to a NPDA with:
GM )()( MLGL
![Page 76: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/76.jpg)
Context-Free
Languages(Grammars)
LanguagesAccepted
byNPDAs
Proof - Step 2:
Convert any NPDA to a context-free grammar with: G
M)()( MLGL
![Page 77: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/77.jpg)
ConvertingConverting Context-Free Context-Free GrammarsGrammarsto to NPDAsNPDAs
![Page 78: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/78.jpg)
An example grammar:
T
TaT
bS
aSTbS
What is the equivalent NPDA?
![Page 79: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/79.jpg)
q0 q1 2qS, , $ $
Grammar:
NPDA:
T
TaT
bS
aSTbS
,
,
,
,
T
TaT
bS
aSTbS
bb
aa
,
,
![Page 80: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/80.jpg)
The NPDA simulates leftmost derivations of the grammar
L(Grammar) = L(NPDA)
![Page 81: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/81.jpg)
Grammar:
T
TaT
bS
aSTbS
A leftmost derivation:
abababTababTbaSTbS
![Page 82: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/82.jpg)
NPDA execution:
0q q1 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 0
b
currentstate
![Page 83: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/83.jpg)
q0 q1 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 1
b
S
![Page 84: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/84.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 2
b
a
b
ST
q1
![Page 85: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/85.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 3
b
a
b
ST
q1
![Page 86: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/86.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 4
b
bTb
q1
![Page 87: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/87.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 5
b
bTb
q1
![Page 88: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/88.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 6
b
b
Ta
q1
![Page 89: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/89.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 7
b
b
Ta
q1
![Page 90: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/90.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 8
b
ba
q1
![Page 91: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/91.jpg)
q0 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 9
b
b
q1
![Page 92: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/92.jpg)
q0 q1 2qS, , $ $
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 10
b
accept
![Page 93: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/93.jpg)
In general:
Given any grammar G
We can construct a NPDA M
With )()( MLGL
![Page 94: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/94.jpg)
Constructing NPDA from grammar :
q0 q1 2qS, , $ $
wA, aa,
M
For any production
wAFor any terminal
a
G
![Page 95: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/95.jpg)
Grammar generates string G w
if and only if
NPDA acceptsM w
)()( MLGL
![Page 96: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/96.jpg)
Therefore:
For any context-free languagethere is an NPDAthat accepts the same language
![Page 97: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/97.jpg)
ConvertingConverting NPDAsNPDAstotoContext-Free Context-Free GrammarsGrammars
![Page 98: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/98.jpg)
For any NPDA M
we will construct
a context-free grammar withG
)()( GLML
![Page 99: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/99.jpg)
Intuition:
G
The grammar simulates the machine
A derivation in Grammar :
abcABCabcS
Current configuration in NPDA M
![Page 100: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/100.jpg)
in NPDA M
abcABCabcS
Input processed Stack contents
terminals variables
GA derivation in Grammar :
![Page 101: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/101.jpg)
Some Necessary Some Necessary Modifications Modifications First, we modify the NPDA:
• It has a single final state• It empties the stack when it accepts the input
Original NPDA Empty Stack
fq
fq
![Page 102: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/102.jpg)
Second, we modify the NPDA transitions:
all transitions will have form
iq jqBa,
or
iq jqCDBa ,
symbolsstack :,, DCB
![Page 103: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/103.jpg)
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
}:{)( ba nnwML
Example of a NPDA in correct form:
symbolstack initial :$
![Page 104: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/104.jpg)
The Grammar The Grammar ConstructionConstruction
)( jiBqq
In grammar :G
Terminals:Input symbols of NPDA
states
Stack symbol
Variables:
![Page 105: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/105.jpg)
iq jqBa,For each transition
We add production aBqq ji )(
![Page 106: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/106.jpg)
For each transition
We add production ))(()( klljki DqqCqqaBqq
iq jqCDBa ,
For all states lk qq ,
![Page 107: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/107.jpg)
Start Variable: )$( fo qq
Stack bottom symbol
Start state final state
![Page 108: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/108.jpg)
Example:
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
aqq )1( 00Grammar production:
![Page 109: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/109.jpg)
Example:
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
Grammar productions:
![Page 110: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/110.jpg)
Example:
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
Grammar production: )$( 0 fqq
![Page 111: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/111.jpg)
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)1)(1(|)1)(1()1(
)1)(1(|)1)(1()1(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)$)(0(|)$)(0()$(
)$)(0(|)$)(0()$(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
Resulting Grammar: ablestart vari:)$( 0 fqq
![Page 112: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/112.jpg)
)0)(0(|)0)(0()0(
)0)(0(|)0)(0()0(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
bqq
aqq
)0(
)1(
00
00
)$( 0 fqq
![Page 113: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/113.jpg)
Derivation of string abba
)$( 0 fqq )$)(0( 000 fqqqqa
)$( 0 fqqab
)$)(1( 000 fqqqqabb
)$( 0 fqqabba abba
![Page 114: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/114.jpg)
In general, in Grammar:
wqq f
)$( 0
if and only if
w is accepted by the NPDA
![Page 115: Pushdown automata](https://reader036.vdocuments.us/reader036/viewer/2022081720/548cad88b4795936648b4684/html5/thumbnails/115.jpg)
Explanation:
By construction of Grammar:
wAqq ji
)(
if and only if
in the NPDA going from tothe stack doesn’t change belowand is removed from stack
iq jq
AA