0

I am looking at the wikipedia entry for how to solve this. It lists five steps

1.Sort points along the x-coordinate

2.Split the set of points into two equal-sized subsets by a vertical line x = xmid

3.Solve the problem recursively in the left and right subsets. This will give the left-side and right-side minimal distances dLmin and dRmin respectively.

4.Find the minimal distance dLRmin among the pair of points in which one point lies on the left of the dividing vertical and the second point lies to the right.

5.The final answer is the minimum among dLmin, dRmin, and dLRmin.

The fourth step I am having trouble understanding. How do I choose what point to the left of the line to compare to a point right of the line. I know I am not supposed to compare all points, but I am unclear about how to choose points to compare. Please do not send me a link, I have searched, gone to numerous links, and have not found an explanation that helps me understand step 4.

Thanks

Aaron

David Hall
  • 32,624
  • 10
  • 90
  • 127
Aaron
  • 4,380
  • 19
  • 85
  • 141

1 Answers1

2

The answer to your question was in the next paragraph of the wikipedia article:

It turns out that step 4 may be accomplished in linear time. Again, a naive approach would require the calculation of distances for all left-right pairs, i.e., in quadratic time. The key observation is based on the following sparsity property of the point set. We already know that the closest pair of points is no further apart than dist = min(dLmin,dRmin). Therefore for each point p of the left of the dividing line we have to compare the distances to the points that lie in the rectangle of dimensions (dist, 2 * dist) to the right of the dividing line, as shown in the figure. And what is more, this rectangle can contain at most 6 points with pairwise distances at least dRmin. Therefore it is sufficient to compute at most 6n left-right distances in step 4. The recurrence relation for the number of steps can be written as T(n) = 2T(n / 2) + O(n), which we can solve using the master theorem to get O(n log n).

I don't think I can put it much clearer than they already have, but do you have any specific questions about this step of the algorithm?

David Hall
  • 32,624
  • 10
  • 90
  • 127
  • What I am having trouble with is the rectangle of dimensions. Does this mean if I have three points to the left of the line I and three points in the right of the line I need to find the distance for all pairs of left right and then compare them to the distance of the the shortest pair on the right and left? – Aaron Apr 24 '11 at 23:48
  • That is stating that because we know that we don't need to consider point pairs greater than the minimum of dLmin, dRmin, we can eliminate a certain set of the right hand points. That set is points lying outside the (dist, 2*dist) rectangle to the right of the dividing line (where the rectangle is centered on each left point). Basic geometry shows that any points out side that rectangle must be greater than dist away from the left point. In fact, there are points inside the rectangle that are also not candidates, but I think calculating a more accurate exclusion area and whether a point is... – David Hall Apr 24 '11 at 23:54
  • within it would be more computationally expensive than just using the "close enough" rectangle approximation. – David Hall Apr 24 '11 at 23:55
  • So every point to the left has a rectangle that the point is centered in. All point in the recangle on the right side need to have the distance between the two points found, is that correct? Is the distance of the square that shortest distance on the left side for x and 2*shortest distance for the y? Is that what (dist, 2*dist) is? – Aaron Apr 25 '11 at 00:09
  • No. The rectangle's left hand side lies on the x-y dividing line. The rectange then extends dist into the right hand side. The rectangle's y centre is the y coordinate of the current left hand point being checked. The rectangles y length is 2*dist. But yes, you need to find the distance between all points in the rectangle on the right and the current left hand point. – David Hall Apr 25 '11 at 00:16
  • So if the shortest distance for point (2,5) is 4 so we would only check points on the right side if the distance was 4 or less for x and 8 or less for y? – Aaron Apr 25 '11 at 00:25
  • Say we have two left hand points (1,3) and (2,6) we then need to check within two rectangles. The first rectangle (if we take x as being at 3) goes from 3 to 7 (3+4) in the x and from 7 to -1 (left point y of 3 +- 4) in the y. The second rectangle goes from 3 to 7 in the x and 10 to 2 in the y (left point 6 +- 4). That is, the rectangle for each point on the left centers its y coordinates on the left points y coordinate. – David Hall Apr 25 '11 at 00:31
  • When you say 3 to 7 (3+4) where is the 4 coming from? I undestand how to get the y range but are you assuming that y is 4? (3+-4) 3 is the y coordinate but where does 4 come from? – Aaron Apr 25 '11 at 00:56
  • 4 is the shortest distance (min of dLmin and dRmin) – David Hall Apr 25 '11 at 00:59
  • got it, so for (1,3) the range of x is 1 to 5? – Aaron Apr 25 '11 at 01:04
  • @Aaron not sure what you meant by that last comment - the rectangle that relates to the point (1,3) when the min dist is 4 and the x centre line is a 3 is a rectangle that goes from 3 to 7 in the x (from the centre line at 3 and then plus 4 for the dist) and goes from -1 to 7 in the y (the points y coord plus 4 and minus 4). It sounds like you missed that all the rectangles have their left hand side on the centre line. – David Hall Apr 25 '11 at 01:08
  • why is the x at the centre line 3? – Aaron Apr 25 '11 at 01:18
  • Because in this hypothetical example, that is where we say it is. The centre line is the line you used to divide the left and right from each other. (the term in the original quote was dividing line) – David Hall Apr 25 '11 at 01:21
  • got it, so would we then compare all left points to all right points that are between 3 and and 7 and whatever the y is – Aaron Apr 25 '11 at 01:28
  • yes. Now, one thing I'm not 100% on in the algorithm is that I would think we only need compare left points that are less then dist (for us 4) away from the dividing line. Only those points can have a right point closer than dist. I think how that works is due to the recursive nature of the algorithm. But either way, what you are describing now matches the algorithm as written in the wikipedia article. – David Hall Apr 25 '11 at 01:32