q
1
1
0
q
q
Would be easier if
Suppose we could guess when the string we are
reading has only 3 symbols left
Then we could simply look for the sequence 101
and accept if we see it
3 symbols left
qdie
This is not a
DFA!
Nondeterminism
Nondeterminism is the ability to make
guesses, which we can later verify
Informal nondeterministic algorithm for
strings that end in 101:
1. Guess if you are approaching end of input
2. If guess is yes, look for 101 and accept if you
see it
3. If guess is no, read one more symbol and go
to step 1
Semantics of guessing
0, 1
q
Semantics of guessing
0, 1
q
Semantics of guessing
0, 1
q
Meaning of automaton
Guess if you are 3
symbols away from
end of input
0, 1
q
Example
Construct an NFA over alphabet {0, 1} that
accepts those strings that contain the
pattern 001
Example
Construct an NFA over alphabet {0, 1} that
accepts those strings that contain the pattern 001
somewhere
Answer
0, 1
q
0, 1
0
Example
Construct an NFA that accepts all strings with an
even number of 0s or an odd number of 1s
1
q0
r0
1
0
0
s0
r1
even number of 0s
0
1
1
s1
odd number of 1s
Formal definition
A nondeterministic finite automaton (NFA) is a
5-tuple (Q, , , q0, F) where
Q is a finite set of states
is an alphabet
: Q () subsets of Q is a transition
function
q0 Q is the initial state
F Q is a set of accepting states (or final states).
Example
q0
, 1
0
q1
states
alphabet = {0, 1}
states Q = {q0, q1, q2}
initial state q0
q0
accepting states F = {q2} q1
q2
q2
table of
transition function
inputs
1
{q1} {q1}
{q2}
{q0, q1}
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 -transitions are taken for
free).
Example
q0
, 1
0
q1
q2
Examples
q0
, 1
q1
q2
0
2
00
q0
, 1
q1
q2
q2
q2
0
2
or
q0
, 1
or
, 1
2
q1
q0
q1
4
Examples
2
001
q0
, 14
101
11
q0
q0
q1
0
, 1
q2
q2
q1
0
q0
, 1
q1
, 1
q2
STOP
0
1
q1
0
q2
STOP
NO!
Theorem