CSE 5: Introduction to the Theory o Computtion, Winter A. Hevi nd J. Mo Solution to Prolem Set Jnury, Solution to Prolem Set.4 ). L = {w w egin with nd end with }. q q q q, d). L = {w w h length t let nd it third ymol i }.,, q q q q q 4,, l). L = {w w contin n even numer o, or exctly two }. q q q 4 q 6 q q q 5,.5 ). L = {w w end with } with three tte. Notice tht w only h to end with, nd eore the two zero, there cn e nything. Thereore, we cn contruct the ollowing NFA to recognize L:, q q q
CSE 5, Solution to Prolem Set. ). We need to give n exmple o NFA M (nd correponding lnguge C = L(M)) uch tht, wpping the ccept nd non-ccept tte in M yield NFA (y M ) tht doe NOT recognize the complement o C. The exmple i the ollowing: conider the lnguge C = {, } recognized y the ollowing NFA: q q Clerly, wpping the ccept nd non-ccept tte give the ollowing NFA M q q But the lnguge recognized y M contin the empty word () which lredy i in C = L(M). Thereore, L(M ) cnnot e the complement o L(M) (otherwie it wouldn t ccept ).. To trnorm n NFA into DFA, we trt with inding the -cloure o the originl trt tte q nd mke E(q ) the new trt tte. A conveninent wy to ve work nd void mitke i to compute trnition only or the new tte ppered in previou computtion, trting rom the new trt tte. Thi lzy trtegy i proved to e correct nd the proo cn e ound in the irt dicuion ection note. Second thing to er in mind i tht we re lwy computing the -cloure o the trnition. Don t orget tht! ). The -cloure o the originl trt tte remin the me or thi NFA. Plee reer to Figure or the inl DFA., Stte,,,,,, Φ, Figure : Prolem. ()
CSE 5, Solution to Prolem Set ). Notice tht or thi NFA, the -cloure o it originl trt tte i no longer the me. It i ctully the new tte {, }. So we ll trt rom here. Plee reer to Figure or the inl DFA. Stte,,,,,,,,,,,, Figure : Prolem. (),,,, Φ,. e). L = {w w trt with nd h odd length, or trt with nd h even length}. Solution: Almot directly rom the deinition o L: ( ) (( ) ( )). h). L = {w w i ny tring except nd }. Solution: ( ) ( )( ). Tip: How did we come up with thi? Firt uild the NFA or DFA tht recognize the lnguge (or the complement o the lnguge ought; recll tht, given DFA recognizing L, the DFA recognizing L i given y wpping the ccept nd non-ccept tte in the DFA or L). Then, y imple inpection (or uing the NFA-to-RE trnormtion procedure) otin the correponding RE. For exmple, the DFA tht recognize L i: q q q q q 4,, (it not hrd to ee how to get to the regulr expreion rom the ove DFA). j). L = {w w contin t let two nd t mot one }. Solution: ( ). Tip: The DFA tht recognize L i:
CSE 5, Solution to Prolem Set 4 q q q 4 q q q 5 q 6,.4 ). We convert the regulr expreion ( ) ( ) into n NFA y ollowing the tep in Theorem.8 (hown in Figure ). Finlly, or comprion, we lo how n equivlent NFA uilt y oerving pttern which i much impler (hown in Figure 4.) ). Sme tep ove or the regulr expreion ((() ()) ). Plee reer to Figure 5..6 ). We need to convert the NFA o Figure 6 (upper let utomt) into regulr expreion. We mut ollow the uul procedure:. Trnorm the NFA into GNFA. Remove tte o the GNFA one y one. For exmple, we irt remove tte nd then tte.. When only the (ingle) trt tte nd the (ingle) ccept tte re remining, the reulting regulr expreion i the regulr expreion leling the lt rrow. Thi i ( ). The procedure i depicted in Figure 6. ). We need to convert the NFA o Figure 7 (upper let) into regulr expreion. We ollow the me procedure eore, which i depicted in Figure 7. The equivlent regulr expreion i (( ) )( ( )) ) ( )..7 ). A = {www w, } Proo: Sme Exmple.4 on Pg. 8 o the Siper ook. c). A = { n n }. (Here, n men tring o n ) Proo: Aume to the contrry tht A i regulr. By the Pumping Lemm, ny tring in it longer thn the pumping length hould e pumple. Let the pumping length e p. We chooe p A the tring tht we will pump. Let w = xyz = p. By condition o the lemm, xy p. Thi men tht the pumping prt, which h to e non-zero in length cnnot e o length greter thn p.
CSE 5, Solution to Prolem Set 5 (U)* Figure : Prolem.4 () NFA rom ollowing tep in Theorem.8,, Figure 4: Prolem.4 () Simpler NFA y inpection
CSE 5, Solution to Prolem Set 6 Figure 5: Prolem.4 () ( ) Figure 6: Prolem.6 (). Trnorming NFA into the equivlent RE. Firt, convert the originl NFA (irt grph) into GNFA (econd grph); then remove tte (third grph) nd tte (lt grph) until only tte nd re let.
CSE 5, Solution to Prolem Set 7, ( ) ( ) ( ( )) ( ) (( ( )) ) ( ) Figure 7: Prolem.6 () Trnorming NFA into the equivlent RE. Firt, convert the given NFA (upper let) into GNFA (upper middle); then in equence remove tte (upper right), (lower let), nd (lower right) until only tte nd re let. Let the length o thi prt e q.t. q p. By Clue o the Pumping Lemm: k N, n N.t. n = p + kq Let u conider the ce where k =. By the Pumping Lemm, there mut e n n.t. n = p + q where < q p. Now we know tht or m N, m + m < m+. Since q < p, it ollow tht p + q < p+. Hence it i not poile tht the tring we get y one round o pumping e memer o A. Tht i, there i long enough tring in A tht cnnot e pumped. Hence A i not regulr. In generl, lnguge tht involve more thn liner growth re never regulr.. c). Conider L = { n m : n m }. Prove thi lnguge i not regulr y uing the Pumping Lemm. Proo: Aume y contrdiction tht L i regulr. Then, y PL, we know tht there exit pumping length p > uch tht ny word w L, w p cn e prtitioned xyz = w (with xy p nd y > ) in uch wy tht, or ny i, the word xy i z lo elong to L. Notice tht reching contrdiction my e tricky in thi ce, ince it not enough to how tht there exit prtition xyz = w uch tht w cnnot e pumped (recll tht y pumping word w = xyz we men conidering word o the orm xy i z or i ). Inted, we need to exhiit word w L uch tht, ny poile prtition xyz = w, w cnnot e pumped without lling out lnguge L. Mot choice o word do not work ince they cn e pumped. Mgiclly, (hopeully, y the end o the prolem you ll ee why) we ue the word p p+p!, where p! = p (p ). Clerly w p. Moreover, ny prtition o w into xyz mut e uch tht y comprie only (ince xy p). Then, it mut e the ce tht y = k or ome k < k p (ince y > ). Now, we conider the word w = xy i z, or ome i which we leve unpeciied or now.
CSE 5, Solution to Prolem Set 8 The word w equl xy i z = p+(i )k p+p!. We wnt to prove tht or ny vlue o k (tht i, ny poile y nd thu, ny poile prtition) there exit vlue o i which cue w to hve the me numer o nd : n = p + (i )k = p + p! = m. Thi contrdict the condition n m or word in L. Indeed, y olving p + (i )k = p + p! we get i = p! k +. So, or ny vlue o k (recll tht < k p) p! k + will e poitive integer nd thu, there exit vlue i (nmely i = p! k + ) uch tht w L. Neverthele, y PL, w L. We ve got contrdiction. Alterntive olution: We cn lo how tht thi lnguge i not regulr y uing cloure propertie o regulr lnguge. By contrdiction, ume L i regulr. Then L i lo regulr. Let ee how L look like: L i the lnguge o ll the word tht either () re o the orm n m, where n = m, or () contin the utring (which i not llowed in L). Thereore, L = { n n : n } { w : w = ( ) ( ) }. And thu, L \ { w : w = ( ) ( ) } = { n n : n }. The let hnd ide o the lt expreion i regulr ecue the et-minu opertion i regulr (recll tht A \ B = A B). However, the right hnd ide i not. We ve got contrdiction. d). Show tht the lnguge L = {w w {, } i not plindrome }. Proo: Recll tht word w i plindrome i w = w R, where w R i the word ormed y revering the ymol in w (eg. i w =, then w R = ). For exmple w = i plindrome. A lwy, we prove it y contrdiction. Aume L i regulr. Then the lnguge complement o L, y L = L = {w w {, } i plindrome } i lo regulr. I L i regulr, then y pumping lemm, there exit n integer p > (the pumping length) uch tht ny word w L, w p cn e prtitioned xyz = w (with xy p nd y > ) in uch wy tht, or ny i, the word xy i z lo elong to L. However, conider the word w = p p. Clerly, w = p + o it tiie the condition w p o the theorem. However, ny vlid prtition o w into word x, y, z (vlid in the ene tht w = xyz, y >, nd xy p) mut e uch tht y = k or ome integer k >, (ince xy p, tring y cn t contin the middle ) nd then x = p k, nd z = p. I we orm the word w = xy z (tht i, tke i = ). then w = p k p = p k p which cnnot e plindrome ince p k < p. Thu, w L, which contrdict the reult o the pumping lemm.