views:

1389

answers:

3

I have a set of 2D points and need to find the fastest way to figure out which pair of points has the shortest distance in the set.

What is the optimal way to do this? My approach is to sort them with quicksort and then calculate the distances. This would be O(nlogn + n) = O(nlogn).

Is it possible to do it in linear time?

Thanks.

A: 

No. Minimum distance among ALL points in O( n ^ 2 ) because you must compare every point against every other point. Technically it's n * n / 2 because you only have to fill have to fill half the matrix.

There are faster algorithms are for finding the nearest neighbor to a given point. Unfortunately, you have to then do this for every point to find the closest two points.

S.Lott
The diagram isn't an algorithm. The Fortune Algorithm produces the diagram. http://en.wikipedia.org/wiki/Fortune%27s_algorithm. I'm not sure this applies, since it partitions space rather than compares points.
S.Lott
+6  A: 

it is actually http://en.wikipedia.org/wiki/Closest_pair_problem

leiz
A: 

If you could probe out a constant amount from each point and use iterative deepening DFS, youd never check further apart than the two closest points...and since you're not dependent on a failed pass, you'd never need to recompute the way ID DFS tends to.

max