0% found this document useful (0 votes)
2K views49 pages

DFA NFA Example

Uploaded by

sheham ihjam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2K views49 pages

DFA NFA Example

Uploaded by

sheham ihjam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Example 5 Design a DFA that reads strings niade up of letters in the ‘CHARIOT’ and recognize those strings that contain the word ‘CAT’ as a substring. Solution, Here £=(C, H, A, R, I, O, T} The transition graph is as follows : HAR1O,T @ CHARLO,T HAR IO The transition table 8 for the FA can be shown as Tessa % | %» | % | % 4 o | > [2 | >| mo lm | w b o | m] | oa) m | m | 4 a Here we can see that the 4p is the initial state and gy is the final state Example 6 Design a DEA that reads strings made up of {0, 1}and accept only those strings with ends up in either 00 or 11. Solution. Here the FA has two different final states q, and qy. 9, state accepts strings ending with “00” and q, accepts string ending with “11”, : __INTRODUCTION TO AUTOMATA THEORY 33 Transition table for the FA shown in above Figure as follows : Input State a 9 1 > % 4 % a n b h n % 4% 4 % % Gy s pyample 7 Design a DFA for the language + ( L={w:n, (w)21 we(a, ¥)') (@ L=(win,(w)=1 wl, by} Solution. Let DFA be M=(Q, = 8, Go F) (@) Here language L contains exactly only ‘a only since m, (w)=1 Thatis a, ab, abb, ba, babb, bb..a, abbb.. ‘The transition diagram will be as chown in the Figure alongside. B > a Here, (qo, 1)€Q qq is the initial state E=(a,b) 4 is the final state. (0) Now the given language is L={w:n, (w)21 wea, 0)” _. That is, it contains the set of strings in which every string whare in the string such as a, bab,bba, babb, bb...a, babb...b. ‘The transition diagram is as shown below. Here, (qo, m)€Q Qe 4q is the initial state ome Z=(a, b) ris the final state. Sxample 8 _ Design a deterministic finite automata for the given language : L=(win,(w)21 and n,(w)=2, w ela, oy) containing at least one ‘a’ any § CF 34 THEORY OF AUTOMATA & FORMAL LANGUAGES. _ Solution, Here language L contains 1, (w)21 and 1,(w)=2 i.e. every sing ofthe language must contain at least one’ and exactly two b’s such as ba, bab, ab, baab, baa..ab, aa...abba..., ‘The transition diagram will be as follows : Here (or 41, far 951 441 457 4s EQ F=(q5, 4) Z=(a, b). Rae Design a DFA for the language : L=(w, abw,: w,, w, €(a, bY") Solution, Here language L contains every string at least one abin the string at any position ie., bab, ab, aabb, babb, abbb etc. The transition diagram will be as follows : 38 Here Q={4p, 4, 42) Z={a, b} 9 = {4} i.e, go is the initial state and 4, is the final state. Examp'e 10 Construct a DFA that accepts the set of natural numbers x which are divisible by 3. Solution. Let M={Q 5, 4,5,F} be a DFA with Q=(40 t+ 42) (0, 1, 2,...9} F=(qo) ie,, here qy is initial state and final state also. ODUCTION TO AUTOMATA THEORY 35, Example 11_ Example 2 Here DFA is given in the figure for the language L. Find the DFA for 2. Solution. The language for DEA is L={a"b: n20} Now, let us assume that DFA for I? is M={Q,5, 8,4, F) The transition diagram for [? is defined as Here, 4g is the initial state qq is the final state. Example_12 Find a DEA that accepts all the strings on (0,1) except those containing the substring OOL. Solution. If the string starts with 001, then it must be rejected. This implies that there must be a path labelled 001 from the initial state to a non-final state. This state must be a trap state. All other states are accepting states. This gives us the basic structure of the solution, but we still must add provisions for the substring 001 occurring in the middle of the input. So, the final DFA is Example 13 Design a DEA which accepts set of strings such that every string containing 00 as a substring but not 000 as substring. Solution. Here qy is the initial state 42) 93 and q, are final states Qs is dead state. X Nee” 36 THEORY OF AUTOMATA & FORMAL LANGUAGES Example 14 Construct DFA that accepts strings on (0, 1} (a) The set of all strings with three consecutive 0's. / (b) The set of all strings beginning with a 1 which interpreted as the binary representation of an integer is congruent to zero modulo 5. Solution. (a) ® 4 is dead state. Here we have to design a automation which accepts those binary strings when we interpreted them in integer then those integers are divisible For example, 101, 100011 etc’ Other solution : The trick isto label the states with the value (mod 5) of the partial bit string and find the rule for taking care'of the next bit by @n+1)mod5=(2nmod5 +1)mod5 by 5 ie,, remainder is zero. Example 15 Given ; D={a, b} construct a DFA which recognizes the language L={a™b" rm, n>0} Solution. The given language L has all strings which begin with one or more a's followed by one or more b's. qq is dead state. —_— INTRODUCTION TO AUTOMATA THEORY 37 example 16 _ Design the DFA that accepts: (?) L={(aby" Solution, pts : (i) L=((aby": n20) (ii) Ly ={(aby": n21) ) wo qq is the dead state. gy is the dead state. Example 17 Determine the automata with set of strings having aabb as a substring. Solution. Example 18 Construct a DEA that accepts the language ofall legal infix arithmetic expressions over the alphabet E={a, by +, -,*, /}assuming normal precedence rules apply. Solution. For valid infix expressions, we have the following cases : 1. First input symbols cannot be any of the operators +, -, * oF /. 2. For each operator in the expression, there must be two operands one preceding and one followed to it. 3, ‘There cannot be simultaneous occurrence of more than two operands or two operators. ‘Some invalid expressions are : +a-b, +ab, ab—+, a*—b/ ‘The transition diagram of the required DFA is (2) ab E-{a, b} ab Draw DFA for the following language L over {0, 1}: L=(All strings of length at most 5}. tui PTU 2002 ; UPTU B.Tech 2013-14] Solution. Let the DFA be M={Q, 5, 8, qo, F}. The transition diagram is Example 19 Here 4p is the initial state and (qq, 4, 92/937 44 95} are final states. X a 38 Example 20 Draw a DFA that accepts set of all strings THEORY OF AUTOMATA & FORMAL LANGUAGES. _ __ same symbols. id in the last two some [B.Tech UPTU 2009-10] Solution, Let the DFA be M=(Q %, 4 F} The transition diagram is Example at Construct a DFA that accepts the following language : L= {we la, b, c}: w begin and end with different letters}. Solution. The words that are acceptable to DFA can be of three types : 1. Begin with ‘a’ and end with ‘b' or ‘¢’ 2. Begin with ‘b’ and end with ‘a’ or ‘c’ 3. Begin with ‘c’ and end with ‘a’ or ‘Y’ The transition diagram is as follows : Example 22 Draw a DFA that accepts the language : L={a" : n>1} , Solution. Here, L={a" : n21} [UPTU B.Tech. 2009-10] ie, Leontains a”, a*,a°, a8)... ie, aa, ana, aagaaa,... SSE —._'NTRODUCTION To AUTOMATA THEORY 39 105,84, F} ° wn alongside : Here, qy is the initial state and 4 is the final Let the required DFA be M= and the transition diagram is as sho state. Example 23 Design a DFA, M conch hich accepts the language L(M)= (wo e(a,8)"): w does not contain three Solution. __ Here qo,4, and q, are ‘final states’. Therefore any input string not containing three conse- cutive B's will be accepted. If we get three consecutive ¥s then the q, state is reached, which is not final state hence Mwill remain in this state irrespective of any other symbol in the rest of the string. This state is also called “dead state” or Mis said to be “trapped” at q5. Example 24 Design a DFA, the language recognized by the automaton being L={a"b:n>0}. Solution. For the given language L={a"b : n 0} the strings could be b, ab,a*b, a°b,... Thus the DFA accepts all strings consisting of an arbitrary number of d's followed by a single b. 6B b © ab & Construct a DFA accepting all strings w over {0, 1} such that the number of 1's in w is 3 mod 4. Solution. Let Mbe the required DFA. Since the language accepted by Mdoes not involve 0, so we can assume that Mdoes not change state input 0. If 1 appears in w (4k +3)times, Mcan come back to the initial state, after reading 4 1’s and to a final state after reading 3 1's. ‘Thus the DFA is shown in the Figure. Example 25, 40 THEORY OF AUTOMATA & FORMAL LANGUAGES Example 26 Obtain the DFA that acceptsirecognizes the language L(M)=(w:w ¢ (a,b,c}” and w contains the pattern abad. Solution. Since the given pattern ‘abac’ has length 4, there are 4 states required in addition to one initial state 4g Example 27 Obtain the DFA which accepts/recognizes the set of all strings on L=({a,b}.starting with the prefix ‘a’. TUPTU 2005] Solution. Here the length of prefix ‘al is 2. So only two states (q and q,) are recognized ‘a in addition to the initial state. The DFA is as shown in adjoining figure. - In this DFA, q, state is a trap state. [It is not necessary always to have a dead or trap state]. Example 28 Determine the DFA with the - (a) set of integers ~ (b) set of signed integers (0) set of strings beginning with ‘a’ and ending with Y. (d)_set of strings having ‘aba’ as a subword. [UPTU MCA 2013-14) Solution. (2) Set of integers : L=(0,12,...,9} _ _ INTRODUCTION TO AUTOMATA THEORY 41 (0) Set of strings beginning with ‘¢ and ending with‘ : a 4q is the dead state. “ a,b (@ Set of strings having ‘abd as a subword : Example 29 Let = (0,1). Give DFA’s accepting the following strings : (a) The set of all strings beginning with 101 (b) The set of all strings containing 1101 as substring. (6) The set of all strings that begin with OL and end with LL Solution. (a) ® © 4s is the dead state. “ Example 30 Draw DFA for each of the languages. None of your DFAs may contain more than 4 states : (2) All strings which do not contain the substring ba. (6) All strings that contain an even number of b's. (c) All strings that do not end with aa. Solution. (a) © Example 31 Construct a DFA accepting all strings over (0, 1}. (@) having odd number of 0's. TUPTU MCA, 2013-14] (0) having even number of 0's and even number of 1’s. (UPTU B.Tech, 2013-14 ; MDU, BE 2005] (©) even number of 0's. Solution. (a) Odd number of 0's. % is the final state, 4p is the final state. INTRODUCTION To AUTOMATA THEORY 43 q, is the dead state and 4, is the final state. le 32 grample 32_ Construct a DFA accepting all strings over {a,b} ending in ‘al’. Solution. Example 33 =(b™ab": mn>O}. th exactly one‘d which is a DFA that shall recognize the language L- Solution. The given language L=(6"a b*: mn>O0l has all words wit eee word ie, there is one or more U8 after or before single ‘d. {a,b}, construct Given | neither the first nor last letter qq is the dead state and q, is the final state. NON-DETERMINISTIC FINITE AUTOMATA (NFA) We shall now study a more convenient device to design a DFA known as non-deterministic finite automaton. The concept of non determinism plays a central role in both the theory of languages and computation. Non determinism means a choice of moves for an automaton. Rather 27 yo we | Example 35 Design a NFA that accepts all inputs witha triple letter Iike 00, 111 Solution. Example 36 Construct an NEA that recognizes the language : (@) Words that start with ab and end in ba (0) Words that end in ab. [UPTU MCA 2013-14] Solution. (a) ® Example 37, Determine an NFA accepting all strir i 7 substring 00. epting, ings over {0, 1} which end in 1 but does not contain the Solution. In this NEA, strin; not contain 00, Mould end in a1 and it should - _ INTRODUCTION TO AUTOMATA THEORY 47 example 38 Sketch the NFA state diagram for M= (4914142793), 10,11, 8 qo, (qg}) with the state table as State . a 0 1 > % 40 Ie 4 4s A % cy cy % Solution. Here 8(q9,0)={99,4;} 8(4o1)= (40142) 8(q3,0)= {43} (4,0) = {9s} 8(q3,1) = {4s} 8(qa/1)= (Gah So, the NFA is shown in the adjoining figure. Example 39 Find an NFA with four states for L={a": n20) U(b"a: n21} Solution. In this language two cases arise : @ a®:n20 (i) ba: ne] The NFA is shown in the adjoining figure. Example 40 Design an NFA with no more than 5 states for the set : L={abab": n20} U faba": n20}. Solution. Here NFA accepts all strings of the type abab" and aba", where n20. 48__THEORY OF AUTOMATA & FORMAL LANGUAGES Example 41 Design an NFA with three states that accepts the language {ab, abc)” . ~ Solution. It accepts “ab’ or “abc” in the first step and then this is looped with initial state so. can be accepted. that any combination of “ab” and “abd” Hence the NFA is as follows : Example 42 Determine an NEA that accep Solution. ts the language L=(bb* (a+b). Example 43 Give the NDFA to accept the following language : “The set of strings over alphabet (0,1, 2, 3,...9) Such that the final digit has appeared before”. Solution. The idea is to use a state 4g; for i=0, 1, 2,..9 to represent the fact that we have seen an input i and guessed that this is the repeated digit at the end. Here, q, is the final state and q, isthe initial state. INTRODUCTION TO AUTOMATA THEORY 49 Example 44 Find the language accepted by the NFA whose state diagram is given below. Solution, There are two final states q, and q,. The substring ending at q, is aband substrings ending at q, are ‘abd and ‘aa. Thus the language accepted by this NFA is : (ab+aab+aba)". Example 45 Construct the NFA for the following language : L= (x €(a, b}’ : x contains any number of a's followed by at least one b J. Solution. This transition diagram is itself a DFA. NFA and DFA Capabilities NFA and DFA are equivalent to each other. In other words, for every NFA there exists an equivalent DFA accepting the same set of words. Therefore the capabilities of NFA and its equivalent DFA are same. Acceptance by NFA © Astringis accepted by an NFA if there is some sequence of possible moves that will put the machine in a final state at the end of string. © A string is rejected or not accepted only if there is no possible sequence of moves by which a final state can be reached. Example 46 Draw NFA with four states for all strings over {0, 1} in which third symbol from right end is ‘0’. TUPTU 2002] Solution. Let the NFA be M=(Q, 2, 8, go, F} SS 50 THEORY OF AUTOMATA & FORMAL LANGUAGES ‘Transition diagram is Here, qq is the initial state 4q is the final state ; 2 = {0, 1} and 8 function is defined as 0 1 > % {ora} % h h b % % % 43, 2 = 2.9 EQUIVALENCE OF DFA AND NDFA. () A DFA can simulate the behaviour of NFA by increasing the number of states. (i) Any NFA is a more general machine without being more powerful. Theorem 2.1 For any NDFA or NFA, there exists a DFA which simulates the behaviour of NEA ic, if Lis the set of strings accepted by NFA, then there exists a DFA which also accepts L Proof. Let M=(Q,.8,49, F)be an NEA accepting the language L. We construct DFA M' as follows : M'=(Q,L8,q),F') where Q =2° (any state in Q' is denoted by [a9 fo = (40); F’ =set of all subsets of Q containing an element of F. 21Gj\ where 4149 014; €Q) i Let Mis initially at qo. By applying an input symbol ‘¢, M can reach any of the states in (90,2) To describe M, we require all the possible states that Mcan reach after the application of ‘d. So M' has to remember all these possible states at any instant of time. Hence the states of M’ are defined as subset of Q. As 4p is initial state so q, is defined as {qa} If the string ‘w’ is accepted by M then M reaches a final state on processing ‘w. So, a final state in M’ is any subset of Q containing some final state of M. Now, we define 8’ of DFA M’ 8 ta 411 4) = 8(4 A) 8(qp,€)V...08(4;,0). A 52 THEORY OF AUTOMATA & FORMAL LANGUAGES EXILE Algorithm Conversion from NFA to equivalent DFA 1. Seek all the transitions from starting state q, for every symbol in E. If we get a set of states for same input then consider that set as new single state. 2. In step (1), if we are getting a new state then check all transitions of £ for this new state only. Suppose new state as [q,, 4,] then for some input alphabet ‘a’ compute 6(q,, a) U 8(q,, a). Let the result be [4;, qn] create a vertex [41 4m] a8 @ new state if it does not already exist. Add an edge from [41, 42] to [4 4m] and label it with ‘a’, 3. Repeat set (2) till we are getting any new state. 4. All those states which consist at least one final state of given NFA as member state will be considered as final state. Example 47 Convert the following NEA into DFA : Solution, Initially, we have q, as the starting state so create start state as [qo] Now (40), 0)= {Aor 44) We create new state as Again, we find 6((q5], )=(@) ie, we create new state as o Weal) (s) 1 @) Again for the vertex [q, 4, ]and input 0, we have B40 4) 0)= 8 (4, 0)8(q,,0) = Go HILO = (0 4) ie, state [qo 4] [since there is already a vertex labelled [49, a) _INTRODUGTION To AUTOMATA THEORY 53 ai 8(l40. 4) 1) = 840, 1)8(q4,1) = (auto, a) = lor ah Now for vertex [4] (G1, 0)=S (4) Y= (Gor a4) ie, state [9 %] Finally, the vertex {qg, 4, ]and [q, ] contains the final state q, of NFA so these are final states in equivalent DFA. Thus, the equivalent DFA is Example 48 Convert the following NFA to its equivalent DFA : Solution. Initially, we have qq as the starting state, so create start state as [49] Now (G01 0)= fos i} and 8(go1 1)= (ae) Since these do not already exis, 0, crate twornew Gea) states as shown in the adjoining diagram ‘Again, 8({go- 44], 0)= 8(4p0) V8(Q,- 0) @ , = {or WIUM0) = {qo a) The state [99,4] i already there, so we draw self loop. 54 THEORY.OF AUTOMATA & FORMAL LANGUAGES Now 8Udor 4) 1)= 8g, 1) V8(G * hula} = (a ah Create new state as [4,, 47] That is now Now, for vertex [7,] we have 5([42], 0)=B BG21 D= {or 4} ey state [40/44] For vertex [q,, qp] we have . (4, 921, 0)=5 (4, 0) 48(42,0) jp} UD = {ao} =[qo] state (already in graph) and 8, G2) D=8 (G, UG(4a/1) = {JU (49, I= M0. 4) = [or 4] state (already in graph) Thus, the final transition graph is In NFA, 4 is the only final state, so all subsets containing q, as final state i., state[, Jand [a 42] are final states in DFA. Example 49 Determine a DFA from the given NFA, whose state table diagram is given below : StatelX 4 b 4% (Gor) tad ‘4 {ort INTRODUCTION TO AUTOMATA THEORY 55 Solution. Let M' be the required DFA, 0 The states Q are subsets of (ora) ie, (DY [40] (41) (4o-m))- (i) 9 =I901, and Gi) F'= (la) Ua.4) Note that [ ] denotes a single state. Now 8" is defined for the DFA M' as Stately a b a ® @ (aol ora} fal tal a Iaeal (aye) (4-4) [aa It is to be noted that 8 (400% 14) = [40/4] because 5 (C4004 1a) = B40, 2) 08(-2) = (0.4) US = (40m) Similarly, (49,4, ],b) = 8(q),b) U8(q,,b) =n) Y on} = (0-H) So, 8 40-410) =[40-4} When NFA has 7 states, the corresponding FA has 2" states. However, we need not construct 6 for all these 2" states but only for those states that are reachable from {4g}. This is because our interest is only in constructing DFA which is equivalent to given NFA. Example 50 Construct a DFA equivalent to M=((99-91 42-45) (2,01, 8 qq, (95]) where dis defined as StatelX a b 7% Gor 4%. a hh a h % % %3 te 56_ THEORY OF AUTOMATA & FORMAL LANGUAGES Solution. Let the DFA M, is equivalent to given NFA M M, is given by M, =@°, (@,b},8[0] F') where F’ consists of [43 Mol 401 45 44 43 bl 4e 4a 14041 +43 bL40> 4243 LAG 4293] ANd [49-42-43] and 8 is defined by (ao ao) (401 (aoa) [44a] (o>) [4401 [ord 42/43] Maor44-95] [40-445] (ort 42] (oa) [o-t4er4s)_ | Uordre42rAa)_ | (ort Far Qs] The DFA is shown in the Figure below : Example 51 Convert the following NFA to an equivalent DFA [UPTU MCA 2013-14) a\) (J +@) "+ @)+-© Solution. The given NFA has 4 initial state and q, as final state. The state table of given NFA as n (a) ¢ INTRODUCTION TO AUTOMATA THEORY 57 Now, we construct state table of DFA through subset construction. Statel 0 1 (40) (4) (40-4) (oa) (or) (oa) (orm aol Mot-45) 40044045) [aorta (ora) State containing 45 i2., [49,4143] will be final state. The DFA is shown in figure. Example 52 Given the NFA as shown in the Figure, determine the equivalent DFA. Solution. The given NFA has q, and q, as final states. So it accepts string ending in 00 or 11. First we construct state table of NFA. Statel 0 1 7% (or) {qo-45) 4 (a2) e 2 @ % 2 tau) % 2 2 — 58 THEORY OF AUTOMATA & FORMAL LANGUAGES Now, we construct state table of DFA through subset construction. [sees [a (ol load [4-4] [aoa] [0-4 [40-45] loa (oral [or4s-44] 04-4] Gort 4a) [40-45] [aor 4a-4) [oa] Any state containing q, or q, will be final state. The DFA is shown in the Figure below : Example 53 Determine a NFA accepting {abba and use it to find a DFA accepting it Solution. The NFA accepting (ab,ba} is as follows : The state table of NFA is [ean ee oe ; ; 4 @ a aA 2 @ Gs 42 @ Now, Stately, a b (40) (a) [a] (al @ lal (n) 2 ® (31 [al o Example 54 Consider the following NFA: M=((p, q, r,s), {a, bl, 8, p, tl INTRODUCTION TO AUTOMATA THEORY 59 the state table corresponding to the DFA is derived by using subset construction. Or® @® © [UPTU B.Tech 2013-14 ; UPTU B.Tech 2005] (a sh} where 5is given as : State! & a b >P {qs} {a q {rl (ar r {s} (an £ {p} Construct an equivalent DEA. Solution. The transition diagram for the given NFA may be as follows : Now, we construct state table of DFA through subset construction Statel 0 1 ol as) fl fl Li) (a7 sl fl pal fl i lan rl ts an Ipegrl (ans) lan &) lal bys] fs pan 1,01 fs] [rar \ 60 THEORY OF AUTOMATA & FORMAL LANGUAGES Now, again label the states of DFA as (p> A (d->B [9] >c iD Inve [panoF i] >G [Ins] 9H lans]or and the transition table is now INTRODUCTION TO AUTOMATA THEORY 64 Example 55. Construct a DFA equivalent to the following NFA, [UPTU B.Tech 20031 (sl (401 (ad (he 40) [al [or Ge Aa) wl fad fal Uo: 4 2] (aa 43] [or eae 4) 2431 (24a) (aa 4a) Wort 4/44 Uae ty 441 [or tr tar Mal Yaa) (a4) Una 4a) Ware 901 44) Ua tal Ua dal ~ 62 THEORY OF AUTOMATA & FORMAL LANGUAGES Now, again label the states of DFA : [ql A [41> B (ts 1 >C [q]>D (or 4 BIE (42, QJ>F (90. thy dar 41> G (a2, g]>H [42+ 95-4411 The transition table after labelling again the state is INTRODUCTION TO AUTOMATA THEORY 63 Example 56 Construct DEA equivalent to the NEA p, q r, sh 0 1) 8 p, (ol) where 8is given by q q r ? if s - s a a Solution. The oA (pal a @ fm wl fh io) - Is} i io) (pal ean a4 lan fs] i eal [ears] aA brs} io) (3 Ip.qir,sl. ears ars Gar,sh fs] ts} Now, again label the states of DFA as. [p> A (JB noc []>D [pn ql>E [anoF [pn 4N>G [ns] oH [pa nslor ans _— 64 THEORY OF AUTOMATA & FORMAL LANGUAGES The transition table after labelling again, the state is ~ Rome FO we > Example 57, Construct NFA for [s] and derive DFA through subset construction algorithm. (UPTU B.Tech 2007) Solution. NFA for [f] we get and the transition table is This is also DFA. Construction of NFA without e-Moves from NFA with e-Moves For every NFA with e-moves there exists an equivalent NEA without e-moves accepting the same language. If NFA with e-moves is given by M, (QE 8 a9, F) where 8: Qx(ZUue)>22. It can be converted to NFA without &moves Mz =(Q © 8140; F’) where 8’: Qx 522. Q Zand initial state q, are same but set of final states F and F' might not be equal. i lita ho ansteueg iui NFA a steps : H (i) xg a= eclosure (65, °), a)) where 8 (4, )= eclosure () Example 58 Convert NFA with e-moves in the Figure to equivalent NFA without & moves. INTRODUCTION TO AUTOMATA THEORY Solution. Here eclosure (49)={99, 41, 42) e-closure (4 (t+ 2) e-closure (q,)= (g.) As we see that q, is in eclosure (q)) and e-closure (q, ) that means q, is at distance zero from qo and qy. ‘Thus, the set of final states of resultant equivalent NFA without emoves is P= (os 4) 1) Now, we shall find out the transition function 3° 8'(Gq, 0)= e-closure (5(6 (4p, €), 0)) e-closure (6(e-closure (4g), 0)) = eclosure (5((99, 4, 92}, 0) = e-closure (8( 4, 0)U8(q,, 0) U8(4a, 0)) eclosure ({q9}U @ UB) = eclosure (49) = lor he a) Now 8(gp, 1)=e-closure (6(8 (4p, 8), D) = eclesure (6(¢-closure(qg), 1)) = eclosure (5({q9, 4, 92), 1) = eclosure (5( 49, 1)8(q,, 1) U8 (42, 1)) = s-closure ( U q, U2) closure (4,)= (qh, 42} In, 92h 5D Now &'(qo,2)=eclosure (8(6 (4p, 8),2)) = e-closure (8(e-closure(qy), 2)) = eclosure (5((49, 41» 42), 2)) = e-closure (8( 4g, 2) V8(q, 2) V8 (42,2) =eclosure @ US Vv q) = e-closure (4) = (42h 8 (gos 2)= (4a) Similarly, we can obtain 8'(q, 0)=e-closure (6 (a, 8), 0) =@ 68 THEORY OF AUTOMATA & FORMAL LANGUAGES _ 8 D= (e492) 8g, 2)= (aa) 8G, =D 8(q, =O and 8 (qz,2)=(q2) Now we can construct the transition table for NFA without moves as ° Input State : 0 1 2 > % (400 de 2b | A 4a) (a) n @ (4 92) (a) L & @ @ ta) The resultant NFA without e-moves can be represented by transition graph as Construction of DFA with e-Moves ‘There are two approaches for constructing DFA from given NFA with emoves. First Method This consists of be Second Method inthe poh rl dey ela ll aa os bling sna an when required to the diagram. till we come to the stage:when there exists no state without. transitions specified, Example 59 Consider the following NFA with e-moves. 3B. — INTRODUCTION TO AUTOMATA THEORY 69 Solution. To construct the DFA, equivalent to this NFA, we define inital state which will be e-closure of initial state of NFA with e-moves i. ica eelosure (qq)= (4. 41, 42) ie, new initial state for DFA as (49, q,, 4] and the rest of states are eclosure (4,)={9,, 42) ie. [qy, qo] state (q2) ie, [q,] state The final states of DFA are those new states which contain final state of NFA with moves as member. $0 [4o, 91, 4) 141, 42] and [q, all are final states. Now 8'((49, 4, 92], 0) =e-closure (8(q9, 0) 15(q,, 0) V8 (4p, 0)) = e-closure({qg} UBU q,) = e-closure(qg, 42) = (40-911 42) ie [90s 44 Ie state 840. 91» 92), 1)= e-closure (8(q9, 1) V8(q,, 1) V8 (qa, 1) =e-closure(Su {q,)U 2) =e-closure(q,) = (us M2) ie, 4 state. Similarly, 8, 921, 0)=[421 8 Bh Dal 2] 821 )=[4] Bgl Y=S Finally, we have DFA as eclosure (q, Example 60 Construct DFA equivalent to the following NFA. Solution. To construct the DFA e-closure (4p) = {4o} ie, [qo] state e-closure (q,)=(%1, 42) ie, (41, 92] state e-closure (q2)=(q2) ie, [q)] state We define e-closure (qg) as initial state ie., [q)] state. 70 THEORY OF AUTOMATA & FORMAL LANGUAGES: — Now 8 ((qp], 0)= e-closure (5(190], 0)) =e-closure (9, ) =(a, ]state and 8 (Uye], 1)= e-closure (6[40], 1) =e-closure (2) D Now 8 (lq, 92], 0)=e-closure (5(19, 421 0)) = eclosure (8(4y 0) UV (4, 0)) closure (q, U @) =eclosure (q,) [a 91 Now 8 ({42], )=e-closure (5(14,],0)) = e-closure (2) @ and 8 ((42), = eclosure (6{991 1) e-closure (2) 8p], 2)= e-closure (5[99}, 2) =e-closure (2) 84a, 411 2)=eelosure (ty, 42) | =eclosure (6(g9, 2) U 8(q,, 2)) \ =eclosure US) \ =a 8 ((qg], 2)= eclosure (5((4,1, 2)) ( seclosure (q5)=(4o, 4, 43) = (qo, %, 93} aS a new state Now, 8'(L49, 41, 43], 1)= closure (8([49, 41, 43], 1)) = eclosure (5(q9, 1) U 8(q,, 1) U8(q5, 1)) =e-closure (BU q, UZ) = e-closure (q,) = [92] state 8 (40. thr 451, 2)= eclosure (6(14q, 4, asl 2) = e-closure (8(4, 2) U (4, 2) U8(q5, 2)) =e-dlosure(ZUSUZ) | = e-closure (Z)=@ \ INTRODUCTION TO AUTOMATA THEORY 1 8 (lor 41+ 95], 0)= e-closure (8649 44» 9310) = closure (8(4), 0) U 8(q,, 0) U8(q5, 0)) =eclosure (4,)= (49, 44} =[49, 4] state The final state of DFA is [49, 4,, 43] which contains final state q, as a member. Example 61 Construct NFA for (a/b)* and derive DFA through subset construction algorithm. Solution. Let NFA be M=(Q, & 8, qo, F)and transition diagram is NFA with emoves Now e-closure (4g) = {90 41 42) ie, [or 4 92 ]is a starting state e-closure (q,) = (4,} eclosure (9) = {92} e-closure (95)= (43» 4s- 46r Jar» 42) e-closure (44)= (441 951 967 40 i G2} CC el e-closure (4g) = {9g} Now = 8'((4or 1 42), a) =e-closure (5((49. 1» 421, 4)) = closure (8(q9, 4) U 8(q,, 4) U8(q2, @)) = e-closure (OU 4, U2) = eclosure (q,) 37 957 Ir For Ie Ga) = [957 951 Gor For I» 4a) state. 72 THEORY OF AUTOMATA & FORMAL LANGUAGES a Let S=L4o, 4, go] and A=[q5, 45,46. Gor hy dal then 81S, a) =A aan 8S, b)=eclosure (6((40, 41 42) 8) = eclosure (5(qp, b) U (4, b) Y8(42- )) =eclosure (BUS U 4) =eclosure (q,) = (ar A50 6r For Snr M2) = [441 957 Ir Ao th» Ge] state. Let B=[4er 45/967 40s Ge Gy] ie, (5, b)=B Now 8(A, @)=eclosure (8((45, 457 467 Yor tr da) ®) = eclosure (6(45, a) U 5(g5, 2) U5(4g, @) V8(Go, @) V(H, 4) VE(Ga, 2) = eclosure WU BUBB gq, VO) =e-closure (45) = {30 951 96» Gor 1» Go) = Astate ie, B(A, aaa and 8(A, b)=eclosure (8((43, 45, 967 90 41 42), ©) = eclosure (6(4g, 4) U 5(qs, b) V(qg, b) V8(qg, b) U8(Q,,, B) V8(qz, b)) =edlosure G@USGIGBBHU4,) = e-closure (q,) = Mar sr 67 For G+ a} = [as M+ 61 or th» 4a] state. Let Ba[qu, 951 467 4or 4» Qa] state ie, 8(A, b)=B Now — 8(B, a)=e-closure (6((44, 95» 46+ Yor 1» 92) @)) = eclosure (6(q4, 4) V 5(g5, 2) U8(qg, @) U8(qo, 2) U8(q,, a) 8G, 2) = edlosure WU SUSUGBUuq, UB) =e-closure (q,) = Astate ie, 8(B a=A and 8(B, b)=e-closure (8(I4,, 45, 96/ 4or I» 421 b)) = eclosure (5(44, 6) V (45, B) U8(ae, B) U8(q9, B) U8(q,, 6) U8(4p, b)) =eclosure @U BLBUGUBU4q,) =e-closure (q,) = Bstate ie, 3(B, = B eo a and the transition diagram is shown in the figure below. and INTRODUCTION TO AUTOMATA THEORY 73 ‘The transition table for the DPA is a +s A > > ale wow ole Example 62 Construct DFA equivalent to following NFA. Solution. e-closure (qo) = {49} eclosure (q,)= {99,4} e-closure (7))= (42) eclosure (3)= (45 417 40) = (o- h 43) Thus, the initial state in DFA is [qq }. Now, find 8'({qo], 0) = eclosure (8([4o], 0)) =e-closure (q)={4or 41} io 41 state -closure (8{401, 1) =eclosure 2) =@ Now 8 (Uggs 4], 0)=#closure (5(L4o, 411, 0)) =e-closure (8(4), 0) U 8(9,,0)) 51D 74 THEORY OF AUTOMATA & FORMAL LANGUAGES =e-closure (q, U) = e-closure (q)= {997 1) =[90, 41] which already exists. 8 (Mor 41], 1)=eclosure (8((49, 4], 0) e-closure (8(q9, 1) U 8(q,, 1)) s-closure (BU q,)=e-closure (42) = {92} = [92] state and 8 (Udy, 421, 1)=e-closure (6((4,, 42], 1) = e-closure (6(q;, 1) U 6(q/ 1)) Now, for [q, ]state 8 ([q2], 0) = e-closure (8[4,], 0) = e-closure (2) 8 Ugg], 1) =eclosure (8{4,], 1) closure (7p) =[40]- Thus, the transition table for 3! is as fc and final DFA is [Go] 2.10__ MINIMIZATION OF FINITE AUTOMATA. Minimization of FA refers to detecting those states whose presence or absence does not affect the language accepted by automata. Such states are called unreachable states. Unreachable states are those states which are not reachable from the initial state on any possible input sequence. For example (Fig, 2.10) Aig. 2.10 State % 'S unreachable state, INTRODUCTION TO AUTOMATA THEORY 75 Method of finding unreachable states | | | Let M=(Q ¥ 6 q, (2 Jo, F) be a FA. We can find a set of unreachable states as 1, Let S be a set of states initially q) 441 Initially, we partition Q into two groups. % [eat 4% 1 2 : Further division of group 1 is not possible so apply the method in group 2. 864g, 2) = 4 870. = a5 (gy, @) = 93 5 =a G2, =m dn, aay (qs, 0) = 4 8s =a Now, we get partition of group 2 for input ‘¢’ is not possible because all members go to the states which are in same group ie, group 2. But for input ‘b” we. get state q, which is distinguishable from rest of the states because all others go to group 1 but q, is in group 2. Hence, we divide group 2 into two groups. 4% he % fo 1 2 3 ince qo on input ‘b’ goes to group 2) Now apply the method for group 2, 3a, = 42 542, =H 34s, = 4 Partition of group 2for input ‘isnot possible since all the members goto the states which are in same group. INTRODUCTION TO AUTOMATA THEORY 77 Now for input ‘, we get (4), B)= 4, 5(qa, b)= 44 — 3(4, B)= 94 No partition is possible so again we get 7 4% he % ey dys 42 and gy are equivalent states. We can merge these states ie., new state is ] instead of (4,1, [42] and [9,] states. es Urs 927%: Now State/ © a b > lol (ay de 451 Ue 2 43] Ua do 45) Ua Gar 951 (as) Gd (al (ad Minimization of Finite Automata - Process Now, we construct an automaton with the minimum number of states equivalent to a given. automaton. ‘Two states q, and q, are equivalent if both are final states or both of them are non-final states for all input strings x €Z*. But, it is difficult to construct 8(q,,x) and 8(q,,x) for all xe Z". So we will determine K-equivalent of two states. ‘Two states q, and q, are k-equivalent (k 2 O)if both 8(q, .x)and 3(q_ ,x)are final states or both non-final states for all strings x of length k or less i.e.,|x|