TOC Lec3
TOC Lec3
DFA with Subset Construction NFA N => DFA M construction: + DFA Mhas a trap state ERR Given N = (Q, ©, 8, Go, F) Construct M = (Q’, 5, 8, q'o F’) Q’< 22, all the possible states of NFA, M could be in. qo = s-closure(qq) — Initial state of DFA M Define transition for all new states and alla € 5. 8°(T, a) = e-closure(move(T, a)) for alla © Tis the set of state(s). If there is no new state, stop. The final state of DFA is the one in which at least one state is NFA’s final state F= {qe Q|q'nF #2}NFA-to-DFA: No-A transition Subset Construction 1. The subset construction gives us 25 = 32 states; including ‘no! reachable states’. 2. Consider the ‘reachable states from 0? (subsets of q) and defines transitions for all new states. Use a transition table/transition diagram to convert an NFA to DFA a b o {1,2} {4} 1 {0} co 2 {8} co 3 {0}NFA-to-DFA: No-A transition Subset Construction an NFA to DFA >(0} {1,2} {4} 12) 3} {0.3} {1,2} {0,4} 40,4) (1,2) U4} 4 0 O a b {1,2} {4} a ow = 0NFA-to-DFA: No-A transition Subset Construction NFA oO 1 Start —— DFACONVERSION: NFA TO DFA NFA M ae) g eeConversion: NFA to DFA.. DFA If DFA = io a | +({¢0}) {{a.42}) ~ |} ——{q.9) Se nin sl ( © )trap stateConversion: NFA to DFA.....Conversion: NFA to DFA rae) NFA a iC mon “© QeF DFA i “(o: ei la.a}eFConvert the following NFAs to DFAs Exercise-1 Exercise-2 Go {doa} > {a} % {Gorn} {a2} a + favab a 6 {ayaa} {a1 a2} a {a2} ¢ 4 % e ¢ % Exercise-3 ct {Gorn} I srings such thet te thd symbol from the right end ise "1" over 0, 1}. Convert NFA. into DFA. {a a2} ‘Construct NFA for ail strings that contain the substring 0101 over {Q, 1}. Convert NFA into DFA,Minimum DFA > Any DFA accepts a unique language (regular language), + Fora given language, there exist many DFA’s- Ditferent DFAs for the same language have different number of slates, + Considerable difference in the number of states of such equivelent DFAs. + Theorem: For every regular language L, a unique minimal DFA M exists such that L= LM, It is not true for NFAS, + _ Two minimal NFAs for the same language. L= {w,0"lw,: n >= 0, w, € {0, 1}, w, € {0, 1}*} In figure (a) + The DPA (a) consists of inaccessiblefunreachablefuseless oe states. (qs plays no role), +The inaccessible states can be removed along with : | ‘wansitions without any effect. + qyand g, are images ofeach other. + quand q, are images of each othr:Minimum DFA + Minimize a DFA, + "Minimal”?- Minimum Number Of States. * Find an equivalent DFA with the least possible number of states (minimum DFA). + “Unique”? + Unique up to the renaming of states, i.e, it has the same shape. (/somorphic). + Why Minimization? + To write a program (e.g., A compiler) or to design hardware using DFA, there will be a significant benefit in mi it before implementing it.Indistinguishable States: Key Idea + Let M be a DFA. + For all w £ Z*, two states, p, and g, are called indistinguishable (equivalent) if 5*(p, w) « F implies 5*(q, w) ¢ F Or 8*(p, w) € F implies 3*(q, w) ¢ F pa the “indistinguishable” relation is an “equivalent” relation. + LetMbea DFA, For states | and 2, w= a, w=b 5*(1,a)=2 €F and 5¢(2,0)~6€F S*(1,b)=7€F and 5°2,b)=3€F Ir means states I and 2 are inistinguishable forall strings with length one Forstates I and 2 and waa 8*(1,aa)= 6 F and 8°, 2 ‘means states Land 2 are not indistinguishable for waa s®. Check all pairs for w 22, (1,2) (3) (1, 4 (1, 5) (1) (057) (1,8) (1,9) (10) IGM roe 1,10)DISTINGUISHABLE STATES + Let M be a DFA. If there exists some string w € 3* such that 5*(p, w) €Fand 6*(q,w) EF Or — S*(p, w) € Fand 6%(q, w) EF + Then, the states p and q are distinguished by a string w. * The “distinguishable” relation is the “not equivalent” relation. For states 4 and 5 8*(4, 0) =5¢F and 6*5,a)=10eF lt means states 4 and 5 are distinguishable for w = a € 2. i.e., states 4 and 5 are distinguishable for strings of length one.Indistinguishable/Distinguishable Relation + Indistinguishable (“= js an equivalenc P (reflexive) (symmetric) r=>Pp (transitive) + The distinguishable relation is not an equivalence relation. + If p ond q are distinguishable and q and r are also distinguishable + Then p and r are not necessarily distinguishable. FTet hi be a BFA. (p, w) © F implies 5*(a, w) © F 57(p, w) EF implies 8*(a, w) € F * Let M be a DFA + Ifthere exists some string w e Z* such that 5*(p, w) €F and 6°(q, w) ¢F oR 5*(p, w) €F and 6*(q, w) eF + Then the states p and q are said to be distinguishable by a string w.Minimizing a DFA + To minimize a DFA, + Remove unreachable/inaccessible/useless states + States which are not reachable from the initial state(s). + oR + States which are also not connected with final states + Identify equivalence classes of indistinguishable states + Replace the equivalence class with a single state, + The problem is determining “Which DFA states are distinguishable and indistingsThe Minimization Algorithm Given a DFA M =(Q, 5, 5, qo, F); find the minimum DFA M’ 1, _ Remove inaccessible/unreachable/uscless states. 2. Initialize the partition; x ~ {F, QF} 3. Form=1, 2, so + Compute the equivalence class x, using + Forall sets Sex, + Forallg,,q@eS + Forallae® + 1f8(q,, a) and 8(q,, a) make a transition to the states of the same set of x, , +g, and q, are indistinguishable. + Otherwise, q, and q, are distinguishable. Then, split the set S + Repeat step 3 until, for some, T,, _ = Ty 4, Replace each equivalence class of states with a single state + The initial state is the set of states consisting of the initial state + The final state nal state isthe set of states consisting of at least one + This must eventually happen. + Why?DFA minimization: Example M=(Q, &, 5, dor F) = ( {1,2,3,4,5,6,7,8,9, 10}, {a,b}, 6 1, {10} ) Step I: Remove useless Step 2: Initialize the partition m, %) = {Q-F, F} m= {{1, 2, 3,4, 5, 6,7, 8,9}, {10}}DFA minimization-Example:Construct 1, partition Tp = (1, 2, 3, 4, 5, 6, 7, 8, 9}, (10}} ‘Apply the “actansitons” to each lass the next states are (2,6,8,5, 10, 10,2,5,4), {10}, + The a-ransitions indicate that Sand 6 are ina different class than 12,3, 4, 7,8, and 9 + The astansiions spit {1 2,3,4,5,6, 7, 8,9 } {10)) ito (1,2, 3,4, 78,9} {6} and {10) Le, (01.2,3.4,7,8.9), (5.6), (10) | + transitions ‘> Apply the “brnsitons” to each class, the next states are (7,3,9,3, 73,947, 10), {00 + The b-tranitions indicate that 9 in different cae than 1,2, 3,4, 5, 6,7, 0 8 {+The buansiions futher split {1,2,3,4, 7,8, 9}, 15,6), (10) } ino (0, 2,3, 47,8) 5,6), (9), to} ie The Th, psttion is Th ((1,2,5.4,,8), (5.6), 9) (10) ) 5,4 compute m,EXAMPLE: THE IT, PARTITION m= {{1,2,3,4, 7,8}, (5, 6}, {9}, {10} } + apply the a-transitions to the set (classes) in m, {2,6,8, 5, 2,5}, (10, 10}, {4}, {10} + the a-transitions split {1, 2, 3, 4, 7, 8} into (1, 3, 7} and (2, 4,8}. + apply the b-transitions to the set (classes) in m, {7,3,9.3,9, 7}. {7,3}, {10}, {10} + the betransitions split further into {1} , {2, 4, 8} and (3, 7}. 6S | @ la b 4, + my ={{1}, (3, 7}, (2, 4, 8}, {5, 6}, {9}, {103} + m= €(1,2,3,4, 7,8}, (5, 6}, + m,# 7m, . compute m, {9}, {10} }EXAMPLE-1: THE I, PARTITION in UAT}, 13, 7h, 42,4, 8h, (5, 6}, {9}, {10}} apply the a-transitions to these classes: {2}, {8,2}, (6,5, 5}, (10, 10}, {4}, {10}. apply the b-transitions to these classes: {7}, {9,9}, (3,3, The {7,3}, {10}, {10}. no further split + it produces no new classes. + itmeans x, =, . stop,DFA MINIMIZATION: EXAMPLE-1 my =tE1}, €2,4, 8), 3, 7), 5, 6}, (9}, (10}} + Replace each equivalence class of states with a single state + Merge states 2, 4, and 8 into one state. + Merge states 3 and 7 into one state. + Merge states 5 and 6 into one state, The initial state is the set of states consisting of the initial state, ‘The final state is the set of states consisting of at least one final state.DFA MINIMIZATION: EXAMPLE-1 My ={A1}, (2, 4, 8}, {3,7}, (5, 6}, {9}, {10}}- * initial state = {1} * final state = { {10} } + replace each of these classes with a single state.DFA Minimization: What about transitions? Are they lost? No Given DFA M M=(Q, 2, 5, ao, F) M=( {1,2,3,4,5,6,7,8,9,10}, {a,b}, 5, 1, {10} )FIND THE MINIMUM DFA