DFA Stanford
DFA Stanford
Part One
Problem
Problem SetSet Four
Four checkpoint
checkpoint
due
due in
in the
the box
box up
up front.
front.
Late
Late Problem
Problem Set
Set Three's
Three's
also
also due
due up
up front.
front.
Last Thoughts on First-Order Logic
An Extremely Important Table
¬∀a ∈ A. aRa
∃a ∈ A. ¬aRa
What kind of
computer?
An automaton (plural: automata) is a
mathematical model of a computing device.
Why Build Models?
● The models of computation we will explore in
this class correspond to different conceptions of
what a computer could do.
● Finite automata (this week) are an abstraction
of computers with finite resource constraints.
● Provide upper bounds for the computing machines
that we can actually build.
● Turing machines (later) are an abstraction of
computers with unbounded resources.
● Provide upper bounds for what we could ever hope
to accomplish.
What problems can we solve with a computer?
What is a
“problem?”
Strings
● An alphabet is a finite set of characters.
● Typically, we use the symbol Σ to refer to an
alphabet.
● A string is a finite sequence of characters drawn
from some alphabet.
● Example: If Σ = {a, b}, some valid strings include
● a
● aabaaabbabaaabaaaabbb
● abbababba
● The empty string contains no characters and is
denoted ε.
Languages
● A formal language is a set of strings.
● We say that L is a language over Σ if it is a
set of strings formed from characters in Σ.
● Example: The language of palindromes over
Σ = {a, b, c} is the set
{ε, a, b, c, aa, bb, cc, aaa, aba, aca, bab, … }
● The set of all strings composed from letters in
Σ is denoted Σ*.
● Formally: L is a language over Σ iff L ⊆ Σ*.
The Model
● Goal: Given an alphabet Σ and a
language L over Σ, can we build an
automaton that can determine which
strings are in L?
● Actually a very expressive and powerful
framework; we'll see this over the next
few weeks.
To Summarize
● An automaton is an idealized
mathematical computing machine.
● A language is a set of strings.
● The automata we will study will accept as
input a string and (attempt to) output
whether that string is contained in a
particular language.
What problems can we solve with a computer?
Finite Automata
A finite automaton is a mathematical
machine for determining whether a string
is contained within some language.
Each finite automaton consists of a set
of states connected by transitions.
A Simple Finite Automaton
0
start
q0 q1
0
1 1 1 1
0
q3 q2
0
Each
Each circle
circle
represents aa state
represents state
of
of the
the automaton.
automaton.
A Simple Finite Automaton
0
start
q0 q1
0
1 1 1 1
0
q3 q2
0
One
One special
special state
state isis
designated
designated as as the
the
start
start state.
state.
A Simple Finite Automaton
0
start
q0 q1
0
1 1 1 1
The
The automaton
automaton isis
run
run on an input
on an input 0
string
string and
and answers
answers q3 q2
“yes”
“yes” or
or “no.”
“no.”
0
0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
The
The automaton
automaton can
can
be in one state at
1a 1 1 1
be in one state at a
time.
time. ItIt begins
begins inin
the start
the start state.
state. 0
q3 q2
0
0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
The
The automaton
automaton now
now
begins 1 1 1 1
begins processing
processing
characters
characters inin the
the
order
order inin which
which they
they 0
appear.
appear. q3 q2
0
0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
1 1 1 1
Each
Each arrow
arrow inin this
this
diagram
diagram represents
represents aa
0
q3 q2 transition.
transition. The
The
automaton
automaton always
always
0 follows
follows the
the transition
transition
corresponding
corresponding to to the
0 1 0 1 1 0 the
current
current symbol
symbol being
being
read.
read.
A Simple Finite Automaton
0
start
q0 q1
0
After
After transitioning,
transitioning,
the
the automaton
1 1 1 1 automaton
considers
considers the
the next
next
symbol
symbol inin the
the
0 input.
input.
q3 q2
0
0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
The
The double
double circle
circle
Now
Now that
that the
the
indicates
indicates that
that this
this
automaton
automaton has
has 1 1 1 1 state
state isis an
an
looked
looked at at all
all this
this
accepting
accepting state,
state,
input,
input, itit can
can decide
decide
so
so the
the automaton
automaton
whether
whether to
to say
say “yes”
“yes” 0
q3 q2 outputs
outputs “yes.”
“yes.”
or
or “no.”
“no.”
0
0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
This
This state
state isis not
not
an
an accepting
accepting state,
state,
1 1 1 1
so
so the
the automaton
automaton
says
says “no.”
“no.”
0
q3 q2
0
1 0 1 0 0 0
A Simple Finite Automaton
0
start
q0 q1
0
Try
Try itit yourself!
yourself!
Does
Does the
1 1 1 1 the
automaton accept
automaton accept
(say
(say yes)
yes) or
or
0 reject
reject (say
(say no)?
no)?
q3 q2
0
1 1 0 1 1 1 0 0
The Story So Far
● A finite automaton is a collection of states
joined by transitions.
● Some state is designated as the start state.
● Some states are designated as accepting states.
● The automaton processes a string by beginning in
the start state and following the indicated
transitions.
● If the automaton ends in an accepting state, it
accepts the input.
● Otherwise, the automaton rejects the input.
Time-Out For Announcements
Midterm Exam
● Midterm is October 29 from 7PM – 10PM.
● Location information TBA.
● Need to take the exam at an alternate time? Fill
out the alternate time form ASAP.
● Covers material up through and including DFAs.
● Two practice exams available online.
● Handout: Exam Strategies and Policies
available online.
● Review session later this week; more details
on Wednesday.
Your Questions
“Keith, why did you choose to go into
academia as opposed to industry? Do you
have any advice for students deciding
between the two?”
“What do you think is the coolest
real-world application of CS103-related
material?”
“Why are you taking away the Checkpoint
problems... don't?”
Back to CS103!
A finite automaton does not accept as soon
as the input enters an accepting state.
0 This
This automaton
automaton
q1 q2 accepts
accepts aa string
string iff
iff
1 itit ends
ends in
in 00
00 or
or 11.
11.
1 0
0 1
q3 q5
1 0
The language of an automaton is the
set of strings that it accepts.
ℒ(D) = { w ∈ Σ* | D accepts w }
A Small Problem
start
q0
0 0
0 1 1 0
q2 q1
1
Another Small Problem
0, 1
start 0, 1
q0 q1
0 0 0 0
0, 1
q2
The Need for Formalism
● In order to reason about the limits of
what finite automata can and cannot do,
we need to formally specify their behavior
in all cases.
● All of the following need to be defined or
disallowed:
● What happens if there is no transition out of
a state on some input?
● What happens if there are multiple
transitions out of a state on some input?
DFAs
● A DFA is a
● Deterministic
● Finite
● Automaton
● DFAs are the simplest type of automaton
that we will see in this course.
DFAs, Informally
● A DFA is defined relative to some
alphabet Σ.
● For each state in the DFA, there must be
exactly one transition defined for each
symbol in the alphabet.
● This is the “deterministic” part of DFA.
● There is a unique start state.
● There are zero or more accepting states.
Is this a DFA?
0
start
q0 q1
0
1 1 1 1
0
q3 q2
0
Is this a DFA?
start
q0
1 0
0
q1 q2
1
1 0
0 1
q3 q5
1 0
Is this a DFA?
start
q0
0 0
q2 q1
1
Is this a DFA?
start 0, 1
q0 q1
0, 1 0, 1
q3 0, 1 q2
Is this a DFA?
0, 1
start 0, 1
q0 q1
0
0, 1
q2
Designing DFAs
● At each point in its execution, the DFA
can only remember what state it is in.
● DFA Design Tip: Build each state to
correspond to some piece of information
you need to remember.
● Each state acts as a “memento” of what
you're supposed to do next.
● Only finitely many different states ≈ only
finitely many different things the machine
can remember.
Recognizing Languages with DFAs
L = { w ∈ {0, 1}* | w contains 00 as a substring }
1
0, 1
start 0 0
q0 q1 q2
1
Recognizing Languages with DFAs
L = { w ∈ {0, 1}* | w contains 00 as a substring }
1
Σ
start 0 0
q0 q1 q2
1
Recognizing Languages with DFAs
L = { w ∈ {0, 1}*| every other character of w, starting
with the first character, is 0 }
start 0
q0 q1
Σ
1
q2
Σ
Next Time
● Regular Languages
● What is the expressive power of DFAs?
● NFAs
● Automata with magic superpowers!
●
Nondeterminism
● Nondeterminisic computation.
● Intuitions for nondeterminism.
● Programming with nondeterminism.