Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will drw one. Q Q Q2 Stte Trnsition Tle From Stte Input Symol To Stte Q {Q, Q} Q {Q} Q {Q2} Initil Stte = Q Finl Stte = Q2 Alphet = {.} Note: There is no entry where From Stte = Q nd Input Symol = i.e., δ (Q, ) = {}; It is null stte Note: In the lst two entries, though the next stte or to stte is single nd not set, the convention is to represent is set contining one element. Exmple 2 Convert the ove NFA to DFA We tke up the trnsition tle nd replce ech set of sttes y single new stte. In the exmple, we comine replce {Q,Q} y Q. From Stte Input Symol To Stte Q Q Q Q Q Q2 Now we need to define trnsition rules for this new stte Q.
δ (Q, ) = δ (Q, ) + δ (Q, ) = Q + Φ = Q δ (Q, ) = δ (Q, ) + δ (Q, ) = Q + Q2 = Q2 (gin new stte) Define trnsition rules for this new stte Q2. δ (Q2, ) = δ (Q, ) + δ (Q2, ) = Q + Φ = Q δ (Q2, ) = δ (Q, ) + δ (Q2, ) = Q + Φ = Q Incorporting the ove entries, the trnsition tle for the resultnt DFA is: From Stte Input Symol To Stte Q Q Q Q Q Q2 Q Q Q Q2 Q2 Q Q2 Q Some ction is still remining.. We hve to identify the finl stte. The finl stte in the NFA ws Q2. Therefore, the finl stte in the equivlent DFA will e Q2 s it contins Q2. 2. There is no trnsition from the stte Q2. Hence, Q2 ecomes redundnt. So, the finl trnsition tle ecomes: From Stte Input Symol To Stte Q Q Q Q Q Q Q Q2 Q2 Q Q2 Q
Drwing the digrm: Q Q Q2 Exmple 3 All strings over {,} tht contin t lest two s., Q Q Q2 The Regulr Expression for the mchine = **(+)* Alterntively, (+)*(+)*(+)*
Exmple 4 All strings over {,} tht do not end with. Hint: first drw the DFA for strings tht end with nd then tke complement. Refer Exmple. Then convert ech non finl stte to finl stte nd ech finl stte to non finl stte. Q Q Q2 Alterntive: Directly. This wy the numer of sttes is reduced. Q Q Exmple 5 Even numer of s nd s Hint: We give some nmes to the sttes which will reflect the nture of input rech there. Stte: e-e (mening even s, even s) This stte is reched with even numer of s even numer of s. e-e e-o o-e o-o to nd Stte: o-e (mening odd s, even s) This stte is reched with odd numer of s nd even numer of s.
Stte: o-o (mening odd s, odd s); This stte is reched with odd numer of s nd odd numer of s. Stte: e-o (mening even s, odd s); This stte is reched with even numer of s nd odd numer of s Exmple 6 n :n>=,, Trp stte Exmple 7 All strings of {,} with prefix,, Trp stte
Exmple 8 Automton over {,} ccepting ll strings not contining, Trp stte Exmple 9 Finite utomton over lphet {,} tht strt with nd ends with {w : w {,}*}, Trp stte
Exmple DFA for integers divisile y 3. Answer: Since the DFA reds integers, they will consist of digit -9. i.e., Σ = {,,2,3,4,5,6,7,8,9} Now we drw the trnsition digrm.,3,6,9,4,7,3,6,9 I,4,7 2,5,8 II,4,7,3,6,9 III 2,5,8 Note: Stte I is reched when reminder = Stte II is reched when reminder = Stte III is reched when reminder = 2
Exmple Design Mely mchine which reds nd ccepts strings over {,} nd outputs when doule occurrence of is found. Else, outputs. Answer: Σ = {,} Δ = {,} Exmple Input: Output produced: / / / / / / Exmple 2 Drw Mely mchine which ccepts {,} nd outputs for first occurrence of nd then for ech susequent nd. Answer: / / / q q2 / / / q Current Stte Input Next Stte Output q q q q2 q q q q2 q2 q q2 q2
Convert the ove to Moore mchine q/ε q/ q3/ q2/
Exmple 3 Drw NFA for (+)*((+)* + (+)*)(+)*,,,,
Exmple 4 Find deterministic finite utomton equivlent to the NFA M=({q,q,q2},{,},δ, qo,{q}) Where δ is given y Stte \ Input => q q,q q q q2 q2 q2 - q2 Answer: Consider [q,q] s new stte nd define trnsitions from the sme. You get new comined sttes [q,q,q2] nd [q,q2]. So, define trnsitions for them s well to rrive t the following: Stte \ Input q [q,q] q q q2 q2 q2 - q2 [q,q] [q,q,q2] [q,q2] [q,q2] [q2] [q2] [q,q,q2] [q,q,q2] [q,q2] Finl sttes: q, [q, q], [q, q2] nd [q, q, q2] ecuse they ll contin the previous finl stte q. Initil stte remins s q.
Exmple 5 Construct DFA equivlent to the following NFA: c q q c, q3 c q4 q2 c The trnsition tle: Stte / Input c q q,q4 q4 q2,q3 q - q4 - q2 - - q2, q3 q3 - q4 - q4 - - - Derive the trnsition functions for the new sttes [q, q4] nd [q2, q3] Stte / Input c q q,q4 q4 q2,q3 q - q4 - q2 - - q2, q3 q3 - q4 - q4 - - - q2,q3 - q4 q2,q3 q,q4 - q4 -
Note tht q2 nd q3 s seprte sttes re unrechle. So, they re removed, though present in comintion with others, viz., [q2,q3]. Therefore, the finl stte tle ecomes: Stte / Input c q q,q4 q4 q2,q3 q - q4 - q4 - - - q2,q3 - q4 q2,q3 q,q4 - q4 - Exmple 6 Otin n NFA which should ccept lnguge L, given y L = {x {, }* x >=3 nd third symol of x from the right is Answer: The conditions re () () Third symol from the right is. Symol in ny other position cn e or.,,, q q q2 q3