Professional Documents
Culture Documents
Automata
BS Course
Slide # : 06
2
Pushdown Automaton (PDA)
P Q, , , ( qi , a, m ) ( qk , n ),..., q0 , 0 , F
Q: A finite set of states.
S : A finite set of input symbols.
G: A finite stack alphabet.
d: The transition function with input:
qi is a state in Q.
a is a symbol in S or a = e (the empty string).
tm is a stack symbol, tm Î G.
and the output is a finite set of pairs:
qk the new state.
tn is the string of stack symbols that replaces tm at the top of the stack. If
tn = e, then the stack is popped.
q0: The start state.
t0 : Initially, the PDA’s stack consists this symbol and nothing else.
F : The set of accepting states. 3
PDA Example: Lwwr {wwR | w (0 1)*}
The language, Lwwr, is the even-length palindromes over alphabet
{0,1}.
S 0S 0 | 1S1 |
4) ( q1 ,0,0) ( q1 , ) ( q1 ,1,1) ( q1 , )
5) ( q1 , , 0 ) ( q2 , 0 )
6) ( q2 , Read_Past_ End_Of_Input, 0 ) ( q3 , 0 )
5
A Graphical Notation for PDA’s
1. The nodes correspond to the states of the PDA.
2. An arrow labeled Start indicates the unique start state.
3. Doubly circled states are accepting states.
4. Edges correspond to transitions in the PDA as follows:
5. An edge labeled (ai, t m)/tn from state q to state p means
that d(q, ai, tm) contains the pair (p, tn), perhaps among
other pairs.
6
Graphical Notation
(0, 0)/00
for PDA of L wwr
(0, 1)/01 (0,0)/ε
(0, (1, 0)/10 (1,1)/ε
t0)/0t0 (1, 1)/11
(1,
start
t0)/1t0 (ε,t0) / t0
q0 q1 q2
(ε, t0) /
t0
(ε, 0) / 0
(EOF,t0) / t0
(ε, have
All possibilities that do not 1) / 1explicit
edges, have implicit edges that go to an
implicit reject state.
q3
• This is a nondeterministic machine.
• Think of the machine as following all possible paths.
• Kill a path if it leads to a reject state.
• If any path leads to an accept state, then the machine accepts.
7
Exercise 1
PDA
M
:
L( M ) {a b : n 0}
n n
a, a b, a
q0 , q1 b, a q2 , $ $ q3
8
L( M ) {a b : n 0}
n n
Basic Idea:
a, a b, a
q0 , q1 b, a q2 , $ $ q3
9
Execution Example: Time 0
Input
a a a b b b
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
10
Time 1
Input
a a a b b b
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
11
Time 2
Input
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
12
Time 3
Input
a
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
13
Time 4
Input
a
a
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
14
Time 5
Input
a
a
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
15
Time 6
Input
a
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
16
Time 7
Input
a a a b b b a
$
Stack
a, a b, a
q0 , q1 b, a q2 , $ $ q3
17
Time 8
Input
a a a b b b
$
Stack
a, a b, a
accept
q0 , q1 b, a q2 , $ $ q3
18
Rejection Example: Time 0
Input
a a b
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
19
Rejection Example: Time 1
Input
a a b
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
20
Rejection Example: Time 2
Input
a a b a
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
21
Rejection Example: Time 3
Input a
a a b a
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
22
Rejection Example: Time 4
Input a
a a b a
$
Stack
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
23
Rejection Example: Time 4
Input a
a a b a
$
Stack
reject
current
state
a, a b, a
q0 , q1 b, a q2 , $ $ q3
24
Exercise 2
In the PDA, let ‘i’ stands for ‘if’ and ‘e’ stands for ‘else’.
25
Exercise 3
Design a PDA to accept the language:
{a b c | i j or j k }
i j k
26