This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson September 7, 2005 6.046J/18.410J Handout 5 Problem Set 1
MIT students: This problem set is due in lecture on Wednesday, September 21, 2005. The homework lab for this problem set will be held 2–4 P. M . on Sunday, September 18, 2005. Reading: Chapters 1–4 excluding Section 4.4. Both exercises and problems should be solved, but only the problems should be turned in. Exercises are intended to help you master the course material. Even though you should not turn in the exercise solutions, you are responsible for material covered in the exercises. Mark the top of each sheet with your name, the course number, the problem number, your recitation section, the date and the names of any students with whom you collaborated. You will often be called upon to “give an algorithm” to solve a certain problem. Your writeup should take the form of a short essay. A topic paragraph should summarize the problem you are solving and what your results are. The body of the essay should provide the following: 1. A description of the algorithm in English and, if helpful, pseudocode. 2. At least one worked example or diagram to show more precisely how your algorithm works. 3. A proof (or indication) of the correctness of the algorithm. 4. An analysis of the running time of the algorithm. Remember, your goal is to communicate. Full credit will be given only to correct solutions which are described clearly. Convoluted and obtuse descriptions will receive low marks. Exercise 11. Do Exercise 2.36 on page 37 in CLRS. Exercise 12. Do Exercise 3.16 on page 50 in CLRS. Exercise 13. Do Exercise 3.24 on page 57 in CLRS. Exercise 14. Do Problem 4.34 on page 75 of CLRS. Problem 11. Asymptotic Notation For each of the following statements, decide whether it is always true, never true, or sometimes true for asymptotically nonnegative functions and . If it is always true or never true, explain why. If it is sometimes true, give one example for which it is true, and one for which it is false. ¡ 2 (a) (b) (c) (d) (e) Handout 5: Problem Set 1 and (note the little ) and Problem 12. Recurrences Give asymptotic upper and lower bounds for in each of the following recurrences. Assume that is constant for . Make your bounds as tight as possible, and justify your answers. Problem 13. Unimodal Search An array is unimodal if it consists of an increasing sequence followed by a decreasing sequence, or more precisely, if there is an index such that for all for all , and . In particular, is the maximum element, and it is the unique “locally maximum” element and ). surrounded by smaller elements ( (a) Give an algorithm to compute the maximum element of a unimodal input array in time. Prove the correctness of your algorithm, and prove the bound on its running time. A polygon is convex if all of its internal angles are less than (and none of the edges cross each other). Figure 1 shows an example. We represent a convex polygon as an array where each element of the array represents a vertex of the polygon in the form of a coordinate pair . We are told that is the vertex with the minimum coordinate and that the vertices are ordered counterclockwise, as in the ﬁgure. You may also assume that the coordinates of the vertices are all distinct, as are the coordinates of the vertices. 5
©I ¤ ¦ r0 p seq¢ ¤ k1
©I o ¤ k1
©I h o p ¤00 S0 s
BVI mQl ncRI I p ih I jy ¤hd G d fI G ih r I I g e I d e Eo ¤ 5
©I ¦ `Y¢ 4¤ a¥E F (j) F F F F (f) (g) (h) (i) F F F F F (a) (b) (c) (d) (e) A ¦¤ 4¥¢ F ¡ ¡ ¦1§¢E6D§¢ ¦ ¤ ¢ C¨ ¦ ¤ ¦ ¦ ¤ ¢ C¨ ¦ ¤ ¢ 5§¢ )§¥£ ¡ ¡ ¦ ¤ A ¦ ¤¢ 5¦4¥¢ ¢B6¨©§ ¦¦ ¤ ¢ 8 ¨ ¦ ¤¢ 1§¥¢ @9©§ ¦ ¤¢ ! ¦¦ ¤¢ ¢ ¦ ¤¢ 5¦4¥3¢76¨ 54¥32§§¥£ ¡ ¡ ¦¦¦ 0 ¤¢ ' $ ! ¦ ¤ ¦ ¤¢ 11§¤¥¢ ¦§¢)(%&¢#"¨ §¢ §§ ¦¦ ¤¢ ¢ ¨ ¦ ¤¢ §¥£©§¥£ F ¤QQI ¦ VVR§4¤ f ¢ ¤ f ©4¥¢ ¨¦¤ F F ¦4¥¢7h4Vc§c¢ §cc4¥¢ ©4¥¢ ¤ ! ¦bT¤x ¦bT¤ ¨¦¤ F ¤ ad§c2¥¢ ©4¥¢ `Y ¦ S y ¤ ¨¦¤ F ¦ ST¤ ¨¦¤ w xVQ w f §4¤ f vc4¥¢ ©§¢ F u¤ ¦ST¤ p ¨ ¦¤ Xd4cc4¥¢ 6©4¥¢ F tgs(q4cV§¢ Ri©§¢ r ¤pI ¦UT ¤ QI ¨ ¦ ¤ F ¦§¤©`a©a7h§§¤ g¢ ©4¥¢ Y `Y¢ ! ¦ f ¨¦¤ F eS ¦ST¤ (#§cc4¥¢ ©§¢ ¨¦¤ F ¤ ad4cc4¥¢ 9©4¥¢ `Y ¦ b T ¤ U ¨ ¦ ¤ F ¤ `Y ¤ ¦ U T ¤ S ¨ ¦ ¤ ©a)2XWV§¢ 6©§¢ QI G RPH¤ ¦¤ §¢ F Handout 5: Problem Set 1 3 (b) Give an algorithm to ﬁnd the vertex with the maximum coordinate in (c) Give an algorithm to ﬁnd the vertex with the maximum coordinate in ¦ `Y¢ §¤
¥ ¦ `Y¢ §¤
¥ o Figure 1: An example of a convex polygon represented by the array . with the minimum coordinate, and are ordered counterclockwise. I (
©I wu ft o wu vft r p wu ift wu
ft
is the vertex time. time. wu xft wu ~ft 5
©I &o wu yft wu }t wu 5{zft p ...
View
Full
Document
This note was uploaded on 02/01/2010 for the course COMPUTERSC 6.046J/18. taught by Professor Erikd.demaineandcharlese.leiserson during the Fall '05 term at MIT.
 Fall '05
 ErikD.DemaineandCharlesE.Leiserson

Click to edit the document details