Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm: Constructing deterministic finite utomton from nondeterministic one. Input: n NF N. Output: F ccepting the sme lnguge. Method: Ech stte of is set of sttes which N could e in fter reding some sequence of input symols. Thus is le to simulte ll possile moves N cn mke on given input string. The initil stte of is the set consisting of S0, the initil stte of N, together with ll sttes of N tht cn e reched from S0 y mens of -trnsition only. The ccepting sttes of re those sets of sttes tht contin t lest one ccepting sttes of N. Let us define the function -CLOSURE (s) to e the set of sttes of N uilt y pplying the following rules:- 1- S is dded to -CLOSURE (s). 2- If t is in -CLOSURE (s), nd there is n edge leled from t to u, then u is dded to -CLOSURE (s) if u is not lredy there. Rule 2 is repeted until no more sttes cn e dded to -CLOSURE (s). Thus, -CLOSURE (s) is just the set of sttes tht cn e reched from S on - trnsition lone. If T is set of sttes, then -CLOSURE (T) is just the union over ll sttes S in T of -CLOSURE (S). The computtion of -CLOSURE (T) is typicl process of serching grph for nodes rechle from given set of nodes. In this cse the nodes of T re the given set, nd the grph consists of the - leled edge of the trnsition digrm only. simple lgorithm to compute -CLOSURE (T) is shown in Fig.14 31
egin Push ll sttes in T onto STCK; -CLOSURE (T):=T; While STCK not empty do Pop S, the top element of STCK, off of stck; For ech stte t with n edge from S to t leled do End End If t is not in -CLOSURE (T) then egin End dd t to -CLOSURE (T); Push t onto STCK; Fig.14: Computtion of -CLOSURE The sttes of nd their trnsition re constructed s follows. Initilly, let - CLOSURE (S0) e stte of. This stte is the strt stte of. We ssume ech stte of is initilly "unmrked". Then perform the lgorithm of Fig.15. While there is n unmrked stte x= (S1, S2... S n ) of do egin Mrk x; For ech input symol do egin Let T e the set of sttes to which there is trnsition on '' from some stte Si in x; End y: = -CLOSURE (T); If y hs not yet een dded to the set of sttes of then Mke y n "unmrked" stte of ; dd trnsition from x to y leled if not lredy present End Fig.15: The Suset Construction 32
Exmple Convert the NF shown in Fig.16 into F 0 1 6 7 8 9 10 2 4 3 5 Fig.16: NF N for ()*. Fig.16 shows NF N ccepting the lnguge ()*. The initil stte of the equivlent F is -CLOSURE (0), which is = {0, 1, 2, 4, 7}, since these re exctly the sttes rechle from stte 0 vi pth in which every edge is leled. Note tht 0 is reched from itself y such pth, the pth hving no edges. The lgorithm of Fig.15 tell us to set x to nd compute T, the set of sttes of N hving trnsitions on from memers of. mong the sttes 0, 1, 2, 4 nd 7, only 2 nd 7 hve such trnsition, to 3 nd 8, so y= -CLOSURE ({3, 8}) = {1, 2, 3, 4, 6, 7, 8} Let us cll this set. mong the sttes in, only 4 hs trnsition on to 5, so the F hs trnsition on from to C= -CLOSURE ({5}) = {1, 2, 4, 5, 6, 7} Then we hve two trnsitions:- C We continue this lgorithm for stte nd C. 33
1- For set - If the input is symol "", then only stte 2 nd 7 give trnsition on symol "" to stte 3 nd 8, therefore -CLOSURE({3,8})=, then we hve this trnsition - If the input is symol "", then only stte 4 nd 8 give trnsition on symol "" to stte 5 nd 9, therefore -CLOSURE ({5, 9}) = {1, 2, 4, 5, 6, 7, 9} Let us cll this set. ecuse stte not dded to the stte of F, then we dd it, with trnsition:- 2- For set C - If the input symol is "", then only stte 2 nd 7 hve trnsition on "" to stte 3 nd 8, therefore -CLOSURE ({3, 8}) =, then the trnsition is: C - If the input symol is "", then only stte 4 gives trnsition on to stte 5, therefore -CLOSURE (5) =C, then the trnsition is:- C C 3- For set :- - If the input symol is "", then only stte 2 nd 7 gives trnsition on "" to stte 3 nd 8, therefore -CLOSURE ({3, 8}) =, then the trnsition is - If the input symol is "" then only stte 4 nd 9 gives trnsition on "" to stte 5, nd 10, therefore:- -CLOSURE ({5, 10}) = {1, 2, 4, 5, 6, 7, 10} Let us cll this E, then the trnsition:- 4- For set E E 34
- If the input symol is "", then only stte 2 nd 7 given trnsition on "" to stte 3 nd 8, therefore:- -CLOSURE ({3, 8}) =, then the trnsition is E - If the input symol is "", then only stte 4 gives trnsition on "" to stte 5, therefore -CLOSURE (5) =C, then the trnsition is:- E C The trnsition tle for NF is shown in Fig.17, nd the F equivlent to NF of Fig.16 is shown in Fig.18. The finl stte is E ecuse it contin the stte 10 which is the finl stte for NF in Fig.16. (Strt) (ccept) Stte Input C C C E E C Fig.17: Trnsition Tle Strt C E Fig.18: F ccepting ()*. 35
Minimizing the Numer of sttes of F The F of Fig (18) constructed from the NF of Fig (16) is not the smllest possile. In prticulr, we show Fig (12), nother F with only four sttes tht lso ccept ()*. Prt of the reson for this nonminimlity of the suset construction lies in the fct tht we did not include in the lgorithm, for converting NF to F, some ovious stte identifictions tht could e mde. There re two methods for minimizing the numer of sttes nd trnsitions:- 1-Empiricl Method: This method minimized the numer of sttes nd trnsitions ccording to the following steps:- - We merge two sttes in F in one stte if they hve the sme importnt sttes. The importnt stte is the stte with no -trnsition - We merge two sttes if they either oth include or oth exclude ccepting sttes of the NF. Exmple: Minimize the F shown in Fig.19 ccording to the Empiricl method. Strt C Fig.19: F ccepting ()* = {0}, = {1, 2, 8, 3, 5}, C= {4, 7, 8, 2, 3, 5}, = {6, 7, 8, 2, 3, 5} Finl is stte 8. From Fig.19 we know tht the lnguge tht NF re shown in Fig.20 36
0 Letter 1 2 Letter 3 4 igit 5 6 7 8 Fig.20: NF ccepting ()* The importnt sttes in Fig.20 re {0, 3, 5}. We see tht stte nd C contin the sme importnt nd contin the finl stte (8), therefore we cn merge these two sttes into one stte nmed C, nd then the result is C C= {1, 2, 3, 4, 5, 6, 7, 8} fter tht we look to the stte C nd stte nd see tht they hve the sme importnt stte nd the sme finl stte, therefore we cn merge these sttes into nother stte clled C then the minimized F is shown in Fig.21. C Fig.21: NF ccepting ()* 37
2- Forml Method In this method we don t need to experience for deciding which of the stte tht re legl for merging, insted of stte we must use the following lgorithm:- lgorithm: - Minimizing the numer of sttes of F Input: - F M with set of sttes S, inputs, trnsitions defined for ll sttes nd inputs, initil stte S0, nd set the finl stte F. Output: - F M ' ccepting the sme lnguge s M nd hving s few sttes s possile. Method:- 1- We construct prtition T of the set of sttes Initilly, T consist of two groups, the finl sttes F, nd the non finl sttes S-F. Then we construct new prtition Tnew y the procedure of Fig (22). Tnew will lwys e refinement of T, mening tht Tnew consists of the groups of T, ech split into one or more pieces. If Tnew = T, then no more chnges cn ever occur, so we terminte this prt of the lgorithm: For ech group G of T do egin Prtitions G into sugroups such tht two sttes S nd t of G re in the sme sugroup iff for ll input symol, sttes S nd t hve trnsitions on to sttes in the sme group of T; End. Plce ll sugroups so formed in Tnew; Fig (22). New prtition Tnew 2- When the finl prtition T hs een constructed in step (1), select representtive for ech group, tht is, n ritrry stte in the group. The representtive will e the sttes of the reduced F M '. Let S e representtive stte, nd suppose on input there is trnsition of M from s to t. Let r e the representtive of t's group (r my e t). Then M ' hs trnsition from S to r on. Let the initil stte of M ' e the representtive of the group contining the initil S0 38
of M, nd let the finl sttes of M ' e the representtive which re in F. Note tht ech group of T either consists only of sttes in F or hs no sttes in F. 3- If M ' hs ded stte, tht is, stte d which is not finl nd with trnsitions to itself on ll input symol, then remove d from M '. lso remove ny stts not rechle from the initil stte. ny trnsitions to d from other sttes ecome undefined. Exmple:- Minimize The F shown in Fig.18 Solution: The initil prtition of T consists of two groups: 1- The finl sttes:- which contins (E) 2- The non finl sttes:- which contins (C). To construct Tnew y the lgorithm of Fig (22), (1) We first consider (E), since this consists of one stte, it cnnot e further split, so we plce (E) in Tnew. (2) Now consider (C) nd do the following:- () If the input is, then ech of these sttes goes to, so they could ll e plced in one group s fr s input is consumed. () If the input is, then,, nd C go to memers of the group (C) of T, while goes to E, memer of nother group. Thus, in Tnew (C) must e split into groups (C) nd (). The new vlue of T is thus (C)() (E). Constructing the next Tnew, we given hve no splitting on input, ut (C) must e split into two groups (C) (), since on input nd C ech go to C, while goes to, memer of group of T different from tht of C. Thus the next vlue of T is (C) () () (E). When we construct Tnew from this, we cnnot split ny of the groups consisting of single stte. The only possiility is tht (C) could e split. ut nd C go to the sme stte,, on input, nd they go to the sme stte, C, on input. Hence, Tnew=T, nd the finl prtition T from step (1) of lgorithm is (C) () () (E). 39
Let us now choose representtives. Of course, nd E represent the group contining only themselves. Let us choose to represent the group (C). Then the trnsition tle for the reduce utomton is shown in Fig.23. (Strt) (ccept) Stte Input E E Fig.23: Reduced utomton For exmple, E goes to C on input in the utomt of Fig.18. Since is the representtive of the group for C, we hve trnsition from E to on input in Fig.23. similr chnge hs tken plce in entry for on input, nd ll other trnsitions re copied from Fig.18. There is no ded stte in Fig.23, nd ll sttes re rechle from the initil stte. Fig.24 shows the minimized F. Strt E Fig.24: Minimized F ccepting ()*. 40