Closest pair of points problem


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. The closest pair problem for points in the Euclidean plane was among the first geometric problems that were treated at the origins of the systematic study of the computational complexity of geometric algorithms.
A naive algorithm of finding distances between all pairs of points in a space of dimension d and selecting the minimum requires time. It turns out that the problem may be solved in time in a Euclidean space or Lp space of fixed dimension d. In the algebraic decision tree model of computation, the algorithm is optimal, by a reduction from the element uniqueness problem.
In the computational model that assumes that the floor function is computable in constant time the problem can be solved in time. If we allow randomization to be used together with the floor function, the problem can be solved in time.

Brute-force algorithm

The closest pair of points can be computed in O time by performing a brute-force search. To do that, one could compute the distances between all the pairs of points, then pick the pair with the smallest distance, as illustrated below.
minDist = infinity
for i = 1 to length - 1 do
for j = i + 1 to length do
let p = P, q = P
if dist < minDist then
minDist = dist
closestPair =
return closestPair

Planar case

The problem can be solved in time using the recursive divide and conquer approach, e.g., as follows:
  1. Sort points according to their x-coordinates.
  2. Split the set of points into two equal-sized subsets by a vertical line.
  3. Solve the problem recursively in the left and right subsets. This yields the left-side and right-side minimum distances and, respectively.
  4. Find the minimal distance among the set of pairs of points in which one point lies on the left of the dividing vertical and the other point lies to the right.
  5. The final answer is the minimum among,, and.
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. Therefore, for each point to the left of the dividing line we have to compare the distances to the points that lie in the rectangle of dimensions bordering the dividing line on the right side, as shown in the figure. And what is more, this rectangle can contain at most six points with pairwise distances at least. Therefore, it is sufficient to compute at most left-right distances in step 4. The recurrence relation for the number of steps can be written as, which we can solve using the master theorem for divide-and-conquer recurrences to get.
As the closest pair of points define an edge in the Delaunay triangulation, and correspond to two adjacent cells in the Voronoi diagram, the closest pair of points can be determined in linear time when we are given one of these two structures. Computing either the Delaunay triangulation or the Voronoi diagram takes time. These approaches are not efficient for dimension, while the divide-and-conquer algorithm can be generalized to take time for any constant value of, with exponential dependency in d.

Dynamic closest-pair problem

The dynamic version for the closest-pair problem is stated as follows:
If the bounding box for all points is known in advance and the constant-time floor function is available, then the expected O space data structure was suggested that supports expected-time O insertions and deletions and constant query time. When modified for the algebraic decision tree model, insertions and deletions would require O expected time. It is worth noting, though, that the complexity of the dynamic closest pair algorithm cited above is exponential in the dimension d, and therefore such an algorithm becomes less suitable for high-dimensional problems.
An algorithm for the dynamic closest-pair problem in d dimensional space was developed by Sergey Bespamyatnikh in 1998.
Points can be inserted and deleted in O time per point.