1. 程式人生 > >DFA 和 NFA 的區別

DFA 和 NFA 的區別

         When I first read 'DFA' and 'NFA', I feel they are very complex. but when I read the concept of them, I found they are very very simple. Not complex at all.
       DFA is acronym of deterministic finite automata. You had better know what is finite automata before trying to know DFA and NFA. An automate is a mathmatical model for finite state machine. I think everyone know finite state machine well.It is just a serial of states and the trigger condition. Finite automate is this kind of state machine which will stop after a certain steps. How doest the state machine transfer state is regulating by its onwer internal  principle and the input.
  An automata is represented by the 5-tuple (set of states, finite set of symbols,transition function, start state, accepted state). You can find the detailed definition at (http://en.wikipedia.org/wiki/Automate_theory).
   The difference between DFA and NFA :
   1. Deterministic finite automate :
    Each state of an automaton of this kind has a transition for every symbol in the alphabet.
   2. Nondeterministic finite automate :
     States of an automaton of this kind may or may not have a transition for each symbol for each symbol in the alphabetet, or can even have multiple for a symbol. If a transition is undefined, so that the automaton doesn't know how to keep on reading the input, the word is rejected.
   
     我的理解就是:
    1.  DFA在任何狀態對於任何輸入都是有一個明確的處理(state transiton),  而NFA 不然。
    2. 如果輸入集合為N,狀態幾個為M,則DFA 的狀態遷移矩陣應該為N X M, 而NFA 的狀態遷移矩陣是可以儲存裁剪的。
   3. DFA 之所以比 NFA 快是因為DFA 在任何狀態都與任何輸入的處理都是確定的,而NFA 不能夠確定處理(需要藉助輔助資訊)
   4. 關於 DFA 不支援backtrack 和 NFA 支援 backtrack , 這個不是 DFA 和 NFA 的本質區別,而是由於各自的本質特性導致在實現上的差異而帶來的不同效果。就好像是一個沒有腿的人,要走路必須做電動車,結果是比有腿走路的人快,所以說沒腿的人走的快不是本質的區別。