Pushdown Automata
description
Transcript of Pushdown Automata
![Page 1: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/1.jpg)
Lecture Pushdown Automata
![Page 2: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/2.jpg)
stack
stack head
finitecontrol
tape head
tape
![Page 3: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/3.jpg)
The tape is divided into finitely many cells. Each cell contains a symbol in an alphabet Σ.
a l p h a b e t
![Page 4: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/4.jpg)
The stack head always scans the topsymbol of the stack. It performs two basic operations:
Push: add a new symbol at the top.
Pop: read and remove the top symbol.
Alphabet of stack symbols: Γ
![Page 5: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/5.jpg)
• The head scans at a cell on the tape and can read a symbol on the cell. In each move, the head can move to the right cell.
a
![Page 6: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/6.jpg)
• The finite control has finitely many states which form a set Q. For each move, the state is changed according to the evaluation of a transition function
δ : Q x (Σ U {ε}) x (Γ U {ε}) → 2 .Q x (Γ U {ε})
![Page 7: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/7.jpg)
• (p, u) δ(q, a, v) means that if the tape head reads a, the stack head read v, and the finite control is in the state q, then one of possible moves is that the next state is p, v is replaced by u at stack, and the tape head moves one cell to the right.
pq
a a
v u
![Page 8: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/8.jpg)
• (p, u) δ(q, ε, v) means that this a ε-move.
pq
a
v u
a
![Page 9: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/9.jpg)
• (p, u) δ(q, a, ε) means that a push operation
performs at stack.
pq
a a
u
![Page 10: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/10.jpg)
• (p, ε) δ(q, a, v) means that a pop operation performs at stack
pq
a a
v
![Page 11: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/11.jpg)
• There are some special states: an initial state s and a final set F of final states.
• Initially, the PDA is in the initial state s and the head scans the leftmost cell. The tape holds an input string. The stack is empty.
s
![Page 12: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/12.jpg)
• When the head gets off the tape, the PDA stops. An input string x is accepted by the PDA if the PDA stops at a final state and the stack is empty.
• Otherwise, the input string is rejected.
f
x
![Page 13: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/13.jpg)
• The PDA can be represented by
M = (Q, Σ, Γ, δ, s, F)
where Σ is the alphabet of input symbols and Γ is the alphabet of stack symbols.
• The set of all strings accepted by a PDA M is denoted by L(M). We also say that the language L(M) is accepted by M.
![Page 14: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/14.jpg)
• The transition diagram of a PDA is an alternative way to represent the PDA.
• For M = (Q, Σ, Γ, δ, s, F), the transition diagram of M is an edge-labeled digraph G=(V, E) satisfying the following:
V = Q (s = , f = for f F)
E = { q p | (p,u) δ(q, a, v) }.
a, v/u
![Page 15: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/15.jpg)
Example 1. Construct PDA to accept L= {0 1 | n > 0}n n
Solution 1.
0, ε/0
1, 0/ε
1, 0/ε
![Page 16: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/16.jpg)
Solution 2.
Consider a CFG G = ({S}, {0,1}, {S → ε | 0S1}, S).
ε, ε/S ε, ε/S
ε, S/ε
ε, ε/0
ε, S/1
0, 0/ε
1, 1/ε
![Page 17: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/17.jpg)
Theorem Every CFL can be accepted by a PDA.
Proof. Consider a CFL L = L(G) for a CFG G = (V, Σ, R, S).
ε, ε/S
a, a/ε for a in Σ
ε, A/xn A → x1 x2 …xn in R
ε, ε/x1
PDA. aby accepted becan it CFL is languageA L
Theorem
![Page 18: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/18.jpg)
Sometimes, constructing the PDA is easier thanconstructing CFG.
![Page 19: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/19.jpg)
CFL a is )}(#2)(#)(# |},{{ that Show xxxbax bab
Construct a PDA or a CFG?
PDA!!!
Sometimes, constructing the PDA is easier thanconstructing CFG.
Example 2
![Page 20: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/20.jpg)
Idea
accepted! be would string
input theexists, choicecorrect a as long As : trouble thissolves
ncomputatio nisticnondetermi ofconcept theNo, on?cancellati
each at choice ticdeterminis a make toneed weDo . two
sometimes and one sometimes cancel toneed we,each For
. with cancel toneed we),(#2)(#)( ifcheck To
x
a
ab
baxxx# bab
![Page 21: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/21.jpg)
• (p, s) δ(s, ε, ε)
ps
a
s
a
s/,
![Page 22: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/22.jpg)
(q, s) δ(p, a, s)
pp
a
a
a
ssa /,
ss
(p, a) δ(q, ε, ε)
a/,
![Page 23: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/23.jpg)
(q1, a) δ(p, a, a)
pp
a
a
a
aaa /,
aa
(p, a) δ(q1, ε, ε)
a/,
![Page 24: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/24.jpg)
(p, ε) δ(p, a, b)
pp
a a
b
/,ba
![Page 25: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/25.jpg)
(p, b’) δ(p, a, b)
pp
a a
b
'/, bba
b’
![Page 26: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/26.jpg)
(p, ε) δ(p, a, b’)
pp
a a
b’
/',ba
![Page 27: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/27.jpg)
(r1, s) δ(p, b, s)
pp
b
b
b
ssb /,
ss
(p, b) δ(r1, ε, ε)
b/,
![Page 28: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/28.jpg)
(r2, b) δ(p, b, b)
pp
b
b
b
bbb /,
bb
(p, b) δ(r2, ε, ε)
b/,
![Page 29: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/29.jpg)
(r3, b’) δ(p, b, b’)
pp
b
b
b
'/', bbb
b’b’
(p, b) δ(r3, ε, ε)
b/,
![Page 30: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/30.jpg)
(p, ε) δ(p, b, a)
pp
b b
a
/,ab
![Page 31: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/31.jpg)
(t, ε) δ(p, b, a)
pp
b b
/,ab
a
(p, ε) δ(t, ε, a)
/,a
a
![Page 32: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/32.jpg)
(t, ε) δ(p, b, a)
pp
b b
/,ab
a
(u, x) δ(t, ε, x)
/',b
z z≠a z
b’
(p, b’) δ(u, ε, ε)
az
zz
/,
![Page 33: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/33.jpg)
(p, ε) δ(p, ε, s)
pp
s
/, s
![Page 34: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/34.jpg)
s/,
a/,
zza /,
',bbz
/',ba
'/, bba
/,ba
b/,
az zzb /,
/,ab
/,ab
/,azz /,
'/, baz
/, s
![Page 35: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/35.jpg)
)}.(#2)(#)(# |},{{ acceptingPDA Construct xxxbax bab
job. thedo first Let the
.' twocancel which a havemust we),(#)(# have To
b
sabxx ab
Idea
Example 3
![Page 36: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/36.jpg)
1s/,
a/,
zza /,
',bbz
/',ba
'/, bba
/,ba
b/,
az zzb /,
/,ab
/,ab
/,azz /,
'/, baz
/, s
Solution'/, bba
/,ab /,a'/, b
zz /,az
1
1zza /,
',bbz
a/,
1zzb /,az
b/,
![Page 37: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/37.jpg)
)}.(#2)(#)(# |},{{ acceptingPDA Construct xxxbax bab
job. thedo first Let the
. one cancel which a havemust we),(#2)(# have To
b
abxx ba
Idea
Example 4
![Page 38: Pushdown Automata](https://reader035.fdocument.org/reader035/viewer/2022062216/563db7e0550346aa9a8ec660/html5/thumbnails/38.jpg)
1s/,
a/,
zza /,
',bbz
/',ba
/,ba
/,ba
b/,
az zzb /,
/,ab
/,ab
/,azz /,
'/, baz
/, s
Solution'/, bba
1
1zza /,
',bbz
a/,
1zzb /,az
b/,
/,ab