Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
9 views
TOC 2nd chapter
theory of computation
Uploaded by
kkiru8225
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save TOC 2nd chapter For Later
Download
Save
Save TOC 2nd chapter For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
9 views
TOC 2nd chapter
theory of computation
Uploaded by
kkiru8225
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save TOC 2nd chapter For Later
Carousel Previous
Carousel Next
Save
Save TOC 2nd chapter For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 64
Search
Fullscreen
@ Finite Automata and 1 TN VAs Regular expressions Ee language accepted by DEA or NFA and c-NPA is called regular language. A regular re can be described using repular expressions consisting of the symbols such as alphabets in &, the operators such as *.’, ++" and“, ‘The three operators used to obtain a regular expression are: » (4 operator) union operator (least precedence) © G operator) concatenation operator (next least precedence) x ¢ (* operator) closure operator (highest precedence) __> Note: The symbols *(* and ‘)’ can be used in regular expressions. The order of evaluation of the regular expression is determined by the parenthesis and the priority associated with other operators. Now, let us see ;AViiat is st repular expression?” A regular expression can be formally defined as follows, _Delinition: A regular expression is recursively defined as follows. - isa regular expression denoting an empty language. €-(epsilon) is a regular expression indicates the language é EEO: empty string. g anit . ais a regular expression which indicates the langage containing only (a} » If Ris a regular expression denoti ¢ language Lp and S is a regular expression denoting the language Ls, then 2 a R+ is a regular expression corresponding to the language L; c, R* is a regular expression corresponding to the language Lp’. 5. The expressions obtained by applying any of the rules froj regular expressions, J The following table shows some examples of regular expression: Corresponding to these regular expressions, maa [ae String consisting of any number of a's (or string ‘eons ecg Mm TS rl Pee String consisting of at least one a (or string co a's)ions 2.22 O Finite Automata and Regular expressio i b String consisting of cither one a or one ay Set of strings of a's and b’s of any length including the NULL sting Set of strings of a's and b's ending with the string abb [see] Set of strings of a's and b’s starting with the string ab. (a+b)*aa(atb)* | Ser of strings of a's and b's having a sub string aa, Set of string consisting of any number of a’s(may be empty string aks followed by any number of b's(may include empty string) followeq by
0 adn } 3 Autom 40) Obtain a regular expression to accept strings of a's and b's ending with ‘by’ and tas . substring aa of a’s and b's ending with “b’ and has no substring aa” can be e any combinations of either b or ab Without ¢”, oat So, RE is (b+ab) (beaby* Be Six Note: The language corresponding to the regular expression can be written as LR) = { (b+ ab)" Ind 1} The statement restated as “ 11) Obtain a regular expression to accept Strings of 0’s and 1's having no two Consecutive zeros, The first observation from the Statement is that whenever a 0 occurs it should be followed by 1. But, there is no Testriction on the number of 1's. So, itis a string consisting of any combinations of 1’s and 01’s, So, the partial regular expression for this can be of the form (1+01)* No doubt that the above expression is correct. But, suppose the string ends with a0. What, to do? For this, the string obtained from above regular expression may end with 0 oumiay end with € which can be Tepresented by the regular expression: F +e) is (1 +01) O+8) So, . . Y ing with ‘a’ 12) Obtain a regular expression to accept string of a's and b’s starting with ‘b’, q Strings of a’s and b’s of arbitrary length can be written as (a+b)*Asimple approach 2.27 B Finite Automata and Formal languages — he string starting with ‘a and end with "b we have to precede the above ut, 10 Bet I jlowing the above RE with b. F 5 with aan So, R.Bis.a(a+b)*b D 3) obtain areguiar expression to accept string of a’s and b's whose second symbol! from ‘e rightend isa. «fist symbol from the right end ean be a or b which can be repres: ‘ (a+b) ented by the R.E ¢ second symbol from the right end should be a which can be represented by the a e third symbol from the right can start with any combinations of a’s and b's (a+b) So, R.E is (a+ b)* a (a+b) of ote: On similar lines, strings of a’s and b’s whose third symbol from the right end is can be written as So, R.E is (a + b)* a(atb) (a+b) : c 14) Obtain a regular expression representing string of a's and b's whose tenth symbol from e right end is a. [On similar lines to the previous problem, the RE representing strings of a’s and b’s whose tenth symbol from the right end is a can be written as shown below: # (atb)’ a (a+b) (a+b) (a+b) (a+b) (a+b) (a+b) (a+b) (a . fe Since there are ten (a+b) expressions to the right of a, the above expressionjusing short ‘hand notation can be written as shown below: So, RE = (a +b)* a(atb)® Note: It is clear from this expression that all strings must be of leng we need to track the last 10 characters.28 G Finite Automata and Regular expressions — 2a inite Automata and Regular ¢3 > ) Obtain a regular expression to accept strings of a’s and b's ¢ 15) Obtain « a Such that thicg symbol, iw right is and fourth symbol from the rightis 6 m the righ a We are interested only in the third and fourth symbol so end is a and fourth symbol from the right end is 6 given by that third 5 and the regular ba(a + b) (a+b) 'Ymbol from th f ti expression for this ; s But, this substring can be preceded b: the regular expression 18) Obtain a reguiar ex; and ending Pression to ace Is with tun i vith the same letter where 5 = (a, b} orien eters bu bagnng Since, the string should start can be preceded and followed and end with the same letter, by a as shown below: the above regular expressio RE 1 =a(atb)'a °F preceded by and followed by b as shown below: RE2=b(a+b)"b So, the final regular ex; Pression with two or more letters but begin: with the same letter wh ere Y = {a, b} can be written as: 47) Obtain a regular expression to accept strings of a's and b's Or multiples of 3 or both, ‘The regular expression whose length is even can be obtained usiBG Finite Automata and Formal languages — A simple approach 2.29 ((a+b) (a+b) )* and the regular expression whose length is multiples of 3 can be obtained using ((a+b) (a+b) (a+b) )* gular expression whose length is either even or multiples of 3 or both is ‘Thus, the regula 7 vier - ‘aking various combinations of strings obtained using the above regular obtained by t expressions. So, RE = ( (a +b) (a +b) )* + ((a +b) (a +b) (a+b) )* _ 4g) Obtain a regular expression to accept strings of a's and b's such that every block of four consecutive symbols contains at least two a's. It is required to have a block of 4 symbols with at least two a’s which can be represented by the RE: _ aa(a#d)(@+b) or a(atb)a(at+b) or a(atb)(atb)a or (atb)aa(a+b) or (atb)a(atb)a or (a+b)(atb)aa to have star operator * (which indicates zero or more the empty string. So, we have to use the + operator symbols) and can be expressed as shown below: . Solution: It is given that ® nrepresent number of a’s © mrepresent number of b’sns ind Regular expres = a is even. This results in following two atm +n is even. Iris also given th is even) Even number of a’s followed by even numb Case 1: (m+ " eects which is given by the regular expression: 1» number of symbols ev cr Of b's Tesulty in RE = (aa)" (bb)" Case 2: (m+ n is even) Odd number of a's followed by odd number of b's n results in ¥en, number of symbols which is given by the regular expression: RE =a(aa)” b(bb)" The final regular expression is obtained by adding the above ‘wo regular expressions, So, RE = (aa)* (bb)’ + a(aa)” b(bb)* 1, nm 23} (3 marks VTU July 2007) 20) Obtain a regular expression for the language L = {anbm | m 24,n2 Solution: The possible Cases to satisfy the given telations are shown below: Case 1: Since nm > 3,ifm=1 thenn 23. The equiv: alent RE is given by: RE = aaaa* b Case 2: Since nm > 3, if'n= 1 then m>3, The equivalent RE is given by: RE = a bbbb* Case 3: Since nm> 3, if m>2 thenn>2. The equivalent RE is given by: aa* bbb* So, the final regular expression is obtained by adding all the abov So, R.E = aaaa* b + a bbbb* + aaa* bbb* 21) Obtain a regular expression for the language L = {a2"b?m |p > 0,m20} 5 marks (VTU Jan/Feb 2005) a’s and for every m > 0, b® senting even number of a's is © regular expressions. Solution: For every n 3 0, a” results in even numb results in even number of b’s. The regular expression given by: RE = (aa)*B Finite Automata and Formal languages — A simple approach 2.31 ression representing even number of b’s is given by: RE = (bb)* ‘the regula exP! ular expression corresponding to L = {a""b?" | n= 0 and m > 0} is obtained by So, Teel ing the above two regular express concaten So, R. 2 poyodtain a regular expression for strings of a's and b's containing not more than three a’s _golution: Strings of a's and b's containing not more than three a’s results in following casi . » g indicating zero a’s or © onea or two a’s or © three a's Note: At any point of time, number of a’s should never exceed three a’s. The regular expression for all the above strings can be written as: RE: (€ + a) (€ +a) (e +a) Now, we can insert any number of b's represented by b* at various positions in above expression as shown below: be 23) Obtain a regular expression for the language L = {a"b™ : n> 4 ‘ } Solution: The given language consists of n number of a’s folloy Where n > 4 and m < 3, This language can be interp: yy m number of b's languages: catenation of two2.32 B Finite Automata and Regular expressions ‘The first language consists of strings of four 4's followed by any number of a, oa n> 4). This is represented by the regular expression: | 7 RE = aaaa(a)* jo 7 ings of at mos k ay have , he second language consist of strings o! 2 O'S iba te oe b, or iw b’s or three b's but not more than three b's. This can be "epresent 's by the regular expression: ens RE= (+b) (€+b) (e+b).. (2) So, the final regular expression is obtained by concatenating RE shown in yn in (2). aay So, RE = aaaa(a)* (€ +b) (e+ b) (e+ b) 24) Obtain a regular expression for strings of a's and b's whose lengths are Multiples of () ang RE Solution: The strings of a’s and b’s whose length is 3 is given by the following euler expression: RE =(a+b) (a+b) (a+b) The regular expression for strings of a’s and b's whose lengths are multiples of 3 canky obtained by using the * operator. So, R.E= ((a+b) (a+b) (a+ b))* 25) Obtain regular expression for the language L = (w : lw! mod 3 = 0 where w ¢ (2b)) : 5 marks (VTU Jan/Feb 2005) 3 marks VTU July 2006) It is given that the language consists of. strings whose length is multiple of 3 which canbe! written as shown below: % L={ €, aaa, aab, aba, abb, baa, bab, bba, bbb, aaaaaa, aaaaab, etc. } The strings of a's and b's whose length is 3 is given RE: (a +b) (a+b) (a+b) by the following regular ex Note that minimum strin whose length is multipl expression. g has to be € whose length is 0 which is divisible by, les of 3 can be obtained using * operator for the (@+b) (a+b) (a+b))*B Finite Automata and Formal languages ~ A simple a roach 2.33 te: The above regular expression and the regular expression’ obtained in previous Note? problem are same. 26) Obtain @ regular expression for the language L = {w: Na(w) mod 3 = 0 where w (a,b)*} pserve that even though the string is made up of a's and b's we are interested in only eae of a's. The number of a’s in the string should be divisible by 3. So, number of a’s ai be 0, 3, 6 and so on, Note: There is no restriction on the number of b’s. So, any number of b’s denoted by b* can be inserted. ‘The minimum string that correspond to the language is: aS 4 By incorporating any number of b’s denoted by b* in all possible places in the above expression, we have the following regular expression: RE: b’ab‘ab‘ab” To incorporate € in the above regular expression, we can use * operator. xe So, RE= (b’ab“ab‘ab’)* i ti: (27 Obtain a regular expression for the set of all strings that di lonot, end with 01, over {0, 1}* tis given that the string should not end with 01. So, other strings whose length is 2 and that do not end with O1 are 00, 10 and 11, These strings ‘canbe. preceded by any combinations of O's and 1's denoted by (0 + 1)". These strings canlend with 00 or 10 and 1, So, RE= (0+ 1) (00+ 10+11) 4 (8) Obtain a regular expression for L = {vuv : u, Y ¢ {a, b}* ar Since v= 2, the string having length 2.can be represente v¥aa+ab+ba +b.) Aes there is no restriction on string u, the string u can Be Sand is represented by the following regular expression; u=(a+b)*» 2.34 B Finite Automata and Regular expressions So, the final regular expression to accept the languags L= {vuv:u, ve (a,b)* and lvl 2) I gular expressions V, Uand V. is obtained by concatenating the re; So, R.E = (aa + ab + ba + bb) (a+ b)* (aa + ab + ba + bb) } 29) Give regular expressions for the following languages on ¥ = (2, b,c} (a) All strings containing exactly one 2 ; (b) All strings containing no more than three a's vies {e) All strings that contain at Teast one occurrence of each symbol in yy one a) Itis given that strings of a's and b's coiitainn Solution: (All strings containing exactl nd the regular expression to represent one @ 1s given by: exactly one a has to be represented. So, RE=a But, one a can be preceded and followed by any combinations of b's and ¢’s which is represented by the regular expression: : RE=(b+0)* So, RE=(b+c)*a(b+0)* 1 (All strings containing no more than three a's) This indicates that string may consist of no a's or string may have one a or string may have two a's or string may have three a’s which is represented by the regular expression: (e+2) (¢+) (e+a) Since string may consists of any combinations of b’s and c's which is represented by the regular expression: ny +o)" We can insert (b + c)* in various positions of (€ + a) (€ + a) (€ + a) to get the resultant expression: C So, R.E = (b + c)* (+a) (b+0)* (€ +a) (b +c)* (€ +a) b+0)* CAN seri = string that contain at least one occurrence of cach symbol in Y) Since Y = {a, b, c} and i shi : Which satin re consist of at least one occurrence of each symbol, the various strings 2 condition are: 4 abe, 3 4 2cb, bac, bea, cab, cbajnite Automata and Formal languages — an A simple approach 2.35 e regular expression corresponding to the above strings can be written as: abe + acb + bac + beat cab + cba But, we can incorporate any combinations of a’s, b’s and c’s Tepresented by (a +b +.c)* in various positions in the above regular expression: (atb+c)* a (atb4c}* b (atbte)* ¢ (atb4e)* + (atb+<¢)* a (atb+c)* c (atb+c)* b (atb+e)* + (atb+c)*b (atb+o)* a (atbtc)* c (atbtc)* + (atb+c)* b (atb+c)* c (atb+o)* a (atbtc)* + (atb+c)* ¢ (atb+c)* a (atb+c)* b (atb+c)* + (atb+c)* ¢ (atb+c)* b (atb+c)* a (atbtc)* ; ie 30) Obtain a regular expression for L = {w: string ends with ab or ba where w € {a, b}*}, |The regular expression corresponding to the string ending with ab or ba can be written as: RE = ab + ba But, the strings of a’s and b’s denoted by the regular expression (a+b)* ending with ab or, ba can be written as: psa RE = (atb)*(ab+ba), ‘Note: Now, let us sée “What are precedence of tegular expression operators?” In all above regular expressions that we have discussed’so far have the operators +, * and concatenation operator with the following precedence of operators. ¢ The star operator (denoted by *) has the highest precedence * The concatenation operator (also called dotOperator) has the next highest precedence Note: The precedence of all the above oj example, (a+b)a*. In this expression # (a+b) has the highest precedence’ ® Next preference is given for * op * Next preference is given for concaten2.36 Q Finite Automata and Regular expressions ¢ Automata and Regular Expressions 2.6 This section shows the relation between DFA, NFA, €-NFA and Te; gular Presi Ga tam) Shes 7 Now, let us see how to obtain an e-NFA from the Tegular expression and later te the regular expression from a given FA. obtain -1 To Obtain e-NFA from Regular Expression Theorem: Let R be a regular expression, Then there exists a fi 8, 90, F) which accepts L(R), inite automaton M=(Q,3, or Prove that there exists a finite automataon to acce] Pt the language L(R) Corresponding to the regular. expression R (06 marks VTU Dec-06, Jan-07) So Proof: By definition, 6, ¢ and ro resbulat expressions. So, the corresponding machines ‘0 recognize the language for the spective expressions are shown in figure 2.2 below: $ —@) ©) >O+@ st ¥ig2.2 e-NFAs to accept , € and a Py is The schematic representation of a Tegular expression R to accept the language LR) shown in figure 2.3, where q is the start State and f is the final state of mact * LE) Fig 2.3 Schematic representation of FA accepting L(®)Finite Automata and Formal languages — A simple approach 2.37 Ts = eaeitifon of a regular expression itis clear that if Rand S are regular expression, then R+S and R.S and R* are regular expressions which clearly uses three operators ‘+’, set gnd *.". Let us take cach case separately and construct equivalent machine. Lot Mi = (Qi, 21, 81, qi, fi) be a machine which accepts the language L(R,) conesponding t0 the regular expression Ry, Let Mz = (Qs, Zo, 82, qo, fz) be a machine ‘shich accepts the language L(R,) corresponding to the regular expression Ro. Then the various machines corresponding to the regular expressions Ry + Ro, Ri . Rz and R* are shown below: ace Case 1: = Ri + Ro. We can construct an NFA which atcepts either L(R,)'or L(R:) which can be represented as L(R; + Ro) as shown in figure'2.4, LR») LR) Fig. 2.4To accept the language L(R1 + R2) i Itis clear from figure 2.4 that the machine can either accept L(Ri) or L(Ra). Here, qo is ihe start state of the combined machine and qris the final state of combined machine M. Case 2:R = Ry « Rp. We can construct an NFA which'accepts L(Rj) followed by L(Rz) which can be represented as L(R: . Re) as shown in figure 2.5. LR) LR) GD) @ 8) Fig, 2.5To accept the language L(R1 . R2) Itis clear from figure 2.5 that the machine after accepting L(Ri) moves from state qi to fi. Since there is a ¢-transition, without any input there will be a transition from state f; to State qo. In state qx, upon accepting L(Rz), the machine moys b State. Thus, q, which is'the’start state of machine M, beeomes combined machine My and fz which is the final state of State of machine M arf accépts the language L(R1.R:).2.38 Bi Finite Automata and Regular expressions Cas figure 2. Fig. 2.6 To accept the language L(R1)* It is clear from figure 2.6 that the machine can cither accept € or ay . + ny number of thus accepting the language L(R1)’. Here, qo is the start state ris th Lay, ¢ final state, 1) Obtain an NFA which accepts strings of a's and b's starting with the string ab, ‘The regular expression corresponding to this language is ab(a+b)*, Step 1: The machine to accept ‘a’ is shown below. —@O-+@ Step 2: The machine to accept ‘b’ is shown below, Step 3: The machine to accept (a + b) is shown below. ae ea@—> Ons : \ —< xi “O—pO« . is shown below. Step 4: The machine to accept (a+b)*B Finite Automata and Formal languages — A simple approach 2,39 5; The machine to accept ab is shown below. Step 5: >( 0} a ¢ Dy b @ Yr step 6: The machine to accept ab(a+b)* is shown below. Fig, 2.7 To accept the language L(ab(a+b)*) 2) Obtain an NFA for the regular expression’a*+ b‘ + c* ‘The machine corresponding the regular expression a* can be written as roStep 1: The machine to accept (a +b) and (atb)* Step 2: The machine to accept (a+b)* is shown below. 20 2 Finite Automata and Regular expressions ‘ ¢ regular expression a* + ‘The machine corresponding the regular expression a* + b* + c* jg Shown in oS PROPOR & \ : Se = Fig. 2.8 To accept the lanigeags Lea +b* + c*) 3) Obtain an NFA for the regular expression (a+b)*aa(atb)* bn. are shown below, O@xe OOG Finite Automata and Formal languages — A simple approach 2.41 chine to accept aa is shown below. es 3; The ma siep 4: ‘The machine to accept aa(a+b)* is shown below. top 4 Fig. 2.9NFA to accept (a+b)"aa(a+b)" Le Obtain RE from FA(Kleene’s theorem) ast aes F . ae hi In this section let us see how to obtain a regular expression) from FA. using Kleene’s theorem. ee Theorem: Let M = (Q, &, §, qi, F) be an FA reco; h language L. Then there exists an equivalent regular expression R for the regulan ; If the language L is accepted by a DFA then prove thabth language L so that L=L(R) q 8 or 4 tee that if L = L(A) for some DFA A, then there'll2.42 RA Finite Automata and Regular expressions The proof along with the procedure to obtai Note: na regul, & Bular oxPreSsion automaton is shown below: : : sl Ti, he states of machine M wy : : Let Q= (qt day---dn} are th 5 | where n ig Giietpath from state 101 te state] through an intermediate stg ee DiMber of greater than kis given by the regular expression Rif as shown below, 8 TUmbey fe, ie = Ryt = {we E* wis label (path) from ito state j that gocs through an intermediate State « whose number is not greater than k} where #>K andj >k. The string w can be written as We=xy where Ix! > O and lyl> 0 and 8 (i, x) =k and Sky) =i) Basis: K-= 0. This indicates that there is no inte Tmediate state and the » States given by the following two conditions: Si ® StH and the PatD from sae ing 1. There is a direct edge from state } to State j. This is possible when ij. Hes: M with all input symbols'a such that there is a transition from stare A #DFA considered with following cases: : oe State, a. No input symbol and the corre noes Sponding regular expression ig Bivenby c. There are multiple inputs 1, 82, 3...a% where ther symbol from state j to state to j and the corres given by re is a transition from each onding regular expression is Ry? sartantas oot ay 2., There is only one state such that j = j and there exists a path from i of Symbol a forming a self loop or a path of length 0 (ic., if no loop path f State 7 then there is a path of length 0) and is denoted 3b@ Finite Automata and Formal langua ~ A simple approach 2.43 RY sate RAO Say +a. ast ok EE Induction: Suppose, there exists a path from i to j through a state which is not higher than k. This situation leads to two cases: 1. There exists a path from state i to state j which does ot go through k and so the language accepted is Ry“), “2, There exists a path from state i to state j through k as shown below: The ah from state i to state j can be broken into several pieces as shown below: . The path from state j ito state k and not passing Hhrough a state ‘higher than kis given by! Ru on 2. The path from state k to state & and not passing through astate higher than k (may exist.zero or ao times) is given by Ru ?)* 3. The path from. state k to state j and not passing through 'a state higher than k-is given by j Ry*™ is given by the concatenation of above 3 regular expressio. Re =RiX? + Ra? Ra ?)* RY? By constructing the regular expressions in inerg depends only on expressions with a smaller sup¢ available whenever there is a nced. Finally, we ~N Note: Assume that state 1 is the initial state and the sum of all regular expressions Ri where st‘Automata an! egular expressions g 244 BF d Regul: i the FA shot 4) Obtain a regular expression for o a 01 eC) e corresponding to the regulal wn belo’ What Is the lang! r expression? uage at is the | ; = 2. By renaming the states, the above FA “i yt 7 0,1 By following the procedure shown in Klcene’s theorem (scction 2.4) we have y Solution: Let go = 1 and qr shown below: 0 _Abasis: when k Rue =Et1 Note: If the beginning and ead Rene states are same add € which denotes the . : Rx =O oe Ra =e+041 Anduction: The regular expression corresponding to the path from state i through a state which is not higher than kis given by ~ to state j ») “ Y= RAD 4 RY Re? Ry h ~ path from state i to state j through’ a state not higher than 1): The various regular expressions obtained are shown below: Ry? Ry +R, RnR, F€+1)+@+1) (41) +1) +1) + (E41) 1" i 1) e+ 141 =1° ‘2 Ri ER +Ry Ri RR - +1" 0 =0+(e4+1) 0+1°0Thy “ D Finite Automata and Formal languages ~ A simple approach 2.45 ® w =Ry” +Ra? Rn)‘ Ri (0) tL o+o(e+ D' +1) =o Ra? =Ro +R RuOCR 2” =(e+04+1)+O(e4+1)'0 =(€+0+1) When k = 2 (i.c., path from state i to state j through a state not higher than 2): The various regular expressions are given by Ru? = Ru +R” ResYRe #141 “Oe +041)" o =I 1totr" Ry =Ro” Ro RPP Rv sole an “0+ 10 (€+0+1)° (€+0+1) i ~ O+1 0@+1)° (©4041) : ; yt eset) ‘04100417 Fo U* ef 2 ‘0@+1)" , =Rn® +R: RRA? + (E4041) (+0410 F wo40 | cGeaspeueog wad sil @+0+1y =(€+04+1)+ 04+] ae =@+1" eae cor) Lag iy Note: Since the total number of states in the given mi should be 2, _— Since the start state is 1 and final state is 2, the. Ry gE TOO NY | 8, the Tegular expression for the given DRAM ane tg of any number of 1’s followed by a V's. This can also be expressed as strings offressions Automata and Regular exp! 2.46 © Finite 4 monn it ular expression for the FAsI (2) Obtain a reg! is i H 0 —@- _0_», ion? is the language corresponding to the regular expression? Whal i is is already given in 3 tion for this problem is al i eae aa this problem is that, instead of calculatin; Ry fom k= 0ton, start from k =n, and then work back to ii Previous example. Ano g the regular expre; ‘SSions fay the case when k = 0. In the current example, number of stat les n= 2 and hence to start with assume k = 2, The Tegular expression is given by DR Ry =Ry” +R” Rix! MT Root), -(Eq. 1) ® Itis clear from the above expression that Ris and Ros" are Tequired and are obtained using the following regular expressions: Rud) = Rif +R, RT Rp. Ra? = Rn +R Ri OTRO, Ths fesular expressions for these two equations can be obtained if we know R, 1, R2, Rai? and Ra” which are obtained when k = 0 as shown below: 7 When k = 0; sut FR 4 RAO RRO FE+N E41 9 +1 =1'0 2 +R Ri yR, 40 E+ 04+ DG es iG =(€+0+1)X B Finite Automata and Formal languages — A simple approach 2.47 ting for Rist? and Ro2'” in Eq. (1) we have gubstitutt . Ry £Rr (Roz) Ra “0410 (E+ 041) +041) 210410041) +041) i ‘0410 O41) “0(0+1) @ Riz the regular expression for the given DFA is 1°0 (0 + 1)" which is the language Sing ‘of any number of 1's followed by a zero and then followed by strings of 0's and I's. This can also be expressed as strings of 0's and 1's with at least one zero. 3)Consider the DFA shown below po wet | States [0 1 =a a a a eo 4 *q B @ Obtain the regular expressions Rj, Ry!) and simplify the regular expressions as much as possible, Note: The symbol * preceding state q3 indicates that q3 is the final state. Solution: Rename the states 1, 2 and 3 in order and the reste) fod ete ee States [0 1 a1 2 1 2 3 1 3 3 2 Where state 3 is the final state and state 1 i 'agram is shown below:expressions foarte. and Regular 0% 7.48 BL EInite Au Shown in Kleen eorem (section 24) we aye how! p By following the procedure asks: when kel Ryser l Note: If the beginning and ending Rae 0 stater are name add & which denotes the Ryn length 0 (i.c., whenever i = j) Ry co el Rag rere Rays 0 Rad Ry” = 1 RyVae+0 Induction: ‘The regular expression corresponding to the path from state i to State j through a state which is not higher than k is given by RM ERM 4 Ry HY | Ruy RyY When k = 1 (ic, path from state i to state j through a state not higher than 1): The various regular expressions obtained are shown below: Ry? eR Ry Ry sR, RY sR FR [ROP R =0+(€+ 1) (e+ 1) 0 =041°0 = 10 Ra sry FR [Ry RW Bot +1 +1) 9 Ry? = Ry +R RvR, +1 @+1) (+1) =141)°=11"B Finite Automata and Formal languages — A simple approach 2.49 Ra = =Rn® + Rx® RnOFR2” +1E+ yo se+110 2 Ra + Ra Rn OV Rs” Ras? O+1E+D Oo =0 Ru? =Ra® +R? RuOeRn HOro(et 1) (e+) =o Rx? =Rx2” * Ra nO TR” 3 =1l+o(e+1)0 ! =1 Ry =R3 +R” Ri Re” =(€+0)+ (+0) 6 =(€+0) ° : When k = 2 (ie., path from state i to state j through a state not higher than 2): The various regular expressions are given by Ri (2) =Ru® +R Ra)" Ra =I +VOeriT Oy =1'+1°001"0)11" R® =Rv? +R RP] Ra” | = 10+ 1°0 (+ 110) *(e+11°0) t =1°0+1°0(11'0)" (e+ 11°0) Ru = Rs? + Riv” Reg Ra” =o+1'0 E+ 110) 0 = 1'0a1'0y"0 Rn® = Ra? +Rx? Ra)" Rai? 1 +(e + 11"0) +11 “oy 14 (e+11'0) (1'O)11"2.50 ¢ Automata and Regular expressions tp (1) {9 Raf RVR * Ra =Ra! uo; e(er 110) (e411°09 (e110) =(€+11°0) +(e + 11°0) (110) (e+ 11°0) Ra Ros Rx® =Ro + Rag’? [Rar] Rog 0+ +110) (4110) 0 =0+(e+11°0) (11'0)' 0 i Ra SR” + Rn RR” i =o+ M+ 110) 11 =101"0)11" Rn® =Rx® +R RAR +1(e+ 110)" +110) =1+1(11'0)° @+11'0) Ra =R yO 4 ER, RRO \ } =(+e)+1(11'0)'0 4 a ‘The regular expression is given by Rus can 3 can be calculated as shown below: Ru® SRO 4 Ry Ry@P RP =1011"0)'0 + 1'0(11"0)'0 (0+ 2) +1010) oF (04 ®)+1(11°0)'0 263 To Obtain RE from FA(by eliminating States) a In this section let us see how to obtain a regular ex Theorem: Let M exists an equivale Pression from FA, = Q & 8 qo, F be an FA Fecognizing the language L, Then there ‘nt regular expression R for the regular language L such thar L=L@). The general procedure ‘0 obtain a regular expression from FA is shown below. Consider the generalized graph 1 f\non fn — ts Fig. 2.10 Generalized transition graphnite Automata and Formal languages — A simple a ari ry and 4 a ‘¢ rogular expression for sty (tat gts 2) re the regular expressions and correspond to the labels for the this can take the form: (2.1) cach final state (accepting state) q, apply the reduction procedure and bring ere graph to the form shown in figure 2.10. 2, ais not the start state, the reduced graph obtained will be of the form shown in figure 2.10. and use the equation 2.1 to obtain the regular expression. ote! For the state elimination process has to be rt state is also an accepting state, t the start state. The final 3, If the stat ; performed so that we should get rid of every state excep! automaton will be of the form r 5 — bs start 4, The final regular expression is the sum of all the regular expressions obtained from the reduced automata for each accepting state. or example, If rs is not there in figu re 2.10, the regular expression can be of the form r=% (2% (2.2) then the regular expression can be of the form (2.3) {If qo and qi are the final states, ren* +4) 2% ) Obtain a regular expression for the FA shown below: 0 ce the state q3 is reached ere is no way to reach the and the resulting figure is It is clear from the FA that qs is the dead state (i.e., respective of.the input, the machine stays in q3 only {final state) and so all the edges'connected to q3 can be re! shown below:a Automata and Regular expressions Itis clear from the figure that if we input the string 01, the machine goes to state comes back to qo and the process can be repeated, So, instead of qi, we can loop bag! the string 01 as shown below: % Similarly on 10, the machine comes back to go and so we can replace it by another loop with the edge labeled 10 as shown: : Itis clear from this fj i : ; z igure that the machine accepts strings of 01's and 10's of any len; and the regular expression can be of the form eee (01 +10)" 2 *) What Is the language accepted by the following FA Since, nt p + tat ‘Me q2 is the dead state, it can be removed and the following FA is obtained.state go is the final state and at this point it can accept any number of 0's which can ‘The si ented using notation as 0 be represent ago the ial state, So, to reach gy one can input any number of 0's followed by 1 a. alowed by any number of 1's and can be represented as ol so the final regular expression is obtained by adding 0° and 0°11". So, the regular expression is et(e+uo RE 2 oh ( eu") P 2 x, It is clear from the regular expression that language consists of any number of 0's (possibly ¢) followed by any number of 1"s(possibly €). 9) Obtain a regular’ expression for the FA shown below: Ou By comparing this figure witll figure 2.10, nn=1401'0 :2.54 B Finite Automata and Regular expressions By substituting these in equation 2.1 wehave, u r=(1+01°0)' 01°1[ (+1) + 641 + 01°0)"01" 1] 14010)" onit (+1) +6] = (1+01°0)" 01°1 +1) So, the regular expression for the given FA is (1 +01°0)" O1°1 (0+1)" 2.7 Applications of Regular Expressions Pi, Regular expressions in UNIX: Regular expressions operating system. But, certain short hand notations which complex regular expressions are avoided. For any character, the sequence [abede.....] stands for the . .", the operator | is used in place of +, the oper of the commands are invoked sé extensively used in‘ UNK fe used in UNIX platform usitt mple, the symbol ‘.’ stands ft ular expression “a +b +c+d+ Pattern Matching refers to a set of objects with an identifier or a decimal number or we can sesies of regular languages es & Properties o! 3.2_G Regular languag! he intersection of two regular languages is also Te For exampl ; a recogni two different languages, we can Cons a , there Se A Tecoeniees the intersection of these two languages, ty automato! = co s: Using this property, w, isi lar languages: Using » We can sion property of regul » we : Phather a colonia define the same language. If $0, E can Fee tht of automata with as few states as possible. The mina ion of automaton ne important in the design of switching circuits. This is because, as the nung states of automaton decreases the size of the circuit and hence the cost Aecreaga” Any finite language can be expressed using regular expressions and we can cons finite automata (DFA or NFA or e-NFA). Though the regular languages are imp there are non-regular languages which are very interesting and important, Fe example, following are some of the non-regular languages: 1, L={w:we {0, 1}* and has equal number of 0’s and 1’s } “2. L={0°l" forn> 0} 3. L={a? © where p>2isa prime number } 4. Language consisting of matching parentheses Apart from above four languages, there are so many languages which are not regulzr, Now, the question is “How to prove that certain languages are not regular?” We cay Broye that certain languages are not regular using one powerful tool called Pumping emma. (32 Pumping Lemma for regular languages Now, let us “State and Prove pumping lemma for tegular languages” 1+5 marks in VTU July/Aug 2004 5, 8 marks in VTU Jan/Feb 2006 Aiteorem: Let Mx (WX, 8,40, : F) be an FA and has n number of states. Let L be the regular language accepted by M. Let for every string x in L, there exists a constant n een fee bi 2 n. Now, if the string x can be broken into three substrings u, y and w suc! at * x=uv satisfying the following constraints: v#e€ie, vi>] # luvisn then.uy'w is in L for i20 =— 22 Finite Automata and Formal languages — A simple approach3.3 - proof: Let M=(Q, >, 5, do, F) be an FA and Let L is the language accepted by DFA and is regular. Let x = 444)43...4,, Where m 2 n and each a; is in L. Here, n represent the states of DFA. since we have m input symbols, naturally we should have m+1 states in the sequence Go Gis Jaeve Ie where qo will be the start state and q,, will be the final state as shown below: : —@@2-@ -3@6->@ Since IxI 2 n, by the pigeon hole principle it is not possible to have distinct transitions. On¢e of the state can have a loop. Let the string x is divided into three substrings as shown below: ’ ¢ The first group is the string prefix from ayap...a; i.e., U = aya2...8; ¢ The second group is the loop string from aj413+2. ry V = Dig tis nee 13 + The third group is the string suffix from aj412j12---dm L€., W = Qj12}42---Am —““O es : - aNy iy G8 G20 GH @-"—>( + aa <—__—— Y¥ — > Prefix (u) Loop(v) Suffix(w) Observe from above figure that, the prefix string u takes the machine from qp to q;, the loop string v takes the machine from q; to q, Wote: qi = 4g) and suffix string w takes the machine from qj to qr. The minimum string that can be accepted by the above FA. is uw with ic0, ( : But, when i=1, the string uvw is accepted by DFA When i=2, the string uvvw is accepted by DFA. So, if i>0, the machine goes from qo to q; on input string u, circles from gq; to q; based on the value of i and then goes to accepting state on input string w. In general, if the string x is split into sub panes uy then for alli >0, uvwe L3.4 Gl Regular languages & Properties of regular languages ‘This can be expressed using the transitions as shown below: (Go, Aa. soon 1B} pa. re = 8( 8(qo, M12... = Bla, dita. = Bo Misti = dn Also, after the string the machine will be in state qi. Since q; and qj are same, we can ji Aindiy2- ij input the String any number of times and the machine will stay in qj only. Finally, if the input a 00Oy Ais1jaa.... the machine enters into final state q,,. “ (5 Petstin of Pumping Lemma fow, let us see “What are the applications of pumping lemma?” is a very powerful tool and has the following applications: ¢ Pumping lemma is used to i uages are non-regular.} cannot be used to prove th i ied * Using pumping lemma, * FA is finite or infinite. The pumping ane Seneral strategy used to prove that Certain language is not regular is $ below. : ; Step 1: Assume that the language L is regular and n be the number of states off Step 2: Select the string x such that ixl> n and break it into substri iy ae that x = uvw with the constraints: pairings u, v and * v#eie, M21 * hvisn Step 3: Find any i such that uv'w is not in Lie, ulwe'T Jemma, uv'w is in L for i2 0. So, the result j assumption that the language is regular, Therefc is not regular.
You might also like
Bcs503 Module 2
PDF
No ratings yet
Bcs503 Module 2
46 pages
Atcd Module 2 2021 Scheme
PDF
No ratings yet
Atcd Module 2 2021 Scheme
56 pages
ACD Module - 2 Notes
PDF
No ratings yet
ACD Module - 2 Notes
28 pages
Atc-21cs51 Module 2
PDF
No ratings yet
Atc-21cs51 Module 2
56 pages
Reguler Language and Reguler Expression
PDF
No ratings yet
Reguler Language and Reguler Expression
4 pages
Unit 3 - Regular Expression
PDF
No ratings yet
Unit 3 - Regular Expression
45 pages
Class 10 Regular Expression
PDF
No ratings yet
Class 10 Regular Expression
26 pages
Automata Chapter 2
PDF
No ratings yet
Automata Chapter 2
15 pages
Automata Theory Computability - M2
PDF
No ratings yet
Automata Theory Computability - M2
68 pages
Regular Expression
PDF
No ratings yet
Regular Expression
21 pages
Lecture 7
PDF
No ratings yet
Lecture 7
70 pages
Chapter 2 RegularExpressions (3)
PDF
No ratings yet
Chapter 2 RegularExpressions (3)
95 pages
Chapter 2 RegularExpressions
PDF
No ratings yet
Chapter 2 RegularExpressions
95 pages
unit2
PDF
No ratings yet
unit2
135 pages
Vision 2023 Toc Chapter 3 Regular Expression 59
PDF
No ratings yet
Vision 2023 Toc Chapter 3 Regular Expression 59
8 pages
chapter two
PDF
No ratings yet
chapter two
59 pages
Unit-2 Regular Expression and Languages
PDF
No ratings yet
Unit-2 Regular Expression and Languages
42 pages
Regular Expressions
PDF
No ratings yet
Regular Expressions
169 pages
2.0+Regular Expression Part 1 MKN
PDF
No ratings yet
2.0+Regular Expression Part 1 MKN
33 pages
Toc Unit 2
PDF
No ratings yet
Toc Unit 2
29 pages
TOC Module-2 Notes
PDF
No ratings yet
TOC Module-2 Notes
24 pages
Unit Ii
PDF
No ratings yet
Unit Ii
25 pages
Wa0014.
PDF
No ratings yet
Wa0014.
85 pages
Regular Expressiontzzz
PDF
No ratings yet
Regular Expressiontzzz
46 pages
Chapter Two Regular Expression and Regular Language
PDF
No ratings yet
Chapter Two Regular Expression and Regular Language
30 pages
FLAT Regular Expressions and Languages
PDF
No ratings yet
FLAT Regular Expressions and Languages
14 pages
Regular Expression
PDF
No ratings yet
Regular Expression
14 pages
RE- basics
PDF
No ratings yet
RE- basics
26 pages
chapter 3
PDF
No ratings yet
chapter 3
10 pages
Unit 2
PDF
No ratings yet
Unit 2
53 pages
Regular Expression Notes
PDF
No ratings yet
Regular Expression Notes
46 pages
ATCD-UNIT-2
PDF
No ratings yet
ATCD-UNIT-2
28 pages
Regular Expression: Operations On Regular Language
PDF
No ratings yet
Regular Expression: Operations On Regular Language
33 pages
TOC Unit2
PDF
No ratings yet
TOC Unit2
87 pages
Unit 2: Can Be Recursively Defined As Follows
PDF
No ratings yet
Unit 2: Can Be Recursively Defined As Follows
28 pages
Regular Expressions and Languages
PDF
No ratings yet
Regular Expressions and Languages
16 pages
TOC SY Unit-3
PDF
No ratings yet
TOC SY Unit-3
80 pages
Regular Expression
PDF
No ratings yet
Regular Expression
10 pages
FAFL Final Lecture 2.1
PDF
No ratings yet
FAFL Final Lecture 2.1
21 pages
cs212 Lect02 63 Inter
PDF
No ratings yet
cs212 Lect02 63 Inter
39 pages
Unit-3 Regular Expressions
PDF
No ratings yet
Unit-3 Regular Expressions
100 pages
REGULAR EXPRESSIONS
PDF
No ratings yet
REGULAR EXPRESSIONS
22 pages
Regular expression
PDF
No ratings yet
Regular expression
89 pages
re-nfa-220110090941
PDF
No ratings yet
re-nfa-220110090941
15 pages
Chapter 03 - Regular Expression and Language
PDF
No ratings yet
Chapter 03 - Regular Expression and Language
42 pages
WINSEM2024-25_ISWE203L_TH_VL2024250503413_2025-01-20_Reference-Material-I
PDF
No ratings yet
WINSEM2024-25_ISWE203L_TH_VL2024250503413_2025-01-20_Reference-Material-I
30 pages
Chapter 3 Regular Expressions Notes
PDF
100% (1)
Chapter 3 Regular Expressions Notes
36 pages
Rohini 41292706916
PDF
No ratings yet
Rohini 41292706916
6 pages
3-5 Simplified Note
PDF
No ratings yet
3-5 Simplified Note
32 pages
Theory of Automata
PDF
No ratings yet
Theory of Automata
22 pages
Chapter 2 REGULAR EXPRESSION
PDF
No ratings yet
Chapter 2 REGULAR EXPRESSION
26 pages
Module 2flat
PDF
No ratings yet
Module 2flat
26 pages
Regular Sets and Expressions: Definition. 0, 1, Definition. If
PDF
No ratings yet
Regular Sets and Expressions: Definition. 0, 1, Definition. If
7 pages
Toc U2
PDF
No ratings yet
Toc U2
31 pages
AT&CD Unit 1
PDF
No ratings yet
AT&CD Unit 1
19 pages
re-nfa-220110090941
PDF
No ratings yet
re-nfa-220110090941
20 pages
Unit II Regular Expression
PDF
No ratings yet
Unit II Regular Expression
176 pages
Unit 9 - Final
PDF
No ratings yet
Unit 9 - Final
19 pages
Theory of Computation - Regular Expressions and Regular Languages - Sanfoundry
PDF
No ratings yet
Theory of Computation - Regular Expressions and Regular Languages - Sanfoundry
2 pages