pushdown automata (pda) - swarthmore collegesindhu/cs46/s16/pdadesign.pdf · pushdown automata...
TRANSCRIPT
![Page 1: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/1.jpg)
Pushdown Automata (PDA)
state control
00011111000
a
a
b
a
stack
input
![Page 2: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/2.jpg)
Pushdown Automata (PDA)If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push y, advance read head
q2a, x → y
q1
If a = ℇ do not advance read headIf x = ℇ do not read from stackIf y = ℇ do not write to stack
![Page 3: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/3.jpg)
When does a PDA accept a string?
r1w1q0 r2
w2 qfwn
input: w1w2…wn
…w3
accept if any branch accepts
![Page 4: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/4.jpg)
Pushdown Automata (PDA)
(Q, Σ, Γ, δ, q0, F) δ: Q × Σℇ × Γℇ → !(Q × Γℇ)
q2a, x → y
q1
q3
a, x → z
![Page 5: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/5.jpg)
TheoremsNot every nondeterministic PDA has an equivalent deterministic PDA
A language is context-free iff some PDA recognizes it
![Page 6: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/6.jpg)
CFL vs.
Regular Languages
![Page 7: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/7.jpg)
CFL vs. Regular Languages
PDA to NFA
![Page 8: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/8.jpg)
CFL vs. Regular Languages
NFA to PDA
q2q1a
![Page 9: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/9.jpg)
CFL vs. Regular Languages
NFA to PDA
q2a, ℇ → ℇ
q1
![Page 10: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/10.jpg)
PDA Design Examples
![Page 11: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/11.jpg)
PDA Design {0n1n | n ≥ 0}
![Page 12: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/12.jpg)
stack
input: 000111
{0n1n | n ≥ 0}
![Page 13: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/13.jpg)
q20, ℇ → 0
stack
input: 000111
{0n1n | n ≥ 0}
![Page 14: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/14.jpg)
q20, ℇ → 0
stack
input: 000111
0
{0n1n | n ≥ 0}
![Page 15: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/15.jpg)
q20, ℇ → 0
stack
0
0
input: 000111
{0n1n | n ≥ 0}
![Page 16: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/16.jpg)
q20, ℇ → 0
stack
0
0
0
input: 000111
{0n1n | n ≥ 0}
![Page 17: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/17.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
stack
0
0
0
input: 000111
{0n1n | n ≥ 0}
![Page 18: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/18.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
stack
0
0
input: 000111
{0n1n | n ≥ 0}
![Page 19: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/19.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
stack
0
input: 000111
{0n1n | n ≥ 0}
![Page 20: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/20.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
stack
input: 000111
{0n1n | n ≥ 0}
![Page 21: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/21.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
stack
input: 000111_
{0n1n | n ≥ 0}
![Page 22: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/22.jpg)
q2
q3
1, 0 → ℇ
1, 0 → ℇ
0, ℇ → 0
Does this work?
{0n1n | n ≥ 0}
![Page 23: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/23.jpg)
q2
q3q4
ℇ, ℇ → $
1, 0 → ℇ
ℇ, $ → ℇ 1, 0 → ℇ
q10, ℇ → 0
{0n1n | n ≥ 0}
![Page 24: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/24.jpg)
PDA Design {wwR | w ∈ {0, 1}*}
![Page 25: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/25.jpg)
q2
q3q4
ℇ, ℇ → $
ℇ, ℇ → ℇ
ℇ, $ → ℇ
q1
0, ℇ → 0 1, ℇ → 1
0, 0 → ℇ 1, 1 → ℇ
{wwR | w ∈ {0, 1}*}
![Page 26: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/26.jpg)
PDA Design {aibjck | i, j, k ≥ 0 and i = j or j = k}
![Page 27: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/27.jpg)
q2
q3
ℇ, ℇ → ℇ
a, ℇ → a
b, a → ℇ
{aibjck | i, j, k ≥ 0 and i = j}
q4
ℇ, ℇ → $
ℇ, $ → ℇ
q1
c, ℇ → ℇ
![Page 28: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/28.jpg)
r2
r3
ℇ, ℇ → ℇ
a, ℇ → ℇ
b, ℇ → b
{aibjck | i, j, k ≥ 0 and j = k}
r5
ℇ, ℇ → $
ℇ, $ → ℇ
r1
r4
ℇ, ℇ → ℇ
c, b → ℇ
![Page 29: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/29.jpg)
r2
r3
ℇ, ℇ → ℇ
a, ℇ → ℇ
b, ℇ → b
{aibjck | i, j, k ≥ 0 and i=j or j = k}
r5
ℇ, ℇ → $
ℇ, $ → ℇ
q1
r4
ℇ, ℇ → ℇ
c, b → ℇ
q2
q3
ℇ, ℇ → ℇ
a, ℇ → a
b, a → ℇ
q4
ℇ, $ → ℇ
c, ℇ → ℇ
ℇ, ℇ → $r1
![Page 30: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/30.jpg)
q2
q3
ℇ, ℇ → ℇ
a, ℇ → ℇ
b, ℇ → b
{aibjck | i, j, k ≥ 0 and i=j or j = k}
q4
ℇ, ℇ → $
ℇ, $ → ℇ
q1
q3
ℇ, ℇ → ℇ
c, b → ℇ
q2
q3
ℇ, ℇ → ℇ
a, ℇ → a
b, a → ℇ
q4
ℇ, $ → ℇ
c, ℇ → ℇ
ℇ, ℇ → $
![Page 31: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/31.jpg)
Pumping Lemma: Regular Languages
If A is a regular language,then there is a pumping length p stif s ∈ A with |s| ≥ p then we can write s = xyz so that
• ∀i ≥ 0 xyiz ∈ A• |y| > 0 • |xy| ≤ p
![Page 32: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/32.jpg)
To prove {0n1n | n ≥ 0} is not regular using the Pumping Lemma
1. Suppose {0n1n | n ≥ 0} is regular2. Call its pumping length p3. Find string s ∈ A with |s| ≥ p. Let s = 0p1p
4. The pumping lemma says that for some split 0p1p = xyz all the following conditions hold
• ∀i ≥ 0 xyiz ∈ A • |y| > 0 • |xy| ≤ p
⇒ y is a non-empty string of 0s
![Page 33: Pushdown Automata (PDA) - Swarthmore Collegesindhu/cs46/s16/PDADesign.pdf · Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push](https://reader030.vdocuments.us/reader030/viewer/2022013114/5d213d9c88c993ea218dc05c/html5/thumbnails/33.jpg)
To prove A is not regular using the Pumping Lemma
1. Suppose A is regular 2. Call its pumping length p 3. Find string s ∈ A with |s| ≥ p 4. The pumping lemma says that for some split
s = xyz all the following conditions hold • ∀i ≥ 0 xyiz ∈ A • |y| > 0 • |xy| ≤ p