Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology SingaporeMIT Alliance Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson Day 32 6.046J/18.410J SMA5503 Handout 29 Problem Set 9
MIT students: This problem set is due in lecture on Day 32. 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 threehole punched paper. 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 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 91. Do exercise 22.27 on page 539 of CLRS. Exercise 92. Do exercise 22.312 on page 549 of CLRS. Exercise 93. Do exercise 22.43 on page 552 of CLRS. 2 Exercise 94. Do exercise 24.14 on page 591 of CLRS. Exercise 95. Do exercise 24.36 on page 600 of CLRS. Exercise 96. Do exercise 24.57 on page 614 of CLRS. Handout 29: Problem Set 9 Problem 91. 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 efficient algorithm to find the shortest route that meets your specifications. (b) Give an efficient 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 meanweight cycle. This problem investigates an efficient 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 negativeweight cycles and for all vertices . I P@ X % @ ` cb p Y b d D ! ! $#" Problem 92. Karp's minimum meanweight cycle algorithm % Y b Y b e8 d 5 F H( Y b ` aY ) G EF 8 D BCA % @ 98 5552 ) & 33(763343(10(' % 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 define 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 meanweight cycle (Hint: Show that a shortest path to any vertex on the minimum meanweight 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
 Fall '04
 PiotrIndykandCharlesE.Leiserson
 Algorithms

Click to edit the document details