CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w w {0, 1} nd w ends with 00}.. L is the lnguge represented y the regulr expression ( + ) ( + ). q0 q1 c. L = {0101, 101, 1100}. 1
Question 2. [30 pts.;, 5 pts.; c 20 pts.] L R is the lnguge of strings which re the reverse of the strings in the lnguge L. For L = {w w {, } nd in ech initil sustring of w, numer of s the numer of s 2} complete the following exercises:. Construct the digrm of DFA which ccepts strings in the lnguge L. 2
. Construct the digrm of n NFA which ccepts strings in the lnguge L R. q0 λ λ q5 λ q3 λ q4 c. Convert the NFA to DFA. Be sure to provide ll five components of the DFA, show the trnsition tle for δ, nd provide digrm. You my relel the sttes for 3
convenience, if you like. releling tkes plce. If you do, e sure to show the intermedite steps where Using the lzy construction method, we do ε-closure on stte q5 to otin the initil stte q0q1q2q3q4q5 nd then uild the trnsition tle from there. Note the releling in the sme tle. δ q0q1q2q3q4q5 A q0q1q3q4 B q0q1q2q3 C q0q1q3q4 B q0q3q4 D q0q1q2q3 C q0q1q2q3 C q0q1q3q4 B q0q1q2 F q0q3q4 D q3q4 G q0q1q3 H q0q1q2 F q0q1q3 H q1q2 I q3q4 G q4 L q0q3 J q0q1q3 H q0q3q4 D q0q1q2 F q1q2 I q0q1 K q2 M q0q3 J q3q4 G q0q1 K q0q1 K q0q3 J q1q2 I q4 L Q q3 N q2 M q1 O Q q3 N q4 L q0 P q1 O q0 P q2 M q0 P q3 N q1 O Q Q Q We use ll sttes tht contin q0 s ccepting sttes giving Where δ is s defined in the tle, we hve F = {A, B, C, D, F, H, J, K, P }. M = {A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q}, {, }, δ, A, {A, B, C, D, F, H, J, K, P } Here is the digrm. Look how pretty it is! 4
H P Q C K F O I M Cn you find the oddity in this solution? I mde mistke in converting the NFA ut ws le to fix it y just simple deletion... Cn you see wht it is? Question 3. [25 pts.;,, c 5 pts; c 10 pts] Given lnguges L 1 = {w w {, }, w 3}, L 2 = {w w {, }, w contins },. Construct the digrms of the DFAs which ccept strings in the lnguges L 1 nd L 2. 5
. Construct the digrm of n NFA which ccepts strings in the lnguge L 1 L 2. 6
c. Convert the NFA to DFA, in the sme wy s in Question 2c. We define new initil stte sed on the ε-closure of the initil stte q0 giving q0q1q5. Now we lzily construct the trnsition tle. δ q0q1q5 A q2q5 B q2q6 C q2q5 B q3q5 D q3q6 E q2q6 C q3q5 D q3q7 F q3q5 D q4q5 G q4q6 H q3q6 E q4q5 G q4q7 I q3q7 F q4q7 I q4q7 I q4q5 G q4q5 G q4q6 H q4q6 H q4q5 G q4q7 I q4q7 I q4q7 I q4q7 I The ccepting sttes re those sttes tht re ccepted y either one mchine or the other. Tht would e ll the sttes tht include q4 or q7. Thus we hve F = {F, G, H, I} nd we cn define the entire mchine with δ from the trnsition tle ove. M = {A, B, C, D, E, F, G, H, I}, {, }, δ, A, {F, G, H, I} And the pretty picture, with no minimiztion... 7
d. Define new set of ccepting sttes tht will mke the DFA ccept strings in the lnguge L 1 L 2. Explin riefly the difference etween this new set of ccepting sttes nd the set defined in prt c. of this question. The set of ccepting sttes for the union of two DFAs is simply the set of ll sttes in the union which contin one of the ccepting sttes from the originl mchines. Formlly this is denoted F = {F 1 Q 2 Q 1 F 2 } For the intersection of two DFAs we wnt the ccepting sttes to e those sttes which include ccepting sttes from oth mchines. Formlly this would e F = {F 1 F 2 } In the cse of this specific prolem the new set of ccepting sttes would e F = {I}. Question 4. [25 pts; 7 pts; 18 pts.]. Descrie the lnguge ccepted y the following NFA: 8
This NFA ccepts ll strings over {, } tht egin with nd end with. This cn e descried y the regulr expression ( + ).. Prove tht this NFA ccepts the lnguge tht you descried in prt (). In your proof, use induction on the length of the input. Be sure to stte your induction hypothesis explicitly. Hint: You will use wht Hopcroft et l. cll mutul induction ( 1.4.4) (end of hint). We will complete this proof using mutul induction, where set of conditions is creted to descrie the ction of the mchine. This set of conditions will demonstrte tht the mchine ehves s descried ove. First, the three conditions. () q0 ˆδ(q0, w) w = ε. () q1 ˆδ(q0, w) w egins with (c) q2 ˆδ(q0, w) w egins with nd ends with Our tsk is to verify tht these conditions hold for ll input nd tht the pproprite input leds to cceptnce. Bse Cse For w = 0, we know the only string with mgnitude 0 is ε, so w = ε. () Becuse q0 is the initil stte of the mchine, nd there re no ε-trnsitions from q0, then q0 ˆδ(q0, w) so the left hnd side holds. Since w = ε, the right hnd side holds s well nd the iconditionl is true. 9
() Since there re no ε-trnsitions from the initil stte to q1, it follows tht q1 ˆδ(q0, w) nd the left hnd side is flse. It is cler tht w does not strt with nd so the right hnd side is flse s well. Therefore the iconditionl is true. (c) By the sme resoning s (), it follows tht condition (c) is lso true. Inductive Hypothesis Assume tht for w = n, ll three conditions hold. Inductive Step We now prove tht the three conditions hold for w = n + 1. Let w = xz where x = n nd z Σ. Thus w = x + 1 = n + 1. () There re no trnsitions into q0, so for ny w such tht w 1, q0 / ˆδ(q0, w) nd the left hnd side is flse. Since clerly w ε, the right hnd side is lso flse nd the iconditionl is true. () Consider the prefix string x. By the inductive hypothesis, ll the conditions hold for x, which mens tht condition () holds for x. This mens there re two cses to consider. The first, x strts with, mens tht q1 ˆδ(q0, x). Since there is trnsition from q1 to q1 on oth or, it does not mtter wht symol z is, it follows tht q1 ˆδ(q0, w). In this cse, no mtter wht z is, x will still strt with nd thus w will strt with. Thus the iconditionl will lwys e true. The second cse, x strts with, mens tht q1 / ˆδ(q0, x). Further, ecuse there is no trnsition out of q0 on, the mchine is stuck. Thus is does not mtter wht symol z is, it will lwys e the cse tht q1 / ˆδ(q0, w). Since x strts with it follows tht no mtter wht z is, w will lso strt with. Thus oth sides of the iconditionl will lwys e flse nd the iconditionl itself will lwys e true. (c) The only trnsition into q2 is on from q1. So ny cse which does not ensure q1 ˆδ(q0, x) implies tht q2 / ˆδ(q0, w) nd from condition () we know tht if x does not strt with then q1 / ˆδ(q0, x) nd it follows tht q2 / ˆδ(q0, w). Thus in this sitution, the iconditionl will lwys e true. Now consider the sitution where q1 ˆδ(q0, x). By the inductive hypothesis nd (), we know this implies tht x strts with. Here we hve two cses: z = nd z =. In the first cse, z =, it follows tht w ends with, nd not. Since there is no trnsition from q1 to q2 on n, then we cn conclude tht q2 / ˆδ(q0, w). Likewise, if q2 / ˆδ(q0, w) then we cn surmise tht the trnsition from q1 to q2 on ws not tken nd therefore, w does not end in. Thus the iconditionl is true in oth directions. In the second cse, z =, it follows tht w ends in. Since we know q1 ˆδ(q0, x) nd there is trnsition from q1 to q2 on, it follows tht q2 ˆδ(q0, w). Likewise, if q2 ˆδ(q0, w), since the only trnsition into q2 is from q1 on, then it follows tht w ends with. Agin the iconditionl is true in oth directions. Since in condition (c), it is required to pss through q1 to get to q2, nd q2 is the only ccepting stte of the mchine, it follows tht q1 ˆδ(q0, x) is necessry for cceptnce, 10
nd thus w must strt with. Agin, y condition (c), for q2 ˆδ(q0, w) to e true, then w must end with. Thus we show tht cceptnce y this mchine only occurs for strings tht strt with nd end with. I don t hold tht this proof is completely ullet-proof. If there re ny holes, plese feel free to point them out, nd I ll mke corrections. It is tricky there re lot of cses to consider ll the wy through. But hopefully, this proof illustrtes the process resonly well. 11