CPS420 Discrete Structures
3.2A Deterministic Finite State
Automata
© Sophie Quigley
The copyright to this original work is held by Sophie Quigley, and students
registered in course CPS420 can use this material for the purposes of this
course but no other use is permitted, and there can be no sale or transfer or
use of the work for any other purpose without the explicit permission of
Sophie Quigley
2
How to use this power point
Slides in this power point deck contain audio clips which are invoked
by clicking on speaker icon buttons
The location of each
button indicates the best time to listen to the clip. Try out the ones
on this slide.
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
3
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
➢Vending Machine Example
• DFA Definition
• Next-state Function
• Transition Diagrams
• Tabular Representations
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
4
5
Example
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can be
purchased.
6
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can be
purchased.
• The machine has a starting state shown as
receiving an arrow.
7
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
• This starting state is labelled with a 0
which is the total amount of money
entered into the machine so far
8
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
0.25
• When a quarter (Q) is added, the machine
now has a balance of $0.25
9
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Use a diagram to
show what can be
purchased.
Q
0.25
• The action of putting in a quarter is shown
as an arrow labelled with “Q” for quarter.
10
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
0.25
Q
0.50
Q
0.75
Q
1.00
Soft
Drink
Q
Q
1.25
• After 6 quarters have been entered, the
customer can buy a soft drink.
11
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
0.25
Q
0.50
Q
0.75
Q
1.00
Soft
Drink
Q
Q
1.25
• The customer can stop entering money at
this point, and the soft Drink state is
called a “final” state.
12
Example
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
0.25
Q
0.50
Q
0.75
Q
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
• The customer can continue entering
quarters in order to buy a bottle of water.
13
Example
L
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
• When loonies are entered, the customer
fast tracks through the states.
L
14
Example
L
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
L=Loonie
Q=quarter
• Try to avoid crossing arrows
1.25
L
15
Example
L
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
1.25
L
?
L
16
Example
L
0
A vending machine
accepts quarters (Q)
and loonies (L)
• It does not make
change.
• A bottle of water
costs $2 and a soft
drink $1.50.
Build a diagram
showing what can
be purchased.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
1.25
L
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
✓Vending Machine Example
➢DFA Definition
• Next-state Function
• Transition Diagrams
• Tabular Representations
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
17
18
DFA Definition
A Deterministic Finite State Automaton (DFA) A, also called a Finite
State Automaton (FSA or FA) consists of 5 objects:
• A set I called the input alphabet, of input symbols
• A set S of states the automaton can be in
• A designated state s0 called the initial state
• A designated set of states F S called the set of accepting states, or
final states
• A next-state function N: S× I → S that associates a “next-state” to
each ordered pair consisting of a “current state” and “current input”.
For each state s in S and input symbol m in I, N(s,m) is called the state
to which A goes if m is input to A when A is in state s
19
DFA Definition
L
0
A Deterministic
Finite State
Automaton (DFA),
also called a Finite
State Automaton (FA)
A
consists of 5 objects:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
1. A set I called the input alphabet, of
input symbols
I = {Q, L}
L
20
DFA Definition
L
0
A Deterministic
Finite State
Automaton (DFA),
also called a Finite
State Automaton (FA)
A
consists of 5 objects:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
L
1.25
L=Loonie
Q=quarter
2. A set S of states the automaton can be in
S = {0, 0.25, 0.50, 0.75, 1.00, 1.25,
Soft Drink, 1.75, Water}
21
DFA Definition
L
0
A Deterministic
Finite State
Automaton (DFA),
also called a Finite
State Automaton (FA)
A
consists of 5 objects:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
3. A designated state s0 called the initial
state
s0 = 0
L
22
DFA Definition
L
0
A Deterministic
Finite State
Automaton (DFA),
also called a Finite
State Automaton (FA)
A
consists of 5 objects:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
4. A designated set of states F S called
the set of accepting states, or final
states
F = {Soft Drink, Water}
L
23
DFA Definition
L
0
A Deterministic
Finite State
Automaton (DFA),
also called a Finite
State Automaton (FA)
A
consists of 5 objects:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
5. A next-state function defining the
operations of the automaton
L
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
✓Vending Machine Example
✓DFA Definition
➢Next-state Function
• Transition Diagrams
• Tabular Representations
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
24
25
Next-state Function
L
0
The next-state function N
is defined as follows:
• N: S×I → S that
associates a “next-state”
to each ordered pair
consisting of a “current
state” and “current
input”.
• For each state s in S and
input symbol m in I,
N(s,m) is called the state
to which A goes if m is
input to A when A is in
state s.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
1.25
L
Current State
Next-state Function
Next State
L
0
The next-state function N
is defined as follows:
• N: S×I → S that
associates a “next-state”
to each ordered pair
consisting of a “current
state” and “current
input”.
• For each state s in S and
input symbol m in I,
N(s,m) is called the state
to which A goes if m is
input to A when A is in
state s.
Current Input
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
1.25
L
26
27
Next-state Function
L
0
The next-state function N
is defined as follows:
• N: S×I → S that
associates a “next-state”
to each ordered pair
consisting of a “current
state” and “current
input”.
• For each state s in S and
input symbol m in I,
N(s,m) is called the state
to which A goes if m is
input to A when A is in
state s.
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
1.25
L
28
Next-state Function
L
Q
0
The next-state function N
is defined as follows:
• N: S×I → S that
associates a “next-state”
to each ordered pair
consisting of a “current
state” and “current
input”.
• For each state s in S and
input symbol m in I,
N(s,m) is called the state
to which A goes if m is
input to A when A is in
state s.
Q
0.25
0.50
L
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
L=Loonie
Q=quarter
N(0.50,Q) = 0.75
∈S ∈I
∈S
Q
Q
1.25
L
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
✓Vending Machine Example
✓DFA Definition
✓Next-state Function
➢Transition Diagrams
• Tabular Representations
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
29
30
Transition Diagrams
The operation of an FA is commonly described by a diagram called a
(state-)transition diagram.
In a transition diagram:
• states are represented by circles, and accepting states by double
circles.
• There is one arrow that points to the initial state and other arrows
between states as follows: There is an arrow from state s to state t
labeled m (where ∈ I) iff N(s,m)=t.
31
non-accepting state
Transition Diagram
L
0
The operation of an
FSA is commonly
described by a
diagram called a
(state-) transition
diagram.
In a transition
diagram:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
L=Loonie
Q=quarter
1.75
Soft
Drink
Q
Q
L
1.25
accepting state
• states are represented by circles,
• and accepting states by double circles.
32
Transition Diagram
L
0
The operation of an
FSA is commonly
described by a
diagram called a
(state-) transition
diagram.
In a transition
diagram:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
• There is one arrow that points to the
initial state
L
33
Transition Diagram
L
0
The operation of an
FSA is commonly
described by a
diagram called a
(state-) transition
diagram.
In a transition
diagram:
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
L
1.25
L=Loonie
Q=quarter
• and other arrows between states as
follows: There is an arrow from state s to
state t labeled m (∈I) iff N(s,m)=t.
3.2 Deterministic Finite State Automata
Table of Contents
Part A: Example and Definitions
✓Vending Machine Example
✓DFA Definition
✓Next-state Function
✓Transition Diagrams
➢Tabular Representations
Part B: Languages accepted by DFAs
Next Topic: Non-Deterministic Finite Automata
34
35
Next-state tables
• The next-state table is a tabular representation of the next-state
function.
• In the annotated next-state table, the initial state is indicated by an
arrow and the accepting states by double circles.
36
Next-state Table
I = {input symbols}
Q
L
0
0.25
1.00
0.25
0.50
1.25
0.50
0.75
Soft Dr.
0.75
1.00
1.75
1.00
1.25
Water
1.25
Soft Dr.
Soft Dr.
1.75
1.75
Water
Water
S = {states}
L
0
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
1.25
L=Loonie
Q=quarter
The next-state table is a tabular
representation of the next-state function
N[state,input] = N(state,input)
L
Annotated Nextstate Table
S0 = Initial state
Q
L
→0
0.25
1.00
0.25
0.50
1.25
0.50
0.75
Soft Dr.
0.75
1.00
1.75
1.00
1.25
Water
1.25
Soft Dr.
Soft Dr.
1.75
1.75
Water
Water
F= {Final states}
37
L
0
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
L
1.25
L=Loonie
Q=quarter
In the annotated next-state table, the initial
state is indicated by an arrow and the
accepting states by double circles.
Annotated Nextstate Table
Q
L
→0
0.25
1.00
0.25
0.50
1.25
0.50
0.75
Soft Dr.
0.75
1.00
1.75
1.00
1.25
Water
1.25
Soft Dr.
Soft Dr.
1.75
1.75
Water
Water
38
L
0
Q
Q
0.25
L
0.50
Q
L
0.75
Q
L
1.00
Q
Q
Water
1.75
Soft
Drink
Q
Q
L
1.25
L=Loonie
Q=quarter
The annotated next-state table defines the
automaton completely, precisely, and
unambiguously.
39
Programming a DFA
Q
L
→0
0.25
1.00
0.25
0.50
1.25
0.50
0.75
Soft Dr.
0.75
1.00
1.75
1.00
1.25
Water
1.25
Soft Dr.
Soft Dr.
1.75
1.75
Water
Water
Current state = initial state
While current state is not final
• read current input
• current state = N[current state,
current input]
40
Programming a DFA
Q
L
→0
0.25
1.00
0.25
0.50
1.25
0.50
0.75
Soft Dr.
0.75
1.00
1.75
1.00
1.25
Water
1.25
Soft Dr.
Error
Soft Dr.
1.75
Error
1.75
Water
Error
Water
Error
Error
Current state = initial state
While current state is not final
• read current input
• current state = N[current state,
current input]
41
Next Topics
The next set of slides will cover languages accepted by deterministic
finite state automata.
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )