Closest Pair of Points Problem
Closest Pair of Points Problem
1 Brute-force algorithm
The closest pair of points can be computed in O(n2 ) time
by performing a brute-force search. To do that, one could
compute the distances between all the n(n 1) / 2 pairs
of points, then pick the pair with the smallest distance, as
illustrated below.
minDist = innity for i = 1 to length(P) - 1 for j = i + 1
to length(P) let p = P[i], q = P[j] if dist(p, q) < minDist:
minDist = dist(p, q) closestPair = (p, q) return closestPair
2 Planar case
The problem can be solved in O(n log n) time using the
recursive divide and conquer approach, e.g., as follows:[1]
1. Sort points according to their x-coordinates.
REFERENCES
4 See also
GIS
Nearest neighbor search
Set cover problem
5 Notes
[1] M. I. Shamos and D. Hoey. Closest-point problems.
In Proc. 16th Annual IEEE Symposium on Foundations
of Computer Science (FOCS), pp. 151162, 1975 (DOI
10.1109/SFCS.1975.8)
[2] S. Fortune and J.E. Hopcroft. A note on Rabins
nearest-neighbor algorithm. Information Processing Letters, 8(1), pp. 2023, 1979
[3] S. Khuller and Y. Matias. A simple randomized sieve
algorithm for the closest-pair problem. Inf. Comput.,
118(1):3437,1995
Divide-and-conquer: sparse box observation
6 References
Thomas H. Cormen, Charles E. Leiserson, Ronald
L. Rivest, and Cliord Stein. Introduction to Algorithms, Second Edition. MIT Press and McGrawHill, 2001. ISBN 0-262-03293-7. Pages 957961
of section 33.4: Finding the closest pair of points.
Jon Kleinberg; va Tardos (2006). Algorithm Design. Addison Wesley.
UCSB Lecture Notes
rosettacode.org - Closest pair of points implemented
in multiple programming languages
Line sweep algorithm for the closest pair problem
7.1
Text
7.2
Images
7.3
Content license