I am trying to solve following optimisation problem. Given N 2D points in format (x,y). We need to draw N-1 lines with slope either 1 or -1 , such that the maximum distance to any point is minimised.
I understand that in case when any two or more points lie on a line with slope -1 or 1 answer will be 0 as all points can lie on one of the lines. However when there no two points are on any line with slope -1 or 1, what will be the solution.
MY SOLUTION: find the half of minimum distance between parallel lines passing through points with slopes -1 or 1.
Reasoning: draw N-2 lines on points with farthest pairs except the last one and then draw N-1'th line between closest pair.
However i came to know this is not optimal solution. Please help.
The following algorithm will produce a set of lines with slope $+1$ or $-1$ with the shortest maximum distance. I assume the given points have coordinates $(x_n,y_n)$ for $n=1,2,\ldots,N$. Maybe go to the explanation of the general idea of the algorithm first, if you have triouble understanding what's going on.
The points $a$ and $b$ are the best candidates for 2 points that need to be 'covered' by one line of slope $-1$. If $s_a=s_b$, those points actually are on the same such line. If $s_a \neq s_b$, they were chosen such that the line with slope $-1$ through $(\frac{x_a+x_b}2, \frac{y_a+y_b}2)$ is the optimal line with slope $-1$ that covers any 2 points from the set with minmal maximal distance.
The same is true for points $e$ and $f$ with respect to lines with slope $+1$. They are the best pair of points to be covered by one line of slope $+1$, through point $(\frac{x_e+x_f}2, \frac{y_e+y_f}2)$.
To find out if to use a line of slope $+1$ or $-1$ to cover 2 different points, use the one that corresponds to the minumum of $|s_a-s_b|$ and $|d_e-d_f|$. If the minimum is $|s_a-s_b|$, use the line through $(\frac{x_a+x_b}2, \frac{y_a+y_b}2)$ with slope $-1$ to 'cover' points $a$ and $b$. If the minimum is $|d_e-d_f|$, use the line through $(\frac{x_e+x_f}2, \frac{y_e+y_f}2)$ with slope $+1$ to 'cover' points $e$ and $f$. If $|s_a-s_b|=|d_e-d_f|$, either variant works.
Now use your remaning $N-2$ lines to cover the remaining $N-2$ points (by going through them).
The idea of the algorithm is that you need 1 line to 'cover' 2 different points. A line 'covers' a point if it is one with the smallest distance to that point. Then all the other points can be easily covered by lines going through them. Because there are only 2 possible slopes, we try to find the optimal one for each direction (steps 1-4; 5-6).
Lines with slope $-1$ are characterized by the fact that for each point $(x,y)$ on them, the value $x+y$ is constant and describes the line. The euclidean distance between a point $(u,v)$ and the line $x+y=s$ ($s$ being a constant) is
$$\frac{|(u+v)-s|}{\sqrt 2}$$
Because ${\sqrt 2}$ is a constant, we can ignore it when comparing those distances. In step 1 we calculate that sum value $s_n$ for each line of slope $-1$ going through point $n$. By ordering them in step 2, we find wich of those lines are near each other, and we find the smallest distance in step 3. Step 4 then translates those 2 points back into our original naming scheme.
Then we do the same for lines with slope $+1$, which are characterized by $x-y=d$, $d$ being constant. So we calculate the differences $d_n$ in step 5, and then repeat steps 2-4 accordingly, as described in step 6.
At the end we then have to find out which slope of the two has the best (minimal) maximal distance.