The fastest way to find the minimum distance between points

I have a set of two-dimensional points and you need to find the fastest way to find out which pair of points has the shortest distance in the set.

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

Can this be done in linear time?

Thanks.

+3
source share
3 answers

This is actually :

- : n , ...

, , floor

+11

DFS, , ... , ID DFS.

-1

No. The minimum distance between all points in O (n ^ 2), because you have to compare each point with every other point. Technically, this is n * n / 2, because you only need to fill in half the matrix.

There are faster algorithms for finding the nearest neighbor at a given point. Unfortunately, you have to do this for each point in order to find the next two points.

-4
source

Source: https://habr.com/ru/post/1707101/


All Articles