Answer Key
University:
Massachusetts Institute of TechnologyCourse:
6.046J | Introduction to Algorithms (SMA 5503)Academic year:
2022
Views:
135
Pages:
16
Author:
laubencs
p � wi (pi − p)� Handout 12: Problem Set 2 Solutions 15 Note that if p = pk for some k, then that point does not contribute to the cost. This cost function is continuous because limp�x c(p) = c(x) for all x. To find the minima of this function, we take the derivative with respect to p: � � � � dc ⎞ � � ⎞ � � wi wi − = dp pi
p Note that this derivative is undefined where p = pi for some i because the left- and dc right-hand limits of c(p) differ. Note also that dp is a non-decreasing function because dc as p increases, the number of points pi < p cannot decrease. Note that dp < 0 for dc p < min(p1 , p2 , . . . , pn ) and dp > 0 for p > max(p1 , p2 , . . . , pn ). Therefore there is dc dc some point p� such that dp � 0 for points p < p� and dp � 0 for points p > p� , and this point is a global minimum. We show that the weighted median y is such a point. For all points p < y where p is not the weighted median and p ∈= pi for some i, � wi < pi
p dc < 0. Similarly, for points p > y where p is not the weighted This implies that dp median and p ∈= pi for some i, � pi
� wi pi >p dc This implies that dp > 0. For the cases where p = pi for some i and p = ∈ y, both dc the left- and right-hand limits of dp always have the same sign so the same argument applies. Therefore c(p) > c(y) for all p that are not the weighted median, so the weighted median y is a global minimum. (e) Find the best solution for the two-dimensional post-office location problem, in which the points are (x, y) coordinate pairs and the distance between points a = (x 1 , y1 ) and b = (x2 , y2 ) is the Manhattan distance given by d(a, b) = |x1 − x2 | + |y1 − y2 |. Solution: Solving the 2-dimensional post-office location problem using Manhattan distance is equivalent to solving the one-dimensional post-office location problem separately for each dimension. Let the solution be p = (px , py ). Notice that using Manhattan dis tance we can write the cost function as the sum of two one-dimensional post-office location cost functions as follows: g(p) = � n � i=1 � wi |xi − px | + � n � i=1 wi |yi − py | � 16 Handout 12: Problem Set 2 Solutions �g Notice also that �p does not depend on the y coordinates of the input points and has x dc from the previous part using only the x coordinates as exactly the same form as dp �g input. Similarly, �px depends only on the y coordinate. Therefore to minimize g(p), we can minimize the cost for the two dimensions independently. The optimal solution to the two dimensional problem is to let px be the solution to the one-dimensional post-office location problem for inputs x1 , x2 , . . . , xn , and py be the solution to the one-dimensional post-office location problem for inputs y1 , y2 , . . . , yn .
Introduction to Algorithms (SMA 5503), Problem Set 2 Solutions
Get your assignment done in just 3 hours. Quick, easy, and available 24/7.
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Enter your email below and get instant access to your document