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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
s
o
o
Ad-out
Ad-in
s
o
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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-Love
s
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
Server
Wins
Opp’nt
Wins
s
o
40-15
15-40
30-all
s
s
s
o
o
o
30-40
40-30
s
s
s
o
o
o
deuce
s
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 i
i
Not i
Saw ing
g
i
Not i or g
Saw in
n
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.
Courtesy: Jeff Ullman

Finite Automata

  • 1.
    1 Finite Automata What AreThey? An Example: Scoring in Tennis Courtesy: Jeff Ullman
  • 2.
    2 What is aFinite 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.
    3 Informal Explanation Finite automataare 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.
    4 Representing FA Simplest representationis often a graph.  Nodes = states.  Arcs indicate state transitions.  Labels on arcs tell what causes the transition. Courtesy: Jeff Ullman
  • 5.
    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.
    6 Scoring a Game Oneperson 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.
  • 8.
    8 Acceptance of Inputs Givena 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.
    9 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    10 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    11 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    12 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    13 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    14 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    15 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    16 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    17 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    18 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    19 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    20 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    21 Example: Processing aString Love Start Love-15 15-Love s 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 Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s 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.
    22 Example: Recognizing Strings Endingin “ing” nothing Saw i i Not i Saw ing g i Not i or g Saw in n i Not i or n Start Courtesy: Jeff Ullman
  • 23.
    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.
    24 Example: Automata toCode 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.
    25 Language of anAutomaton 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. Courtesy: Jeff Ullman