视频教程,点这里
DFA构成:五元组(K,∑,f,S,Z)
NFA构成:五元组
DFA M = ({S,U,V,Q},{a,b},f,S,{Q}),其中f定义为
f(S,a) = U, f(U,a) = Q, f(V,a) = U, f(Q,a) = Q,
f(S,b) = V, f(U,b) = V, f(V,b) = Q, f(Q,b) = Q
状态\符号 | a | b |
---|---|---|
S | U | V |
U | Q | V |
V | U | Q |
Q | Q | Q |
move(I,a):其中I是一个集合,a是一条弧。表示I中每个状态经过一条a弧后,所能达到的状态的集合。
这里介绍 子集法,假设NFA N = (K,∑,f,K0,Kt),构造一个等价DFA M = (S,∑,D,S0,St)
步骤
1) 计算ε-closure(K0),取名T0
2)标记T0以处理,分别计算ε-closure(move(T0,∑的单个输入),取名Tx……Ty
3)标记已处理,对新的Tx-Ty重复第二步,直到不再产生新的Ti集合为止
4)按照1、2、3步的关系,确定所有的T集合之间的转换关系
5)S0=[T0],St=含有NFA中的终态的那个T集合
6)画出状态图
例子
- 计算ε-closure(K0),取名T0,K0只有一个0状态
T0 = ε-closure(0) = {0,1,2,4,7}
----------------------------------------------T0------------------------------------------------
Ti = ε-closure(move(T0,a))
move(T0,a) = {3,8}
T1 = {1,2,3,4,6,7,8}
Ti = ε-closure(move(T0,b))
move(T0,b) = {5}
T2 = {1,2,4,5,6,7}
----------------------------------------------T1------------------------------------------------
T1 = {1,2,3,4,6,7,8}
Ti = ε-closure(move(T1,a))
move(T1,a) = {3,8}
Ti = T1
Ti = ε-closure(move(T1,b))
move(T1,b) = {5,9}
T3 = {1,2,4,5,6,7,9}
----------------------------------------------T2------------------------------------------------
T2 = {1,2,4,5,6,7}
Ti = ε-closure(move(T2,a))
move(T2,a) = {3,8}
Ti = T1
Ti = ε-closure(move(T2,b))
move(T2,b) = {5}
Ti = T2
----------------------------------------------T3------------------------------------------------
T3 = {1,2,4,5,6,7,9}
Ti = ε-closure(move(T3,a))
move(T3,a) = {3,8}
Ti = T1
Ti = ε-closure(move(T3,b))
move(T3,b) = {5,10}
T4 = {1,2,4,5,6,7,10}
----------------------------------------------T4------------------------------------------------
T4 = {1,2,4,5,6,7,10}
Ti = ε-closure(move(T4,a))
move(T4,a) = {3,8}
Ti = T1
Ti = ε-closure(move(T4,b))
move(T4,b) = {5}
Ti = T2
D(T0,a) = T1
D(T0,b) = T2
D(T1,a) = T1
D(T1,b) = T3
D(T2,a) = T1
D(T2,b) = T2
D(T3,a) = T1
D(T3,b) = T4
D(T4,a) = T1
D(T4,b) = T2
视频教程,点这里
课件下载:
关注下方微信公众号,
回复:
NFA转DFA.code
欢迎加入交流群:451826376
更多信息:www.itcourse.top