Beruflich Dokumente
Kultur Dokumente
Introduction
New type of computational model called pushdown
automata (PDA).
This automata are like nondeterministic finite
automata but have an extra component called stack.
The stack allows pushdown automata to recognize
some nonregular languages.
PDA are equivalent in power to CFG, in terms of
recognizing the same language.
Pushdown automata
Motivation
regular
expression
NFA
syntactic
DFA
computational
CFG
pushdown automaton
syntactic
computational
NFA
input
0 1 0 0
Pushdown automata
state control
input
0 1 0 0
stack
Pushdown automata
state control
input
0 1 0 0
0 1
1
stack
$
Building a PDA
state control
push $
read 0
push x
read 1
pop x
read 1
pop x
pop $
L = {0n1n: n 1}
We remember each 0
by pushing x onto the stack
When we see a 1, we
pop an x from the stack
We want to accept when
we hit the stack bottom
Well use t$ mark bottom
A PDA in action
state control
push $
read 0
push x
read 1
pop x
read 1
pop x
pop $
L = {0n1n: n 1}
input
0 0 0 1 1 1
x x x
stack
$
push $
e, e / $
read 0
push x
read 1
pop x
read 1
pop x
pop $
q1
1, x / e
q2
10
1, x / e
e, $ / e
q3
0, e / x
Definition of a PDA
A pushdown automaton is (Q, , , , q0, F) where:
11
pop symbol
Example
q0
= {0, 1}
= {$, x}
e, e / $
q1
0, e / x
1, x / e
q2
1, x / e
e, $ / e
q3
pop symbol
A PDA is nondeterministic
Multiple transitions on same pop/input allowed
13
Example 1
L = {w#wR: w {0, 1}*}
= {0, 1, #}
= {0, 1}
#, 0#0, 01#10 L
e, 01#1, 0##0 L
q0
e, e / $
q1
#, e / e
0, e / 0
1, e / 1
q2
e, $ / e
q3
0, 0 / e
1, 1 / e
write w on stack
read wR from stack
14
Example 2
L = {wwR: w *}
= {0, 1}
e, 00, 0110 L
1, 011, 010 L
q0
e, e / $
q1
e, e / e
0, e / 0
1, e / 1
q2
e, $ / e
0, 0 / e
1, 1 / e
q3
Example 3
L = {w: w = wR, w *}
e, 1, 00, 010, 0110 L
0110110110 or 011010110
x
xR
x
xR
011 L
q0
e, e / $
= {0, 1}
q1
0, e / 0
1, e / 1
e, e / e
0, e / e
1, e / e
q2
e, $ / e
0, 0 / e
1, 1 / e
q3
Example 4
L = {0n1m0m1n | n 0, m 0}
0, e / 0
q0
e, e / $
q1
1, e / 1
e, e / e
q2
input: 0n 1m 0m 1n
e, e / e
q5
e, $ / e
q4
1, 0/ e
17
= {0, 1}
e, e / e
q3
0, 1 / e
stack: 0n 1m
Example 5
L = {w: w has same number 0s and 1s}
= {0, 1}
q0
e, e / $
0, e / 0
0, 1 / e
18
q1
e, $ / e
1, e / 1
1, 0 / e
q3
Example 5
L = {w: w has same number 0s and 1s}
= {0, 1}
q0
e, e / $
0, e / 0
0, 1 / e
q1
e, $ / e
q3
1, e / 1
1, 0 / e
Example 5
L = {w: w has same number 0s and 1s}
= {0, 1}
q0
e, e / $
0, e / 0
0, 1 / e
q1
e, $ / e
q3
1, e / 1
1, 0 / e
Example 5
L = {w: w has same number 0s and 1s}
q0
e, e / $
q1
21
q3
1, e / 1
1, 0 / e
0, e / 0
0, 1 / e
w = 001110
e, $ / e
read
stack
0
0
1
1
1
0
$0
$00
$0
$
$1
$
= {0, 1}
22
context-free grammar
23
pushdown automaton
A convention
e, e / c
x, a / b
e, e / d
x, a / bcd
q1
q1
A 0A1
AB
B#
PDA control:
e, e / A
0, 0 / e
0, 0 / e
25
stack:
input:
$A
00#11
$1A0
00#11
$1A
0#11
$11A0
0#11
$11A
#11
$11B
#11
q0
e, A / 1A0
e, A / B
e, B / #
CFG
input
stack
e, e / $A
q1
e, $ / e
q2
0, 0 / e
1, 1 / e
#, # / e
00#11
$A
00#11
$1A0
00#11
$1A
00#11
$11A0
00#11
$11A
00#11
$11B
00#11
$11#
00#11
$11
00#11
$1
00#11
$
e, A / ak...a1
q0
27
e, e / $S
q1
e, $ / e
q2