CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00) 0 0 (00) (11) 1 1 0 0 1
(00) (11) 01 1 1 0 0 0 1 ((00) (11) 01) 1 1 0 0 0 1 2. Use the procedure descried in Lemm 1.60 to convert the following DFA M to regulr expression., 1 2 3 Answer: First convert DFA M into n equivlent GNFA G. 2
s 1 2 t 3 Next, we eliminte the sttes of G (except for s nd t) one t time. The order in which the sttes re eliminted does not mtter. However, eliminting sttes in different order from wht is done elow my result in different (ut lso correct) regulr expression. We first eliminte stte 3. To do this, we need to ccount for the pths 2 3 1, which will crete n rc from 2 to 1 lelled with ; 2 3 2, which will crete n rc from 2 to 2 lelled with ; nd 2 3 t, which will crete n rc from 2 to t lelled with =. We comine the previous rc from 2 to 2 lelled with the new one lelled to get the new lel. s 1 2 t We next eliminte stte 1. To do this, we need to ccount for the following pths: s 1 2, which will crete n rc from s to 2 lelled with ( ) =. s 1 t, which will crete n rc from s to t lelled with =. 2 1 2, which will crete n rc from 2 to 2 lelled with ( ). We comine this with the existing 2 to 2 rc to get the new lel ( ). 2 1 t, which will crete n rc from 2 to t lelled with =. We comine this rc with the existing rc from 2 to t to get the new lel. 3
s 2 ( ) t Finlly, we eliminte stte 2 y dding n rc from s to t lelled ( )( ( )) ( ). We then comine this with the existing s to t rc to get the new lel ( )( ( )) ( ). s ( )( ( )) ( ) t So regulr expression for the lnguge L(M) recognized y the DFA M is Writing this s ( )( ( )) ( ). }{{} ( ) ( ( )) }{{}}{{} sty in 1 1 to 2 ( ) }{{} (2 to 2) end in 3 or 1 should mke it cler how the regulr expression ccounts for every pth tht strts in 1 nd ends in either 3 or 1, which re the ccepting sttes of the given DFA., 1 2 3 3. Prove tht the following lnguges re not regulr. () A 1 = {www w {,} } Answer: Suppose tht A 1 is regulr lnguge. Let p e the pumping length of the Pumping Lemm. Consider the string s = p p p. Note tht s A 1 4
since s = ( p ) 3, nd s = 3(p + 1) p, so the Pumping Lemm will hold. Thus, we cn split the string s into 3 prts s = xyz stisfying the conditions i. xy i z A 1 for ech i 0, ii. y > 0, iii. xy p. Since the first p symols of s re ll s, the third condition implies tht x nd y consist only of s. So z will e the rest of the first set of s, followed y p p. The second condition sttes tht y > 0, so y hs t lest one. More precisely, we cn then sy tht x = j for some j 0, y = k for some k 1, z = m p p for some m 0. Since p p p = s = xyz = j k m p p = j+k+m p p, we must hve tht j +k +m = p. The first condition implies tht xy 2 z A 1, ut xy 2 z = j k k m p p = p+k p p since j + k + m = p. Hence, xy 2 z A 1 ecuse k 1, nd we get contrdiction. Therefore, A 1 is nonregulr lnguge. () A 2 = {w {,} w = w R }. Answer: Suppose tht A 2 is regulr lnguge. Let p e the pumping length of the Pumping Lemm. Consider the string s = p p. Note tht s A 2 since s = s R, nd s = 2p+1 p, so the Pumping Lemm will hold. Thus, we cn split the string s into 3 prts s = xyz stisfying the conditions i. xy i z A 2 for ech i 0, ii. y > 0, iii. xy p. Since the first p symols of s re ll s, the third condition implies tht x nd y consist only of s. So z will e the rest of the first set of s, followed y p. The second condition sttes tht y > 0, so y hs t lest one. More precisely, we cn then sy tht x = j for some j 0, y = k for some k 1, z = m p for some m 0. Since p p = s = xyz = j k m p = j+k+m p, we must hve tht j + k +m = p. The first condition implies tht xy 2 z A 2, ut xy 2 z = j k k m p 5 = p+k p
since j + k + m = p. Hence, xy 2 z A 2 ecuse ( p+k p ) R = p p+k p+k p since k 1, nd we get contrdiction. Therefore, A 2 is nonregulr lnguge. (c) A 3 = { 2n 3n n n 0}. Answer: Suppose tht A 3 is regulr lnguge. Let p e the pumping length of the Pumping Lemm. Consider the string s = 2p 3p p. Note tht s A 3, nd s = 6p p, so the Pumping Lemm will hold. Thus, we cn split the string s into 3 prts s = xyz stisfying the conditions i. xy i z A 3 for ech i 0, ii. y > 0, iii. xy p. Since the first p symols of s re ll s, the third condition implies tht x nd y consist only of s. So z will e the rest of the first set of s, followed y 3p p. The second condition sttes tht y > 0, so y hs t lest one. More precisely, we cn then sy tht x = j for some j 0, y = k for some k 1, z = m 3p p for some m 0. Since 2p 3p p = s = xyz = j k m 3p p = j+k+m 3p p, we must hve tht j +k +m = 2p. The first condition implies tht xy 2 z A 3, ut xy 2 z = j k k m 3p p = 2p+k 3p p since j + k + m = 2p. Hence, xy 2 z A 3 ecuse k 1, nd we get contrdiction. Therefore, A 3 is nonregulr lnguge. (d) A 4 = {w {,} w hs more s thn s}. Answer: Suppose tht A 4 is regulr lnguge. Let p e the pumping length of the Pumping Lemm. Consider the string s = p p+1. Note tht s A 4, nd s = 2p + 1 p, so the Pumping Lemm will hold. Thus, we cn split the string s into 3 prts s = xyz stisfying the conditions i. xy i z A 4 for ech i 0, ii. y > 0, iii. xy p. Since the first p symols of s re ll s, the third condition implies tht x nd y consist only of s. So z will e the rest of the s, followed y p+1. The second condition sttes tht y > 0, so y hs t lest one. More precisely, we cn then 6
sy tht x = j for some j 0, y = k for some k 1, z = m p+1 for some m 0. Since p p+1 = s = xyz = j k m p+1 = j+k+m p+1, we must hve tht j +k +m = p. The first condition implies tht xy 2 z A 4, ut xy 2 z = j k k m p+1 = p+k p+1 since j + k + m = p. Hence, xy 2 z A 4 ecuse it doesn t hve more s thn s since k 1, nd we get contrdiction. Therefore, A 4 is nonregulr lnguge. 4. Suppose tht lnguge A is recognized y n NFA N, nd lnguge B is the collection of strings not ccepted y some DFA M. Prove tht A B is regulr lnguge. Answer: Since A is recognized y n NFA, we know tht A is regulr since lnguge is regulr if nd only if it is recognized y n NFA (Corollry 1.20). Note tht the DFA M recognizes the lnguge B, the complement of B. Since B is recognized y DFA, y definition, B is regulr. We know from prolem on the previous homework tht B eing regulr implies tht its complement B is regulr. (B is the complement of the complement of B.) But B = B, so B is regulr. Since A nd B re regulr, their conctention A B is regulr y Theorem 1.23. 5. () Prove tht if we dd finite set of strings to regulr lnguge, the result is regulr lnguge. Answer: Let A e regulr lnguge, nd let B e finite set of strings. We know from clss (see pge 1-95 of Lecture Notes for Chpter 1) tht finite lnguges re regulr, so B is regulr. Thus, A B is regulr since the clss of regulr lnguges is closed under union (Theorem 1.22). () Prove tht if we remove finite set of strings from regulr lnguge, the result is regulr lnguge. Answer: LetAeregulrlnguge,ndletB efinitesetofstringswithb A. Let C e the lnguge resulting from removing B from A, i.e., C = A B. As we rgued in the previous prt, B is regulr. Note tht C = A B = A B. Since B is regulr, B is regulr since the clss of regulr lnguges is closed under complement. We proved in n erlier homework tht the clss of regulr lnguges is closed under intersection, so A B is regulr since A nd B re regulr. Therefore, A B is regulr. 7
(c) Prove tht if we dd finite set of strings to nonregulr lnguge, the result is nonregulr lnguge. Answer: Let A e nonregulr lnguge, nd let B e finite set of strings. We wnt to dd B to A, so we my ssume tht none of the strings in B rein A, i.e., A B =. Let C e the lnguge otined y dding B to A, i.e., C = A B. Suppose tht C is regulr, nd we now show this is impossile. Since A B =, we hve tht A = C B. Since C nd B re regulr, the previous prt of this prolem implies tht C B should e regulr, ut we ssumed tht A = C B is nonregulr, so we get contrdiction. (d) Prove tht if we remove finite set of strings from nonregulr lnguge, the result is nonregulr lnguge. Answer: Let A e nonregulr lnguge, nd let B e finite set of strings, where B A. Let C e the lnguge otined y removing B from A, i.e., C = A B. Suppose tht C is regulr, nd we now show this is impossile. Since we removed B from A to get C, we must hve tht C B =, so A = C B. Now C is regulr y ssumption nd B is regulr since it s finite, so C B must e regulr y Theorem 1.25. But we ssumed tht A = C B is nonregulr, so we get contrdiction. 6. Consider the following sttement: If A is nonregulr lnguge nd B is lnguge such tht B A, then B must e nonregulr. If the sttement is true, give proof. If it is not true, give counterexmple showing tht the sttement doesn t lwys hold. Answer: The sttement is not lwys true. For exmple, we know tht the lnguge A = {0 j 1 j j 0} is nonregulr. Define the lnguge B = {01}, nd note tht B A. However, B is finite, so we know tht it is regulr. 8