Compsci 102 Discrete Math For Computer Science: Feb. 2, 2012 Prof. Rodger
Compsci 102 Discrete Math For Computer Science: Feb. 2, 2012 Prof. Rodger
Feb. 2, 2012
Prof. Rodger
Deterministic
Finite
Automata
11
1
0,1
1
0111
111
1
0
0
1
1
q1
0
0,1
accept states (F)
0
q12
q0
1
0,1
1
q0
q2
0
0
The alphabet of a finite automaton is the
1{0,1}
set where the symbols come from:
q3
The language of a finite automaton is the
Rudich:
set of strings thatwww.cs.cmu.edu/~rudich
itSteven
accepts
q0
0,1
L(M) =All
strings of 0s and 1s
The Language of Machine M
Steven Rudich:
www.cs.cmu.edu/~rudich
q0
1
1
q1
Steven Rudich:
www.cs.cmu.edu/~rudich
Notation
An alphabet is a finite set (e.g., = {0,1})
A string over is a finite-length sequence of
elements of
For a string x, |x| isthe length of x
The unique string of length 0 will be
denoted by and will be called the empty or
null string
A language over is a set of strings over
Steven Rudich:
www.cs.cmu.edu/~rudich
M = (Q, , , q0, F)
where
q1
0
1
q0
0
M
q3
1
0,1
q2
0
1
Steven Rudich:
www.cs.cmu.edu/~rudich
q0
q0
q1
q1
q2
q2
q2
q3
q2
q3
q0
q2
0,1
0
0
1
q0
q00
Steven Rudich:
www.cs.cmu.edu/~rudich
q001
A language is regular if it is
recognized (accepted) by a
deterministic finite automaton
L = { w | w contains 001} is regular
L = { w | w has an even number of 1s} is regular
Steven Rudich:
www.cs.cmu.edu/~rudich
Union Theorem
Given two languages, L1 and L2,
define the union of L1 and L2 as
L1 L2 = { w | w L1 or w L2 }
Theorem: The union of two regular
languages is also a regular
language
Steven Rudich:
www.cs.cmu.edu/~rudich
and
M2 = (Q2, , 2, q0, F2) be finite automaton for
We
L2 want to construct a finite automaton
M = (Q, , , q0, F) that recognizes L = L1
L2
Steven Rudich:
www.cs.cmu.edu/~rudich
Steven Rudich:
www.cs.cmu.edu/~rudich
q0
1
1
q1
p0
Steven Rudich:
www.cs.cmu.edu/~rudich
0
0
p1
q1,p0
1
0
1
q0,p1
q1,p1
1
Steven Rudich:
www.cs.cmu.edu/~rudich
Automaton for
Intersection
1
q0,p0
q1,p0
1
0
1
q0,p1
q1,p1
1
Steven Rudich:
www.cs.cmu.edu/~rudich
Steven Rudich:
www.cs.cmu.edu/~rudich
Concatenation: A B = { vw | v A and w B }
Star: A* = { w1 wk | k 0 and each wi A }
Steven Rudich:
www.cs.cmu.edu/~rudich
Automata Solution
Build a machine M that accepts any
string with S as a consecutive substring
Feed the text to M
Cost: t comparisons + time to build M
As luck would have it, the Knuth, Morris,
Pratt algorithm builds M quickly
Are all
languages
regular?
a
b
b
a
Pigeonhole principle:
Given n boxes and m >
n objects, at least one
box must contain more
than one object
Letterbox principle:
If the average number
of letters per box is x,
then some box will
have at least x letters
(similarly, some box
has at most x)
Deterministic Finite
Automata
Definition
Testing if they accept a string
Building automata
Regular Languages
Heres What
You Need to
Know
Definition
Closed Under Union,
Intersection, Negation
Using Pigeonhole Principle to
show language aint regular