Chap2 Finiteautomatastud
Chap2 Finiteautomatastud
Finite Automata
even
L, R
There
state
The automaton takes inputs from alphabet {L, R}
The state even is an accepting state
There are transitions saying what to do for every
state and every alphabet symbol
3
In
EXAMPLE
q0
1
1
q1
alphabet S = {0, 1}
states Q = {q0, q1, q2}
initial state q0
accepting states F = {q0, q1}
0,1
0
q2
table of
transition function d:
inputs
states
q0
q1
q2
0
q0
q2
q2
1
q1
q1
q2
5
LANGUAGE OF A DFA
The language of a DFA (Q, S, d, q0, F) is the set of
all strings over S that, starting from q0 and
following the transitions as the string is read left
to right, will reach some accepting state.
L, R
M:
odd
even
L, R
EXAMPLES
S = {a, b}
b
q0
b
b
0
q0
q1
q1
a
a
q3
a
q1
q2
b
b
q4
1
1
S = {a, b}
q0
0, 1
0
q2
S = {0, 1}
EXAMPLES
a DFA over alphabet {0, 1} that accepts
all strings with at most three 1s
Construct
EXAMPLES
a DFA over alphabet {0, 1} that accepts
all strings with at most three 1s
Construct
Answer
0
0
q0
q1
0
1
q2
0, 1
0
1
q3
q4+
EXAMPLES
Construct
( S = {0, 1} )
10
EXAMPLES
a DFA over alphabet {0, 1} that
accepts all strings that end in 01
Construct
11
EXAMPLES
a DFA over alphabet {0, 1} that
accepts all strings that end in 01
Construct
Hint:
12
EXAMPLES
a DFA over alphabet {0, 1} that accepts
all strings that end in 101
Sketch of answer:
0
Construct
q0
qe
1
0
q1
q00
q01
q10
q11
1
q001
q000
q101
q111
1
13
Nondeterminism
14
EXAMPLE
a DFA over alphabet {0, 1} that
accepts those strings that end in 101
Sketch of answer:
0
Construct
q0
qe
1
0
q1
q00
q01
q10
q11
1
q001
q000
q101
q111
1
15
WOULD BE EASIER IF
Suppose
1
0
0
1
qdie
NONDETERMINISM
Nondeterminism
q1
q2
q3
Each
q1
q2
q3
19
q1
q2
q3
20
q1
q2
q3
21
MEANING OF NFA
Guess if you are 3
symbols away from end of
input
0, 1
q0
q1
q2
q3
q1
q2
q3
input: 0 1 1 0 1
EXAMPLE
24
EXAMPLE
Answer
0, 1
q0
0, 1
0
q1
q2
q3
25
DEFINITION
26
LANGUAGE OF AN NFA
The language of an NFA is the set of all
strings for which there is some path that,
starting from q0, leads to an accepting state as
the string is read left to right (and e-transitions
are taken for free).
Example
q0
e, 1
0
q1
q2
e, 00, 001, 101 are accepted, but 11, 0110 are not
27
EXAMPLE
q0
e, 1
0
q1
q2
table of
transition function d:
alphabet S = {0, 1}
states Q = {q0, q1, q2}
initial state q0
accepting states F = {q2}
states
q0
q1
q2
inputs
1
{q1}
{q1}
{q2}
{q0, q1}
28
EXAMPLES
e
q0
e, 1
q1
q2
0
2
00
q0
e, 1
q1
q2
q2
q2
0
2
or
q0
e, 1
q1
0
or
q0
e, 1
2
q1
4
29
EXAMPLES
001
q0
,1
101
q0
11
q0
e, 1
q0
q2
0
1
q1
q2
0
1
q1
0
e, 1
q1
0
e, 1
q2
STOP
0
1
q1
0
q2
STOP
30
EXAMPLE OF e-TRANSITIONS
e
q0
r1
0
s0
e-transitions
r0
1
even number of 0s
0
1
1
s1
odd number of 1s
31
32
YES
If L is the language of some NFA, then
it is also the language of some DFA.
33
34
q0
q0
q2
0
DFA:
q1
q0 or q1
q0 or q2
35
q0
q0
q2
0
DFA:
q1
{q0, q1}
{q0, q2}
36
GENERAL METHOD
states
NFA
DFA
q0, q1, , qn
initial state q0
transitions
{q0}
d({qi1,,qik}, a) =
d(qi1, a) d(qik, a)
accepting
states
FQ
NFA:
q0
q1
q2
0
DFA:
{q0}
0, 1
{q0, q1}
0
{q0, q2}
{q1}
1
0
0
1
{q2}
{q1, q2}
38
{q0, q1}
0
{q0, q2}
{q1}
1
0
0
1
{q2}
{q1, q2}
39
40
41
ELIMINATING e-TRANSITIONS
eNFA:
e, 1
q0
q1
q2
0
Transition table of corresponding NFA:
inputs
states
q0
{q1, q2}
q1
q2
q0, q1, q2
42
ELIMINATING e-TRANSITIONS
NFA:
e, 1
q0
q1
q2
q2
q0
0, 1
q1
0
0, 1
43
q5
q2
q0
qj
qi
e
qi
q5
qj
qi
q7
e
e
q3
qf
44
ELIMINATING e-TRANSITIONS
NFA:
e, 1
q0
q1
q2
q2
q0
0, 1
q1
0
0, 1
45