Date post: | 14-Apr-2017 |
Category: |
Engineering |
Upload: | shiraz316 |
View: | 39 times |
Download: | 0 times |
Courtesy: Jeff Ullman 1
Finite Automata
What Are They?An Example: Scoring in Tennis
Courtesy: Jeff Ullman 2
What is a Finite Automaton?
A formal system. Remembers only a finite amount of
information. Information represented by its
state. State changes in response to
inputs. Rules that tell how the state
changes in response to inputs are called transitions.
Courtesy: Jeff Ullman 3
Informal Explanation Finite automata are finite
collections of states with transition rules that take you from one state to another.
Original application was sequential switching circuits, where the “state” was the settings of internal bits.
Today, several kinds of software can be modeled by FA.
Courtesy: Jeff Ullman 4
Representing FA Simplest representation is often a
graph. Nodes = states. Arcs indicate state transitions. Labels on arcs tell what causes the
transition.
Courtesy: Jeff Ullman 5
Tennis Like ping-pong, except you are
very tiny and stand on the table. Match = 3-5 sets. Set = 6 or more games.
Courtesy: Jeff Ullman 6
Scoring a Game One person serves throughout. To win, you must score at least 4
points. You also must win by at least 2
points. Inputs are s = “server wins point”
and o = “opponent wins point.”
Courtesy: Jeff Ullman 7
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
oAd-out
Ad-in
s
os
o
s
o
Courtesy: Jeff Ullman 8
Acceptance of Inputs Given a sequence of inputs (input
string ), start in the start state and follow the transition from each symbol in turn.
Input is accepted if you wind up in a final (accepting) state after all inputs have been read.
Courtesy: Jeff Ullman 9
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 10
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 11
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 12
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 13
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 14
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 15
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 16
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 17
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 18
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 19
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 20
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s
*
Courtesy: Jeff Ullman 21
Example: Processing a String
Love
Start
Love-15
15-Loves
o
Love-30
15-all
30-Love
s
s
o
o
Love-40
15-30
30-15
40-Love
s
s
s
o
o
o
ServerWins
Opp’ntWins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuces
s
o
o Ad-out
Ad-in
s
o s
o
s
o
s o s o s o s o s o s s *
Courtesy: Jeff Ullman 22
Example: Recognizing Strings Ending in “ing”
nothing Saw ii
Not i
Saw ingg
i
Not i or g
Saw inn
i
Not i or n
Start
Courtesy: Jeff Ullman 23
Automata to Code In C/C++, make a piece of code
for each state. This code:1. Reads the next input.2. Decides on the next state.3. Jumps to the beginning of the code
for that state.
Courtesy: Jeff Ullman 24
Example: Automata to Code
2: /* i seen */c = getNextInput();if (c == ’n’) goto 3;else if (c == ’i’) goto 2;else goto 1;
3: /* ”in” seen */. . .
Courtesy: Jeff Ullman 25
Language of an Automaton
The set of strings accepted by an automaton A is the language of A.
Denoted L(A). Different sets of final states ->
different languages. Example: As designed, L(Tennis) =
strings that determine the winner.