Finding point, which distances sum to all other points on the line is the lowest

algorithm, line, recursion

Solution

This is called the median value. Just sort the values and select the center. If n is even, any of the two center values will do.

There are also O(n) algorithms for calculating the median.

Problem

I've been wondering if it's possible to solve this problem in recursive or "divide and conquer" way. Here is visualisation of my problem: ``` Input: 22 // point no 1 35 // point no 2 5 // ... 44 45 20 46 Output: 2 // point with number 2 has got the lowest sum (87) ``` I know how to do this in an iterative way, but I'm thinking about something more optimal.

Original source