Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
.
0,1,..9
0,1,..9
Nondeterministic Finite Automata with
transitions(-NFA)
How does such a machine accept?
A string will be accepted if there is at least one
sequence of state transitions on an input
(including transitions) that leaves the machine
in an accepting state.
Nondeterministic Finite Automata with
transitions(-NFA)
Example:
-3.45 is accepted
.5678
37 is rejected
q
0
q
1
q
2
q
3
q
5
q
4
+-
0,1,..9
0,1,..9 .
.
0,1,..9
0,1,..9
Nondeterministic Finite Automata with
transitions(-NFA)
A Non-Deterministic Finite Automata with
transitions is a 5-tuple(Q, , q
o
, , F) where
Q is a finite set (of states)
is a finite alphabet of symbols
q
o
Q is the start state
F Q is the set of accepting states
is a function fromQ x ( {}) to 2
Q
(transition
function)
3
Nondeterministic Finite Automata with
transitions(-NFA)
Transition function
is a function from Q x ( {}) to 2
Q
(q, a) =subset of Q (possibly empty)
In our example
(q
1
, 0) ={q
1
, q
4
}
(q
1
, .) ={q
1
}
(q
1
, +) =
(q
0
, ) ={q
1
}
Nondeterministic Finite Automata with
transitions(-NFA)
Transition function on a string
is a function from Q x
*
to 2
Q
(q, x) =subset of Q (possibly empty)
Set of all states that the machine can be in,
upon following all possible paths on input x.
Well need to consider all paths that include the
use of transitions
^
-Closure
closure
Before defining the transition function on a
string ( (q,x)), it is useful to first define what
is known as the closure.
Given a set of states S, the closurewill give
the set of states reachable from each state in S
using only transitions.
^
-Closure
closure: Recursive definition
Let M =(Q, , q
o
, , F) be a -NFA
Let S be a subset of Q
The closure, denotes ECLOSE(S) is defined:
For each state p S, p ECLOSE(S)
For any q ECLOSE(S), every element of (q, )
ECLOSE(S)
No other elements of Q are in ECLOSE(S)
-Closure
-Closure: Algorithm
Since we know that ECLOSE(S) is finite, we can convert
the recursive definition to an algorithm.
To find ECLOSE(S) where S is a subset of Q
Let T =S
While (T does not change) do
Add all elements of (q, ) whereq T
ECLOSE(S) =T
-Closure
Example
4
-Closure
closure: Example
Find ECLOSE({s}) in our example
T ={s} initial step
T ={s, w} add (s, )
T ={s, w, q
0
} add (w, )
T ={s, w, q
0
, p,t} add (q
0
, )
(w, ) =(w, ) =
We are done,
ECLOSE({s}) =T ={s, w, q
0
, p,t}
Nondeterministic Finite Automata with
transitions(-NFA)
Now lets define
1. For any q Q, (q, ) =ECLOSE ({q})
2. For any y
*
, a , q Q
Set of all states obtained by applying to all states in
*
(q,y) and
input aand taking the closureof theresult
U
) , (
) , ( ) , (
y q p
a p ECLOSE ya q
D
(S, a) will be the union of the closures of the
elements of {r
1
, , r
m
}
U
L
n
i
i E m
a p r r r
1
2 1
) , ( } , , , {
=
=
U
m
j
j D
r ECLOSE a S
1
) ( ) , (
=
=
6
-NFA ->DFA
q
0
q
1
q
2
q
3
q
5
q
4
+-
0,1,..9
0,1,..9 .
.
0,1,..9
0,1,..9
-NFA ->DFA
{q
5
} q
5
{q
4
} q
4
{q
3 ,
q
5
} q
3
{q
2
} q
2
{q
1
} q
1
{q
0
, q
1
} q
0
closure
State
-NFA ->DFA
q
0
q
1
q
1
+-
q
2
.
q
1
q
4
0,1,,9
0,1,,9
q
2
q
3
q
5
.
.
q
3
q
5
0,1,,9
0,1,,9
0,1,,9
0,1,,9
-NFA ->DFA
Now we must show that D accepts the same
language as E
Can be shown (using induction) that for all x
*
(q, x) = (q, x)
See Theorem2.22
^
D
^
E
-NFA ->DFA
Show that D and E recognize the same
language
x is accepted by Eiff (q
0
, x) F
E
x is accepted by D iff (q
D
, x) F
E
Thus,
x is accepted by D iff x is accepted by E
Questions?
^
E
^
D
DFA ->-NFA
The other direction is fairly straighforward.
For any DFA, there is an equivalent NFA
An NFA is nothing more than a -NFA with no
transitions. Thus
(q, ) for all states q =
7
What have we shown
For every DFA, there is an NFA that
accepts the same language and visa versa
For every DFA, there is a -NFA that accepts the
same language, and visa versa
Thus, for every NFA there is a -NFA that accepts the
same language, and visa versa
DFAs, NFAs, and -NFA s are equivalent!
Questions?
Lets take a break.