Finite Automata - Kent State University

advertisement
Finite Automata
Course: Theory of Computation
Date: Nov 16th, 2011
Lin Liu lliu AT cs.kent.edu
Why finite automata are important?
Many real applications
–
–
–
–
elevators
coke machines
train track switches
complier design and parsing
Outline
• A Classic Riddle
Man, Wolf, Goat and Cabbage
• Definition for Finite Automata (FA)
The 5-Tuple
• The Language Accepted by FA
Definition
Examples
A Classic Riddle
• A man travels with wolf, goat and
cabbage and wants to cross a river from
east to west.
• A rowboat is available, but only large
enough for the man plus one possession.
• Wolf eats goat if left alone together.
• Goat eats cabbage if left alone together.
• How can the man cross without loss?
Solutions As Strings
• Four moves can be encoded as four
symbols:
–
–
–
–
Man
Man
Man
Man
crosses with
crosses with
crosses with
crosses with
wolf (w)
goat (g)
cabbage (c)
nothing (n)
• Then a sequence of moves is a string,
such as the solution gnwgcng:
– First cross with goat, then cross back with
nothing, then cross with wolf, …
g
E: mwgc
W:
g
n
E: wc
W: m g
E: mwc
W: g
n
w
Transition Diagram
• Showing all legal moves
• All reachable states
• Start state and goal
state
E:
W: mwgc
g
w
c
E: c
W: mwg
g
E: w
W: m gc
g
g
E: m gc
W: w
c
g
c
E: m gw
W: c
c
w
w
n
E: m g
W: wc
n
g
E: g
W: mwc
The Language Of Solutions
• Every path gives some x  {w,g,c,n}*
• The diagram defines the language of
solutions to the problem: {x  {w,g,c,n}*
| starting in the start state and
following the transitions of x ends up in
the goal state}
• This is an infinite language
• (The two shortest strings in the
language are gnwgcng and gncgwng)
Definition for Finite Automaton
A finite automaton is a 5-tuple (Q, , , q0,
F), where
–
–
–
–
–
Q is a finite set called the states;
 is a finite set called the alphabet;
: Q x   Q is the transition function;
q0  Q is the start state;
F  Q is the set of accepting states.
One finite automaton
a, b
q5
b
q0 a
a
a
b
q1 b q2 b q3 a
start
state
state
transition
a, b
q4
accepting
state
After reading a string s…
• FA accepts the string s, if after reading
the last symbol of s, FA ends up in an
accepting state;
• FA rejects the string s, if after reading
the last symbol of s, FA ends up in a
non-accepting state;
• FA crashes, if FA fails during reading s.
a, b
q5
b
q0 a
a
a
b
q1 b q2 b q3 a
a, b
q4
Input strings
Results
abba
Accept
aabb
Reject
abbc
Crash
The language accepted by FA
L = {x  * | FA accepts x}, where
– * = 0 + 1 + 2 + …
– k = All length k strings over the alphabet
.
Accepted language examples
What is the language accepted by this FA?
a, b
L = {a,b}* = all finite strings of a’s and b’s
What language is accepted by this
machine?
a, b
a, b
L=all even length strings containing a’s and b’s
What language is accepted by this
machine?
b
a, b
a
L = All strings in {a, b}* with at least one a.
References
• www.cs.cmu.edu/afs/cs.cmu.edu/academ
ic/class/.../automata.ppt
• Michael Sipser. Introduction to the
Theory of Computation, first edition,
December 1996
• http://en.wikipedia.org/wiki/Automata_
theory
• www.webber-labs.com/fl/lectures/pptslides/02.ppt
Download