2.13 - CS 350 - Homework Solutions Chapter 2 Ex 2.1 (a) E )...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 350 - Homework Solutions Chapter 2 Ex 2.1 (a) E ) T )F )a E T F a (b) E ) E + T ) T + T )F +T )F +F )a+F )a+a E E T T F F a + a (c) E ) E + T ) E + T + T ) T + T + T ) F + T + T )F +F +T )F +F +F )a+F +F )a+a+F )a+a+a 1 E E T E T T F F F a +a + a (d) E ) T ) F ) (E ) ) (T ) ) (F ) ) ((E )) ) ((T )) ) ((F )) ) ((a)) E T F E T F E T F (( a )) Ex 2.2 (a) Note that A \ B = fanbncn : n 0g = C . But C is not a CFL by example 2.20. Thus CFL are not closed under intersection. (b) Suppose two CFLs L1 and L2 were closed under complementation. Then L1and L2 are CFLs also. Then L1 L2 is a CFL also, and so would (L1 L2 ) be a CFL. But by De 2 Morgan's Law, (L1 L2 ) = L1 \ L2 which is not always a CFL by part(a). Ex 2.4 (a) S ! 0S j1A A ! 0Aj1B B ! 0B j1F F ! 0F j1F j" The grammar is actually regular and derivable from the following dfa: 1 S A 1 B 1 F 0 r:e: = 0 10 10 1(0 + 1) 0 0 0,1 (b) S ! 0A0j1A1j0j1j" A ! 0Aj1Aj" The language is also regular, as evidenced by the following dfa: 1 0 0 1 0 1 0 1 1 0 r:e: = 0 + 1 + 0(0 + 1) 0 + 1(0 + 1) 1 + " (c) 3 S ! 0Aj1A A ! 0S j1S j" The language is also regular, as evidenced by the following dfa: 0,1 S 0,1 A r:e: = (0 + 1)((0 + 1)(0 + 1)) (d) S ! 0S 0j1S 1j0S 1j1S 0j0 (Note : this is an irregular language. Use Pumping Lemma with w = 1k 01k ). (e) S ! 1S j1AjAS ( at least one more 1) A ! AAj1A0j0A1j" ( equal ] 's of 1's, 0's) (This is an irregular language.) (f) S ! 0S 0j1S 1j0j1j" (This is an irregular language.) (g) R=fS ! 0S j1S g (This is a regular language.) Ex.2.5 (a) Since this is a regular language, the PDA will ignore its stack and behave like a dfa. The PDA will also be deterministic. R= or PDA Algorithm 1. state =S 4 2. repeat f read input if =1 then if state=S then state:=q1 else if state=q1 then state:=q2 else if state=q2 then state:=f guntil input is exhausted. 3. if state=f then accept else reject 0, ε ε 1,ε ε 0,ε q1 ε S 1,ε ε f 1,ε ε q2 0,ε 1,ε ε ε 0,ε ε PDA state diagram (b) This is also regular and is recognized by a dPDA that ignores its stack. 1. 2. while input 6= " do read input 5 PDA Algorithm read input rst := 3. if = rst then accept else reject The PDA diagram is similar to the dfa given in ex.2.4(b). All stack operations are of the form " ! ". (c) Similar to 2.4(c) (d)This is an irregular language and therefore requires the use of a stack to recognize it. Here is an informal description of the PDA which is nondeterministic. The PDA will push each input symbol onto the stack until , at some point, it will nondeterministically guess that it has read the middle symbol 0, at which time it will begin popping a stack symbol for each remaining input symbol. If it ends up with an empty stack after reading the last input symbol then it accepts. Otherwise, if it does not nd a 0 in the input string or guesses incorrectly about the middle 0 location, it rejects. (e) The stack, at any point in time, contains the excess of 1s or 0s read so far in the input. If a 0(1) is read rst, it is stacked. If a 0(1) is read and a 0(1) is on TOS, the 0(1) is stacked. If a 0(1) is read and TOS=1(0), the 1(0) is popped from the stack. At the end of the input reading, if TOS=1 then the PDA accepts after ushing the stack Otherwise ,it rejects. At the beginning of the computation, a BOS marker is pushed onto the stack. (f) The nPDA begins by pushing input symbols onto the stack, then at some point nondeterministically \guesses" the middle of the input and switches into \checking"mode, comparing each remaining input symbol, one by one, with each TOS symbol and popping TOS if they match. If there is a mismatch then this path of the nondet. computation tree rejects otherwise, if all symbols match and the stack empties after the last input symbol is read, the nPDA accepts. (g) The PDA accepts nothing. In e ect, it never enters a nal state. 0, ε PDA: ε 1,ε ε Ex 2.6 (a) cfg G: S ! SS jbSaajabSajaSbajaaSbj" 6 (b)Note that L = P ;L L = fambn : m 6= ng b(a + b) =L1 L2 L3 fanbn : n 1g fa bg + Now we nd grammars generating L1 L2 , and L3 : G1: S1 ! S2jS3 S2 ! aS2bjS2 bjb S3 ! aS3bjaS3 ja G2: S4 ! bA A ! aAjbAj" G3 : S5 ! S6S7 S6 ! aS6bjab S7 ! ajbjS7S7 Therefore, grammar for L is G: S ! S1 jS4jS5 Note that another way to do this is to construct the pda M for L, then convert M to pda M' for L' by interchanging Q and F. However, this involves much more work, and includes deriving the cfg from M! Ex.2.13 (a) L(G) = f0i]0j ]0k i j k 0g f0n]02n n 0g = L1 L2 where L1 is generated by S ! TT rule, and L2 is generated by S ! U rule. (b)L1 is regular since it can be described by the regular expression 0 ]0 ]0 : However, L2 is irregular. An easy application of the Pumping Lemma proves this. Let w = 0k ]02k where k = jQj for dfa M for L2 with state set Q. Now w = xyz = 0k ]02k :. So, jxyj k ) y = 0r r > 0 since y 6= ", But xynz 2 L ) xy2z 2 L: However, xy2z = 0p(0r )20q ]02k ) p + 2r + q = k, which is false since p+r+q=k. G: Ex.2.14 A ! BAB jB j" B ! 00j" (1) =) S0 ! A 7 A ! BAB jB j" B ! 00j" (2) =) S0 ! "jA A ! BAB jB jBB B ! 00 (3) =) S0 ! "jBAB j00jBB A ! BAB j00jBB B ! 00 (4) =) G': S0 ! "jBC jDDjBB C ! AB A ! BC jDDjBB B ! DD D!0 L(G) = L(G0) = f00g Ex 2.25 L(G)=fa bg+ L(G) = " Therefore, grammar is S! " 8 ...
View Full Document

Ask a homework question - tutors are online