Deterministic Finite Automata

Deterministic Finite Automata
DFA
• A primitive computing machine with very
limited amount of memory.
• Example (inspired from Sipser’s book):
Automatic door mechanism:
Front
pad
D
O
O
R
Rear
pad
Example
Front
pad
D
O
O
R
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
D
O
O
R
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
Front
pad
D
O
O
R
Rear
pad
FRONT
REAR
BOTH
NEITHER
CLOSED
OPEN
NEITHER
FRONT
REAR
BOTH
DFA
INPUT TAPE
D
F
A
ACCEPT
or
REJECT
DFA parts
q0
a
b
q1
a
q2
b
a
b
q4
a
b
TRANSITION
GRAPH
a
b
q3
DFA parts
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
STATES : {q0 , q1, q2, q3, q4}
q3
DFA parts
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
ACCEPTING
STATE
DFA parts
q0
a
NON-ACCEPTING
b
b
q1 STATE
q2
a
a
b
q4
a
b
a
b
q3
DFA parts
q0
a
START
STATE b
b
q1
a
q2
b
a
q4
a
b
a
b
q3
DFA parts
ALPHABET:
Σ = {a,b}
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA parts
ALPHABET:
Σ = {a,b}
q0
a
b
q1
a
q2
b
q3
a
a
TRANSITION
b
q4
a
b
b
DFA parts
ALPHABET:
Σ = {a,b}
q0
a
b
q1
a
q2
b
a
b
q4
a
b
Exactly one transition
from every state under
each symbol in the alphabet.
a
b
q3
DFA parts
ALPHABET:
Σ = {a,b}
q0
a
b
q1
a
q2
b
a
b
q4
a
b
Exactly one transition
from every state under
each symbol in the alphabet.
a
b
q3
DFA transition graph
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA transition graph
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
a
b
JUNK or
TRAP STATE
DFA continued
q0
TAPE
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
bba
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
bb
a
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
bb
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
b
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abb
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
a
b
ACCEPT
DFA continued
Input string: abbb
q0
bbba
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
bbb a
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
abb
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
bb
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
bb
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
b
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
b
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA continued
Input string: abbb
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
a
b
REJECT
Empty string
• Denoted by the Greek letters ε or λ.
• Contains no letters.
Empty string
Input string: ε
q0
a
b
q1
a
b
a
b
The tape is
empty
q2
q4
a
b
a
b
q3
Empty string
Input string: ε
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
a
b
REJECT
Other Example
More than one
accepting states
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
Other Example
Input string: ε
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
Other Example
Input string: ε
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
a
b
ACCEPT
Other Example
Input string: ε
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
b
ACCEPT
a
b
The automaton accepts with input the empty
string ε iff the START state is an ACCEPTING state.
DFA formally
• In order to completely determine a DFA we
need five things:
– Its set of states,
– the alphabet of the input strings,
– a the transition function between states,
– a start state from which the computation begins
and
– the set of states for which the DFA accepts.
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
– Q is the set of states
q0
a
b
q1
a
q2
b
a
b
q4
a
b
Q = {q0 , q1, q2, q3, q4}
a
b
q3
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
– Σ is the alphabet of the input strings
q0
a
b
q1
a
q2
b
a
b
q4
a
b
Σ = {a,b}
a
b
q3
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
– δ is a transition function between states.
q0
a
b
q1
a
q2
b
q3
a
b
q4
a
TRANSITION
(q2 , a b) → q4
a
b
δ: Q × Σ→ Q
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
– q0 is the start state.
q0
a
START
STATE b
b
q1
a
q2
b
a
q4
a
b
a
b
q3
DFA formally
• A DFA M is a quintuple (Q, Σ, δ, q0, F) where
– F is the set of accepting states
q0
a
ACCEPTING
STATEb
b
q1
a
q2
b
a
q4
a
b
F = {q0, q3}
a
b
q3
ACCEPTING
STATE
Languages
• A language L over an alphabet Σ is a set of
strings of Σ.
• Example: Σ = {a,b}
L1 = {a, ab}
L2 = {ε, aab, aabbb, bbab}
L3 = { }
Languages
• The language that a DFA accepts is the set of
input strings for which the DFA accepts.
• Example: This DFA accepts the language
L = {ε, abb}
q0
a
b
q1
a
q2
b
a
b
q4
a
b
a
b
q3
Infinite Languages
• Example: Σ = {a,b}
L = {s : s begins with ab}
q0
a
b
q1
a
q2
a,b
b
q4
a,b
Infinite Languages
• Example: Σ = {a,b}
L = {s :|s| is odd}
a,b
q0
q1
a,b
Try this out
• Create a DFA that accepts the language
L = {anb : n≥0} = {b, ab, aab, aaab, … }
Try this out
• Create a DFA that accepts the language
L = {anb : n≥0} = {b, ab, aab, aaab, … }
a,b
a
q0
b
q1
a,b
q2