Professional Documents
Culture Documents
b,pop(a)
1 2
Example. {anbn : n>= 0}
a,push(a) b,pop(a)
b,pop(a)
1 2
State Stack IInput
1 l aaabbb
1 a aabbb
1 aa abbb
1 aaa bbb
2 aa bb
2 a b
2 l l
Example. {a b
n n : n>= 0}
a,push(a) b,pop(a)
b,pop(a)
1 2
State Stack IInput
1 l aaaabbb
1 a aaabbb
1 aa aabbb
1 aaa abbb
1 aaaa bbb
2 aaa bb
2 aa b
2 a l
Example. {a b
n n : n>= 0}
a,push(a) b,pop(a)
b,pop(a)
1 2
State Stack IInput
1 l aabbb
1 a abbb
1 aa bbb
2 a bb
2 l b
Example. {wcwR : w in {a,b}*}
c, iignore
1 2
a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Example. {wcwR : w in {a,b}*}
c, iignore
1 2
a,pop(a)
a,push(a) b,oop(b) State Stack IInput
b,push(b)
1 l abbcbba
1 a bbcbba
1 ab bcbbz
1 abb cbba
2 abb bba
2 ab ba
2 a a
2 l l
Non Determinism is key!
An automaton that recognizes strings of a’s and b’s. that have an a in
the middle.
a, iignore
1 2
a,pop(1)
a,push(1) b,oop(1)
b,push(1)
Example. {wwR : w in {a,b}*}
l, iignore
1
2
a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Example. {w : w in {a,b}*, w=w }
R
???
1 2
a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Strings of a’s and b’s that have the same
number of a’s and b’s
l,push($) l,pop($)
s q f
a,pushOn(a,a)
a,pushOn($,a)
a,pop(b)
b,pushOn(b,b)
b,pushOn($,b)
b,pop(a)
Strings of a’s and b’s that have the same
number of a’s and b’s
a,push(a)
a,pop(b)
b,push(b)
b,pop(a)
l,push($)
b, iignore l,pop($) b, gnore
0 1 3 4
2
a,pop(1) a,pop(1)
a,push(1) a,push(1)
anbanambam With non determinism!
l,push($)
b, iignore b, gnore 4
1
2
a,pop(1) a,pop(2)
a,push(1) a,push(2)
After all the examples…..
Formal Definitions
M=(Q,S,G,qI, F, D)
• Q finite set of. states
• S finiite alphabet
• G finite stack alphabet
• qI Î Q initial state
• F Í Q set. Of final states
• D Í (Q ´ G*´ S*) ´ (Q ´ G*) state transition relation
Transitions
((q,s,r),(q1, t))
If the automaton is in state q, s is at the top of the stack, and r is a prefix of
the input, then read r, pop s, push t, and go to state q1.
Since the stack is a string:
• when we state “s is at the top of the stack” we are stating s is a suffix of
the stack. (l is always a suffix of any string, so when we state l is at the
top of the stack, we are not saying that the stack is empty).
• When we say “push t onto the stack” we are saying. Add t to the end of
the stack (which is a string).
...
l ...
qI
l
...
...
M a |b
Combining Automata: concatenation
Combining Automata: concatenation
Combining Automata: closure
Combining Automata: closure