Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Singapore-MIT Alliance Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson November 21, 2001 6.046J/18.410J SMA5503 Handout 29 Problem Set 9
MIT students: This problem set is due in lecture on Wednesday, November 21. SMA students: This problem set is due after recitation on Friday, November 23. Reading: Chapters 22 and 24. 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 by the exercises. Mark the top of each sheet with your name, the course number, the problem number, your recitation instructor and time, the date, and the names of any students with whom you collaborated. MIT students: Each problem should be done on a separate sheet (or sheets) of three-hole punched paper. SMA students: Each problem should be done on a separate sheet (or sheets) of two-hole punched paper. You will often be called upon to “give an algorithm” to solve a certain problem. Your write-up 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 your 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. Graders will be instructed to take off points for convoluted and obtuse descriptions. Exercise 9-1. Do exercise 22.2-7 on page 539 of CLRS. Exercise 9-2. Do exercise 22.3-12 on page 549 of CLRS. Exercise 9-3. Do exercise 22.4-3 on page 552 of CLRS. 2 Exercise 9-4. Do exercise 24.1-4 on page 591 of CLRS. Exercise 9-5. Do exercise 24.3-6 on page 600 of CLRS. Exercise 9-6. Do exercise 24.5-7 on page 614 of CLRS. Handout 29: Problem Set 9 Problem 9-1. Running in Boston To get in shape, you have decided to start running to work. You want a route that goes entirely uphill and then entirely downhill so that you can work up a sweat going uphill and then get a nice breeze at the end of your run as you run faster downhill. Your run will start at home and end at work and you have a map detailing the roads with road segments (any existing road between two intersections) and intersections. Each road segment has a positive length, and each intersection has a distinct elevation. (a) Assuming that every road segment is either uphill or downhill, give an efﬁcient algorithm to ﬁnd the shortest route that meets your speciﬁcations. (b) Give an efﬁcient algorithm to solve the problem if some roads may be level (i.e., both intersections at the end of the road segments are at the same elevation) and therefore can be taken at any point. Let be a directed graph with weight function the mean weight of a cycle of edges in , and let to be Let , where ranges over all directed cycles in . A cycle for which is called a minimum mean-weight cycle. This problem investigates an efﬁcient algorithm for computing . Assume without loss of generality that every vertex is reachable from a source vertex . Let be the weight of a shortest path from to , and let be the weight of a shortest path from to consisting of exactly edges. If there is no path from to with exactly edges, then . (b) Show that if , then for all vertices . (Hint: Use both properties from part (a).)
¡ ) i Y © b e8 Dd
Y © b u d x0vWQ87suw tsq ¥ ¥ ` § aY (a) Show that if , then contains no negative-weight cycles and for all vertices . I£ P@ X % ¥ @ ` § cb £ p Y © b ¥ d D !! $#§"£ ¡ Problem 9-2. Karp’s minimum mean-weight cycle algorithm % Yb Y © b e8 d ¥ ¢ 5 F H(¥ Yb ` § aY ) G EF 8 D£ BCA % ¥ @ 98 555©2 ) & 33(7©63343(1©0¨('£ % D ¢ i y£ I @ Y © b e8 d x0v7sWtsrUTSQ ¥ )wu 8 q R i £ I@ gY £ ¥ hA bY © b f8 d Y© b¥ d I@ % ¥ @ WUTS¤£ P@ VRQ I % ` § Y ¡ ©¥£ ¨§¦¤¢ . We deﬁne Handout 29: Problem Set 9
(c) Let be a -weight cycle, and let and be any two vertices on . Suppose that the weight of the path from to along the cycle is . Prove that . (Hint: The weight of the path from to along the cycle is .) (d) Show that if such that , then there exists a vertex 3 on the minimum mean-weight cycle (Hint: Show that a shortest path to any vertex on the minimum mean-weight cycle can be extended along the cycle to make a shortest path to the next vertex on the cycle.) (e) Show that if , then (f) Show that if we add a constant to the weight of each edge of by . Use this to show that (g) Give an -time algorithm to compute . © b ¥ d Y © b ¥ d
, then I@ I@
¡ ) 5 Y © b e8 Dd Y © b u d x0vWQ87suw tsq fT3R e£ I @ Q ¥
¥ d ¢
¡ ) 5i £ Y © b e8 Dd Y © b u d x0vWQ87suw tsq UT3SR Q ¥
¥ 5£ Y © b ¥f8 Dd i Y
¡ x0v7sWtsq )wu 8
Y © b xu d Q ¥ Y Y Y i £ I @ i y£ I @ ich§¥ g i % is increased d ...
View Full Document
This note was uploaded on 01/01/2011 for the course CS 5503 taught by Professor Charlese.leiserson during the Spring '01 term at MIT.
- Spring '01