This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Theory of Computation — CSE 105
Contextfree Languages Study Guide and Homework 2 Homework 2: Solutions to the following problems should be turned in class on July 21, 1999. Instructions: Write your answers clearly and completely. Please use 8.5 11 inches paper. Use a stapler or a clip to attach the individual pages. Write your name. When presenting any construction, for example, an algorithm or an automaton, please give an overview of the main ideas and then present the construction. Always support the correctness of your construction with a short informal proof. Problems: 1. Show that and , , each is contextfree. 2. Let language (CFL). and . Show that 4. Use the pumping lemma to show that the language , each and for some , is not contextfree. 1 8 F C§ B X £ A § £0 &Th"g§# Df# e¨dc¢ $ ! § © §¥ £ a b` £ ` 98 6 5¥ @¨7U2 ` 3. Construct a PDA for the language of all nonpalindromes over palindrome over is any string such that . 8 65 ¨7¥ 98 6 5¥ 2 0 @7431§ is a contextfree . A ¡ ¢ 8Y§ 9 %¨WUTSQ¨R#PIHG¢ Q X£ 8(6V¥ 2 6 §" Q §¥ £ 8 1DC§ B A EF § £ 0 ( & $" ! § § © §¥ £ )'%# ¨¦¤¢ 876 5 1¥ 9876 5¥ 2 0 @Up§ i and for some Study Guide: 1 Basics of Contextfree Grammars To practice writing derivations and parse trees, try problems 2.1 and 2.3 on pages 119/120. 2 Contextfree Grammars and Ambiguity The following problems will give you practice in designing contextfree grammars. They also cover ambiguity of grammars and normal forms. 1. 2.4, page 120 2. 2.6, page 120 3. 2.8, page 120 4. 2.9, page 120 5. 2.13, page 120 6. 2.14, page 120 7. 2.21, page 122 8. 2.25, page 122 9. 2.26, page 122 10. 2.27, page 122 11. In each case, describe the language generated by the contextfree grammar with the productions. (a) (b) (c) (d) u " q 7 q "7 q 5 u "t7 "P5 tyw 7 Px5 "7 "5 w 5 "7 w w 7 tx5 v t7 q 7 C5 q 5 " " 7 P5 t7 q 7 C5 q 5 "" " u t7 q 7 C5 q 5 " " r sq r w r rsqv rsq r sq (e) (f) 12. Find contextfree grammars for each of the following languages (a) (b) (c) (d) (e) (f) (g) (h) or or 13. Find a deterministic ﬁnite automaton for the following language generated by a contextfree grammar. 14. For each of the following contextfree grammars , ﬁnd an equivalent CFG in Chomsky normal form that generates the the language . (a) (b) 3 Pushdown Automata The following problems give you practice in dealing with pushdown automata. 1. Problem 2.5, page 120 2. problem 2.7, page 120 3. Problem 2.10, page 121 4. Problem 2.11, page 121 5. Problem 2.12, page 121 8u ¥ ¢ 7" qqq r x5 C5 " 33sq 8 $ A 8 $£ B 8$ 8$ 8$ 8 $ i 8 A% B 5 B i A " F 7 F 5¥ B8 A " F 7 F 5¥
BA " ! F 7 0 ¥ 5 A £ B " ! F 7 0 ¥ 5 A B X £ " ! F 7 0 ¥ 5 X £ AB " ! F 7 0 ¥ 5 A B £ £ A "" ! FF 77 0 ¥¥ ! 05 qq r 5 t7 q " q "7 3rsq " 5 " q "7 q 5 sq q r 3q sq u " q q r u " 3q " 3sq 6. Write a pushdown automaton for each of the following languages. (a) The language of all oddlength palindromes over (b) The language of all nonpalindromes over (c) The language . and 7. Write a deterministic pushdown automaton for each of the following languages. (a) (b) (c) 4 Closure Operations and Noncontextfree Languages
1. Problem 2.2, page 120 2. Problem 2.15, page 121 3. Problem 2.17, page 121 4. Problem 2.18, page 121 5. Show in each case, using the pumping lemma, that the given language is not a CFL (a) (b) (c) 6. Decide in each case whether the language is a CFL. Prove your answer. (a) (b) (c) (d) are the number of ’s and ’s in where respectively. n§#g l 8 65 71¥
. . 8 " Yg f§ " I7j'i§Whg feW¥ k8 65¥ 2 V & " § d5 8 65 71¥ n§#g § 7 5 o 8 §nl#g i
n§#g
n§mg {I¦)¨
¢ o l "k876 5¥ 2 §¥ £ 8( " "6k8 65¥ 2 6 " §Q§¥ £ %u&W§ II7jTSQp§ x1¨x4¢ 8CQ "G{"§ I6 k 71sTSQp§ tW¨x4¢ " £ " 8 65¥ 2 6 "7Q5§¥ £ 8V & 6 " z7 5 7 z5¥ £ x¤sSU} PhhW{x4¢ 8 xV¤&wvgut UWRCr@gW¥ 6 " s5 s q d7 d5 8V & x¤p "g d 7 d ¥ 5 8 n§#D£ n§xmg f¨¥ o g l " § 8 ~} hW{x4¢ £ " 7 z5¥ £ 8x¤wg mWg 7 d 5 ¥ £ V & " d5 d xx4¢ 8 $
B
y " ! ¨F 7 0 x4¢ 5¥ £
, and ...
View
Full
Document
 Summer '99
 Paturi

Click to edit the document details