Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let x1< x2 < . . . < xn be real numbers representing coordinates of n villages l

ID: 3563059 • Letter: L

Question

Let x1< x2 < . . . < xn be real numbers representing coordinates of n villages located along a straight road. A post office needs to be built in one of these villages.

a. Design an efficient algorithm to find the post-office location minimizing the average distance between the villages and the post office.

b. Design an efficient algorithm to find the post-office location minimizing the maximum distance from a village to the post office.

In addition to the efficient algorithm, also describe the brute-force approach and derive the asymptotic efficiencies of each algorithm.

I am aware that by simply copying and pasting this question, you can find a solution. However I'd like to see this worked out more in depth by hand or explained slighty differently. Thank you

Explanation / Answer

a. If we put the post office at location xi, the average distance between it
and all the points x1 < x2 < ... < xn is given by the formula 1
n
n
j=1 |xj ?
xi|. Since the number of points n stays the same, we can ignore the multiple
1
n and minimize n
j=1 |xj ? xi|. We