Minimalize DFA
2016-04-01 12:37
288 查看
DFA Minimalization
DFA最小化的第一步就是消除unreachable states。这个可以通过如下算法完成:let reachable_states:= {q0}; let new_states:= {q0}; do { temp := the empty set; for each q in new_states do for all c in Σ do temp := temp ∪ {p such that p=δ(q,c)}; end; end; new_states := temp \ reachable_states; reachable_states := reachable_states ∪ new_states; } while(new_states ≠ the empty set); unreachable_states := Q \ reachable_states;
第二部分的主要目标就是消除等价状态,这里的等价指的是Nerode equivalence。
Nerode等价来源于Myhill–Nerode theorem,这里是指对于两个状态s, t,对于任何输入a,(s, a) = (t, a)。
在这一部分的处理算法主要有Moore算法,Hopcroft算法和Brzozowski算法。这里主要介绍Moore算法和Hopcroft算法。
Moore算法的主要思想是通过对Moore等价关系的迭代计算,来逼近Nerode等价。
Hopcroft算法的主要思想则是非常直观的不断细分的算法,也就是对于原始DFA状态的一个粗划分,按照Nerode等价的要求来进行不断的细分,直到收敛。
Moore算法简介
首先定义Moore等价的概念:\(\sim_h:\ p\sim_hq\Longleftrightarrow L_p^{(h)}(\mathcal{A})=L_q^{(h)}(\mathcal{A})\), with \(L_p^{(h)}(\mathcal{A})=\{w\in A^*\lvert\ |w|\le h, p\cdot w\in F\}\)阶数迭代计算:\[p\sim_{h+1}q\Longleftrightarrow p\sim_hq\quad and\quad p\cdot a \sim_{h} q\cdot a\quad for\ all\ a\in A\]
定义DFA的深度(depth)如下:最小的h,使得\(\sim_h=\sim_{nerode}\)。可以保证,\(h \le n-2\)。
定义如下符号,对于状态集合P而言,\(P\cdot a=\{(s,\ a)\ \lvert \ s\in P \}\), \(a^{-1}\cdot P=\{t\ \lvert\ (t,\ a)\in P\}\)。
算法过程如下:
\(\mathcal{P}\ \gets \{F,\ F^c\}\), where F is the final states set.
repeat
\(\mathcal{Q}\ \gets\ P\)
for all \(a\in A\)
\(\mathcal{P_a}\ \gets\ a^{-1}\cdot\mathcal{P}\)
\(\mathcal{P}\ \gets\ \mathcal{P}\land\bigwedge_{a\in A}\mathcal{P_a}\)
until \(\mathcal{P}\ = \ \mathcal{Q}\)
注意,对于两个划分P和Q,
\(\mathcal{R}=\mathcal{P}\land\mathcal{Q}\)指的是这样一个划分,或者等价关系:
如果\(a\sim_R b\Longleftrightarrow (a\sim_{\mathcal{P}}b) \land (a\sim_{\mathcal{Q}}b)\)。
容易证明,这个算法的时间复杂度是\(O(nlogn)\)。请注意,对于\(\mathcal{P}\land\bigwedge_{a\in A}\mathcal{P_a}\)的计算我们可以采用table的方式来完成,这样的时间复杂度就是\(O(\lvert A\lvert*\lvert S\lvert)\)。
Hopcroft算法
S←{F, F^C} for all a∈A do Add((min(F, F^c), a), W) while W != ∅ do (W, a)←TakeSome(W) //select and pop for each P∈P which is split by (W , a) do P', P"←(W , a)|P Replace P by P' and P" in S for all b∈A do if(P, b)∈W then Replace (P, b) by (P', b) and (P", b) in W else Add((min(P', P"), b), W)
请注意,其中的spliter的定义:
The splitter \((P,\ a)\) splits the class \(R\in\mathcal{P}\) if
\[\Phi\subsetneq P\cap R\cdot a\subsetneq R\cdot a\]
相关文章推荐
- 腾讯在线模拟笔试题目,格雷码问题
- C++中结构体和类型的sizeof()
- 默认移动构造函数
- C++ 大数模板
- 程序运行抛出Unsupported major.minor version 52.0异常
- 窗口 子控件的使用
- Linux_ select 多路复用
- Visual C++(MFC)实现C/S
- 程序分析(2)
- 程序分析(3)
- 支付宝和内购的区别以及集成方法
- springMVC4(2)请求映射全面分析
- 源码安装Apache http server
- 什么是堆和栈,它们在哪儿?
- 程序分析(1)
- 9. Palindrome Number
- 指针数组和数组指针的区别
- 找不到或无法加载主类 com.sun.tools.javac.Main
- 本月有几天
- Python-zip压缩-解压