Lecture 08
Lecture 08
Lecture 08
2
NFA → DFA Construction
The DFA uses its state to
keep track of all possible
states the NFA can be in
after reading each input
symbol.
3
NFA → DFA Construction
We will use the following
operations.
-closure(T):
set of NFA states reachable
from some NFA state s in T
on -transitions alone.
4
NFA DFA Construction
move(T,a):
set of NFA states to which
there is a transition on input
a from some NFA state s in
set of states T.
5
NFA → DFA Construction
Before it sees the first input
symbol, NFA can be in
any of the state in the set
-closure(s0), where s0 is the
start state of the NFA.
6
NFA → DFA Construction
Suppose that exactly the
states in set T are
reachable from s0 on a
given sequence of input
symbols.
7
NFA → DFA Construction
Let a be the next input
symbol.
On seeing a, the NFA can
move to any of the states in
the set move(T,a).
8
NFA → DFA Construction
Let a be the next input
symbol.
On seeing a, the NFA can
move to any of the states in
the set move(T,a).
9
NFA → DFA Construction
When we allow for
-transitions, NFA can be in
any of the states in
-closure(move(T,a))
after seeing a.
10
Subset Construction
Algorithm:
Input:
NFA N with state set S,
alphabet , start state
s0, final states F
11
Subset Construction
Output:
DFA D with state set S’,
alphabet , start states
s0’ = -closure(s0), final
states F’, transition
table: S’ x → S’
12
Algorithm
// initially, e-closure(s0) is the only
// state in D states S’ and it is
// unmarked
s0’ = -closure(s0)
S’ = {s0’ } (unmarked)
13
while there is some unmarked state T
in S’
mark state T
for all a in do
U = -closure( move(T,a) );
if U not already in S’
add U as an unmarked state to S’
Dtran(T,a) = U;
end for
end while
14
Algorithm
F’:
for each DFA state S
if S contains an NFA final state
mark S as DFA final state
15
Subset Construction Example
a
2 3
a b b
0 1 6 7 8 9 10
b
4 5
NFA for (a | b )*abb
16
a
2 3
a b b
0 1 6 7 8 9 10
b
4 5
The start state of equivalent
DFA is -closure(0), which is
A = {0,1,2,4,7}
17
2 a
3
a b b
0 1 6 7 8 9 10
b
4 5
A = {0,1,2,4,7}, these are
exactly the states reachable
from state 0 via -transition.
18
2 a 3
a b b
0 1 6 7 8 9 10
b
4 5
The input symbol alphabet
here is {a,b}.
19
2 a 3
a b b
0 1 6 7 8 9 10
b
4 5
The algorithm tells us to mark
A and then compute
-closure(move(A,a))
20
2 a
3
a b b
0 1 6 7 8 9 10
b
4 5
move(A,a)), is the set of states
of NFA that have transition on
‘a’ from members of A.
21
2 a
3
a b b
0 1 6 7 8 9 10
b
4 5
b
DFA for (a | b )*abb
36
Resulting DFA
a a
a b b
A B D E
a
b a
b
C
b a a a a b b
37
Final Transition Table
Input symbol
State a b
A B C
B B D
C B C
D B E
E B C 38