Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.

Similar presentations


Presentation on theme: "Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping."— Presentation transcript:

1 Homework #7 Solutions

2 #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping Lemma. Assume L is context-free. L is obviously infinite, since i, j > 0. Pick a string w in L with length |w| > m, for example, w = a m b m a m b m, j > 0. Then w = uvxyz with |vxy| 1 and uv i xy i z is also in L for all i > 0 The analyses to the right show that this language cannot be context-free because uv 2 xy 2 z is not in L. Case 7) vxy overlaps 2 nd a m and 2 nd b m : Same as #3 Case 6) vxy is within 2 nd b m : Same as #2 Case 5) vxy is within 2 nd a m : Same as #1 Case 4) vxy overlaps first b m and second a m : Similar logic to #3 3c) v is all a’s, y is all b’s: uv 2 xy 2 z = a m+|v| b m+|y| a m b m  L because either m+|v|  m, or m+|y|  m 3b) y itself straddles a’s and b’s: similar to #3a 3a) v itself straddles a’s and b’s: pumping v would produce strings of the form a…a(ab) i b…ba m b m which are not in L Case 3) vxy overlaps first a m and first b m uv 2 xy 2 z = a m b m+|v|+|y| a m b m  L … similar to #1 Case 2) vxy is within first b m uv 2 xy 2 z = a m+|v|+|y| b m a m b m  L because m+|v|+|y|  m because |vy| > 0 Case 1) vxy is within first a m

3 a)Show that each of these languages is context- free. G 1 S  AC|  A  aAbb|  C  cC|  L 1 : |b’s| = 2  |a’s| L 2 : |c’s| = 2  |b’s| So L 1  L 2 = { a n b 2n c 4n | n  0 } #2. Consider the following 2 languages: G 2 S  AB|  A  Aa|  B  bBcc| 

4 2b) Is L1∩ L2 context-free? Justify your answer. L 1 : |b’s| = 2  |a’s| L 2 : |c’s| = 2  |b’s| So L 1  L 2 = { a n b 2n c 4n | n  0 } Not context-free (easy use of pumping lemma.) Pick z = a m b 2m c 4m

5 #3. Convert the following grammar to Chomsky Normal Form S  A | A B a | A b A A  A a |  B  B b | BC C  C B | C A | b B 1. Eliminate  -productions: S  A | A B a | A b A | B a | b A | A b |  A  A a | a B  B b | BC C  C B | C A | b B | C

6 #3 cont. 2. Remove unit productions S  A a | a | A B a | A b A | B a | b A | A b |  A  A a | a B  B b | BC C  C B | C A | b B 3. a) Eliminate useless (non-generating) symbols and all productions involving one or more of those symbols. S  A a | a | A b A | b A | A b A  A a | a b) Eliminate unreachable symbols: None 4. Convert to CNF: S   A A 1 | A B |B 1 A | A B 1 A 1  a B  B 1 A B 1  b A  A A 1 | a

7 #4. Let G be a grammar in Chomsky Normal Form. Fill in the following table.  log n  + 1 n2n-1na1a2a3…ana1a2a3…an 4595 a1a2a3a4a5a1a2a3a4a5 3474 a1a2a3a4a1a2a3a4 3353 a1a2a3a1a2a3 2232 a1a2a1a2 1111 a1a1 11 10  min depth(tree) max depth (tree) Length (derivation) |w| w


Download ppt "Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping."

Similar presentations


Ads by Google