找到点之间最小距离的最快方法

时间:2020-12-20 15:21:05

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.

我有一组2D点,需要找到最快的方法来确定哪一对点在集合中具有最短距离。

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).

这样做的最佳方法是什么?我的方法是使用quicksort对它们进行排序,然后计算距离。这将是O(nlogn + n)= O(nlogn)。

Is it possible to do it in linear time?

是否可以在线性时间内完成?

Thanks.

3 个解决方案

#1


It is actually:

它实际上是:

The closest pair of points problem or closest pair problem is a problem of computational geometry: given n points in metric space, find a pair of points with the smallest distance between them...

最近一对点问题或最近对问题是计算几何问题:给定度量空间中的n个点,找到它们之间距离最小的一对点...

In the computational model which assumes that the floor function is computable in constant time the problem can be solved in O(n log log n) time. If we allow randomization to be used together with the floor function, the problem can be solved in O(n) time..

在假设地板函数可以在恒定时间内计算的计算模型中,问题可以在O(n log log n)时间内解决。如果我们允许随机化与floor函数一起使用,那么问题可以在O(n)时间内解决。

#2


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.

如果你可以从每个点探测出一个恒定的数量并使用迭代加深DFS,那么你永远不会检查比最接近的两个点更远......并且由于你不依赖于失败的传球,你永远不需要重新计算方式ID DFS倾向于。

#3


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.

否。所有点之间的最小距离为O(n ^ 2),因为您必须将每个点与每个其他点进行比较。从技术上讲,它是n * n / 2,因为你只需要填充必须填充矩阵的一半。

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.

有更快的算法用于查找给定点的最近邻居。不幸的是,你必须为每一点做到这一点才能找到最接近的两点。

#1


It is actually:

它实际上是:

The closest pair of points problem or closest pair problem is a problem of computational geometry: given n points in metric space, find a pair of points with the smallest distance between them...

最近一对点问题或最近对问题是计算几何问题:给定度量空间中的n个点,找到它们之间距离最小的一对点...

In the computational model which assumes that the floor function is computable in constant time the problem can be solved in O(n log log n) time. If we allow randomization to be used together with the floor function, the problem can be solved in O(n) time..

在假设地板函数可以在恒定时间内计算的计算模型中,问题可以在O(n log log n)时间内解决。如果我们允许随机化与floor函数一起使用,那么问题可以在O(n)时间内解决。

#2


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.

如果你可以从每个点探测出一个恒定的数量并使用迭代加深DFS,那么你永远不会检查比最接近的两个点更远......并且由于你不依赖于失败的传球,你永远不需要重新计算方式ID DFS倾向于。

#3


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.

否。所有点之间的最小距离为O(n ^ 2),因为您必须将每个点与每个其他点进行比较。从技术上讲,它是n * n / 2,因为你只需要填充必须填充矩阵的一半。

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.

有更快的算法用于查找给定点的最近邻居。不幸的是,你必须为每一点做到这一点才能找到最接近的两点。