The challenge here is to find the set of all integer points that give the minimum sum over all Manhattan distances from a given set of points!
For example:
has a given set of points {P1, P2, P3 ... Pn}
The main problem is to find a point, say, X, which would have a minimal sum at all distances from the points {P1, P2, P3 ... Pn}.
i.e. | P1-X | + | P2-X | + .... + | Pn-X | = D, where D will be minimal over all X.
Moving a step further, there may be more than one value of X satisfying the above condition. that is, there may be more than one X that would give the same value of D. So, we need to find all such X.
One basic approach that anyone can think of is to find median information and then brute force, the coordinates mentioned in this post
But the problem with this approach is this: if the median gives two values โโthat are very different, then we end up with a rough coercion of all points that will never be executed at a given time.
So, is there any other approach that will give a result, even if the points are very far apart (where the median gives a range that is of the order of 10 ^ 9).
optimization algorithm
Login test
source share