CS 311 Homework 5 Solutions due 16:40, Thursdy, 28 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [30 pts.; 15 pts. ech] Prove tht the following lnguges re not regulr using the pumping lemm.. L = {0 n 1 m 0 n m, n 0}. To prove tht L is not regulr lnguge, we will use proof y contrdiction. Assume tht L is regulr. Then y the Pumping Lemm for Regulr Lnguges, there exists pumping length, p for L such tht for ny string s L where s p, s = xyz suject to the following conditions: () y > 0 () xy p, nd (c) i > 0, xy i z L. Choose s = 0 p 10 p. Clerly, s p nd s L. By condition () ove, it follows tht x nd y re composed only of zeros. By condition (), it follows tht y = 0 k for some k > 0. Per (c), we cn tke i = 0 nd the resulting string will still e in L. Thus, xy 0 z should e in L. xy 0 z = xz = 0 (p k) 10 p. But, this is clerly not in L. This is contrdiction with the pumping lemm. Therefore our ssumption tht L is regulr is incorrect, nd L is not regulr lnguge.. L = {wtw w, t {0, 1} + }. To prove tht L is not regulr lnguge, we will use proof y contrdiction. Assume tht L is regulr lnguge. Then y the Pumping Lemm for Regulr Lnguges, there exists pumping length p for L such tht for ny sring s L where s p, s = xyz suject to the following conditions: () y > 0 () xy p, nd (c) i > 0, xy i z L. 1
Choose s = 0 p 110 p 1. Clerly s L with w = 0 p 1 nd t = 1, nd s p. By condition (), it is ovious tht xy is composed only of zeros, nd further, y () nd (), it follows tht y = 0 k for some k > 0. By condition (c), we cn tke ny i nd xy i z will e in L. Tking i = 2, then xy 2 z L. xy 2 z = xyyz = 0 (p+k) 110 p 1. There is no wy tht this string cn e divided into wtw s required to e in L, thus xy 2 z / L. This is contrdiction with condition (c) of the pumping lemm. Therefore the ssumption tht L is regulr lnguge is incorrect nd thus L is not regulr lnguge. Question 2. [20 pts] Convert the following DFA into regulr expression using stte elimintion. Be sure to show intermedite steps of the process. q0 q1 First we introduce new strt nd finl stte, with ε trnsitions to nd from the originl strt nd finl sttes. S ε q0 q1 ε F 2
Now we remove stte, nd reconnect stte q1 to q0, including the regulr expression for the pth through long with the originl pth from q1 to q0. Now remove q1, dding the regulr expression for the pth through q1 to the self-loop on q0. Finlly, remove stte q0, connecting the strt nd finl stte with the regulr expression for the self-loop on q0. This regulr expression represents ll the strings tht this NFA ccepts. Question 3. [20 pts.; 10 pts. ech] Write context free grmmrs tht generte the following lnguges. In ech cse use the lphet Σ = {0, 1}.. {x#y x y }. 3
To construct this grmmr, we will uild lnced string of ritrry length, nd then force the genertion to choose etween pth tht forces either the left or the right side to e ritrrily longer thn the other side. S XSX XL RX L # XL R # RX X 0 1. {w w contins t lest two occurences of the sustring 101} This lnguge is strightforwrd. Force the inclusion of two occurences of the sustring 101 right in the first rule. Then llow ritrry other sustrings to e plced in ll other positions. S A101A101A A AA 0 1 ε Question 4. [30 pts; 15 pts. ech] Construct PDAs tht recognize the following lnguges:. L = { i j i > j} This mchine will count the numer of s y pushing them on the stck. Then it will strt compring s from the input with s on the stck. When ll the s re consumed, then the mchine will drin the stck nd ccept if there re still s on the stck. So long s there re s on the stck, then the string of s must e shorter. 4
. L = {xcy x, y {, } nd x y R } This mchine will push everything onto the stck until it reds the c. Then it will ttempt to mtch the stck ginst the input, consuming input so long s it mtches. The mchine will ccept if it sees one set of mis-mtched chrcters, or if either prt is longer thn the other. In ll other cses, the mchine will get stuck without ccepting. q4 ε, $ ; ε, ε ; ε ε, ; ε ε, ; ε q3, ; ε, ; ε, ε ; ε, ε ; ε ε, ; ε ε, ; ε 5