Running n NFA & the suset lgorithm (NFA->DFA) CS 350 Fll 2018 gilry.org/lsses/fll2018/s350/ 1
NFAs operte y simultneously exploring ll pths nd epting if ny pth termintes t n ept stte.!2
Try n exmple: L is the lnguge L(( )*). q0 q1,!3
Let s run this nondeterministilly on the string nd trk wht pths we n tke: q0 q1,!4
Let s run this nondeterministilly on the string nd trk wht pths we n tke: q0 q1,!5
Let s run this nondeterministilly on the string / nd trk wht pths we n tke: q0 q1,!6
Let s run this nondeterministilly on the string // nd trk wht pths we n tke: q0 q1,!7
Let s run this nondeterministilly on the string /// nd trk wht pths we n tke: q0 q1,!8
Let s run this nondeterministilly on the string //// nd trk wht pths we n tke: q0 q1,!9
Let s run this nondeterministilly on the string ///// nd trk wht pths we n tke: If ny possile pth would ept, then the NFA epts. q0 q1,!10
Consider tht wht n e deterministilly known out n NFA, fter onsuming string, is not single stte the mhine must oupy, ut the set of NFA sttes the mhine ould oupy.!11
Try n exmple: L(( )( )*) L is the lnguge.!12
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q4 q5!13
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q6 q4 q5!14
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q7 q8 q6 q9 q4 q5 q10!15
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q11 q7 q8 q6 q9 q4 q5 q10!16
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q11 q7 q8 q6 q9 q4 q5 q10!17
Now onsider the sttes visited t eh step, running the string: {q 9 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!18 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 9 } {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!19 q5 q10
The ε-losure of set of sttes is the set of sttes whih re rehle without onsuming ny hrters/strings. (Another fixpoint itertion.) losure δ : P(Q) P(Q) losure δ (qs) = ext N δ (qs) where ext N 1 (qs) = ext δ N δ (qs) ext δ (qs) = qs {q q qs (q,, q ) δ}!20
Now onsider the sttes visited t eh step, running the string: {q 9 } {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!21 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } {q 5 } / q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!22 q5 q10
The move of set of sttes nd hrter s, is the set of sttes whih re rehle from ny input stte, vi single trnsition on the hrter s. move δ : P(Q) Σ P(Q) move δ (qs, s) = {q q qs (q, s, q ) δ}!23
Now onsider the sttes visited t eh step, running the string: {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } {q 5 } / q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!24 q5 q10
Now onsider the sttes visited t eh step, running the string: / {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } {q 5, q 10, q 11, q 7, q 2, q 0 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!25 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 5, q 10, q 11, q 7, q 2, q 0 } {q 3 } // q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!26 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 5, q 10, q 11, q 7, q 2, q 0 } // {q 3, q 8, q 11, q 7, q 2, q 0 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!27 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 3, q 8, q 11, q 7, q 2, q 0 } {q 1 } /// q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!28 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 3, q 8, q 11, q 7, q 2, q 0 } /// {q 1, q 8, q 11, q 7, q 2, q 0 } q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!29 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 1, q 8, q 11, q 7, q 2, q 0 } {q 3 } //// q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!30 q5 q10
Now onsider the sttes visited t eh step, running the string: {q 1, q 8, q 11, q 7, q 2, q 0 } {q 3, q 8, q 11, q 7, q 2, q 0 } //// q0 q1 q11 q7 q8 q6 q9 L(( )( )*) q4!31 q5 q10
Now onsider the sttes visited t eh step, running the string: //// {q 3, q 8, q 11, q 7, q 2, q 0 } {q 11 } Ø q0 q1 q11 q7 q8 q6 q9 q10 L(( )( )*) q4!32 q5
So, if we n deterministilly step through n NFA using sets of NFA sttes insted of single NFA sttes, n we produe DFA from n NFA tht enodes these sets of sttes? {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } YES {q 5, q 10, q 11, q 7, q 2, q 0 } {q 3, q 8, q 11, q 7, q 2, q 0 } {q 1, q 8, q 11, q 7, q 2, q 0 }!33
So, if we n deterministilly step through n NFA using sets of NFA sttes insted of single NFA sttes, n we produe DFA from n NFA tht enodes these sets of sttes? {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } YES {q 5, q 10, q 11, q 7, q 2, q 0 } {q 3, q 8, q 11, q 7, q 2, q 0 } Wht we just worked through is just frgment of the DFA enoding this NFA! {q 1, q 8, q 11, q 7, q 2, q 0 }!34
Models of regulr lnguges Converts to GNFA Converts to RE DFA Minimizes to Converts to NFA Converts to!35
The suset lgorithm!36
The suset lgorithm Input: NFA (Q, Σ, δq, q0, FQ) Output: DFA (D, Σ, δd, d0, FD) Let d0 = ε-losureδ({q0}) mrked = {} D = {d0} δd = {} While d D suh tht d mrked: mrked = mrked {d} For eh s Σ: Let dmv = moveδ(d,s) Let dmv+ε = ε-losureδ(dmv) If dmv+ε D: D = D {dmv+ε} δd = δd {(d,s,dmv+ε)} FD = { d D q d. q FQ}!37
Try n exmple: L(( )( )*) L is the lnguge. q0 q1 q11 q7 q8 q6 q9 q4 q5 q10!38
Try n exmple: L(( )( )*) L is the lnguge. {q 5, q 10, q 11, q 7, q 2, q 0 } {q 1, q 8, q 11, q 7, q 2, q 0 } d1 d0 d2 d3 {q 9, q 4, q 6, q 10, q 11, q 7, q 2, q 0 } {q 3, q 8, q 11, q 7, q 2, q 0 }!39