Sei sulla pagina 1di 18

NFA to DFA

DFA
For every string x, there is a unique path
from initial state and associated with x.



x is accepted if and only if this path ends
at a final state.
x
NFA
For any string x, there may exist none or
more than one path from initial state and
associated with x.
NFA DFA
Consider an NFA M=(Q, , , s, F).
For x in *, define
[x] = {q in Q | there exists a path s q}
Define DFA M=(Q, , , s, F}:
Q = { [x] | x in * },
([x], a) = [xa] for x in * and a in ,
s = [],
F = { [x] | x in L(M) }

x
Construction of M
Special Case: M has no -move.

[] = {s}
Suppose [x] is known. How to get [xa] for
a in ?
From [x] to [xa]
[xa] = { p | there exists a path q p for
some q in [x] }
= { p | there exists q in [x],
q p }

= U
a
a
q in [x]
(q,a)
edge
path
Construction of M
F = {[x] | x in L(M)}
= {[x] | [x] F }
Example 1
Construct DFA to accept 00(0+1)*
p
0
0
0
1
s
q s p
q
0
0
1

1
0,1
0, 1
Example 2
Design DFA to accept (0+1)*11
s p
1
1
0
1
q
s
1
s
p
0
1
s
q
1
0
p
0
Example 3
Design DFA to accept 00(0+1)*11
s p q r
0
1
1 0
0
1
t
s
0
p
1

0,1
1
0
q
0
1 q
r
1
q
r
t
0
0
1
Example 4
Construct DFA M for L(M)=.
s
Is this a DFA?
s
0

1
0,1
Example 5
Construct DFA M for L(M)=.
s
Is it a DFA?
s
0

0,1
1
0,1
Construction of M
For q in Q, define
-closure(q) = {p | there exists a path q p}
[] = {q | there is a path s q}
= -closure(s)
Suppose [x] is known. How to get [xa] for
a in ?


path
path
From [x] to [xa]
[xa] = { p | there exists a path q p for
some q in [x] }
= { p | there exists q in [x],
q r p }
= { p | for some q in [x] and r in (q,a),
p in -closure(r) }
= U U -closure(r)
a
a
q in [x]
r in (q,a)
edge path
path
Construction of M
F = {[x] | x in L(M)}
= {[x] | [x] F }
Example 6
Construct DFA M for L(M)=(0+1)*.
0,1

s p q
s
p
q
0
p
q
1
0,1
0,1
Example 7
Convert the following NFA to DFA.
s
p
0

0

0
1
1

0
r
s
r
p
0
q
r
p
1
s
q, r, p
0
1
0
1
q
a
s
d c b s
0,1
0
0 0
0
0
1 1
1
1
e
0
s,a
1
s,a,b
0
0
s,a,b,c
0
s,a,b,c,d
0
s,a,b,c,d,e
1
s,b
1
s,c
1
s,d
1
s,e
How many states?
2 =32
5
How many final states? 2 = 16
4
Can we simplify it?
No, it is minimum!