0% found this document useful (0 votes)
147 views3 pages

Closest Pair of Points Problem

The closest pair of points problem involves finding the two points with the smallest distance between them from a set of n points. A brute force algorithm compares all possible pairs of points, taking O(n^2) time. The problem can be solved in O(n log n) time using a divide and conquer approach that recursively splits the point set into halves and finds the closest pairs within each subset and across the dividing line. The dynamic version maintains the closest pair efficiently under insertions and deletions of points.

Uploaded by

premkumaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views3 pages

Closest Pair of Points Problem

The closest pair of points problem involves finding the two points with the smallest distance between them from a set of n points. A brute force algorithm compares all possible pairs of points, taking O(n^2) time. The problem can be solved in O(n log n) time using a divide and conquer approach that recursively splits the point set into halves and finds the closest pairs within each subset and across the dividing line. The dynamic version maintains the closest pair efficiently under insertions and deletions of points.

Uploaded by

premkumaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Closest pair of points shown in red

2. Split the set of points into two equal-sized subsets


by a vertical line x=x .
3. Solve the problem recursively in the left and right
subsets. This yields the left-side and right-side minimum distances dL and dR , respectively.

The closest pair of points problem or closest pair


problem is a problem of computational geometry: given
n points in metric space, nd a pair of points with the
smallest distance between them. The closest pair problem for points in the Euclidean plane[1] was among the
rst geometric problems which were treated at the origins
of the systematic study of the computational complexity
of geometric algorithms.

4. Find the minimal distance dLR among the set of


pairs of points in which one point lies on the left of
the dividing vertical and the second point lies to the
right.
5. The nal answer is the minimum among dL ,
dR , and dLR .

A naive algorithm of nding distances between all pairs


of points and selecting the minimum requires O(dn2 )
time. It turns out that the problem may be solved in O(n
log n) time in a Euclidean space or Lp space of xed dimension d. In the algebraic decision tree model of computation, the O(n log n) algorithm is optimal. The optimality follows from the observation that the element
uniqueness problem (with the lower bound of (n log n)
for time complexity) is reducible to the closest pair problem: checking whether the minimal distance is 0 after the
solving of the closest pair problem answers the question
whether there are two coinciding points.

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 dist=
min(dL , dR ). Therefore for each point p to the left
of the dividing line we have to compare the distances to
the points that lie in the rectangle of dimensions (dist, 2
dist) to the right of the dividing line, as shown in the gure. And what is more, this rectangle can contain at most
six points with pairwise distances at least dR . Therefore it is sucient to compute at most 6n left-right distances in step 4.[5] The recurrence relation for the number
of steps can be written as T(n) = 2 T(n/2) + O(n), which
we can solve using the master theorem to get O(n log n).

In the computational model which assumes that the oor


function is computable in constant time the problem can
be solved in O(n log log n) time.[2] If we allow randomization to be used together with the oor function, the
problem can be solved in O(n) time.[3][4]
1

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

[4] Richard Lipton (24 September 2011). Rabin Flips a


Coin.

As the closest pair of points dene 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 O(n log n)
time. These approaches are not ecient for dimension
d>2, while the divide-and-conquer algorithm can be generalized to take O(n log n) time for any constant value of
d.

[5] Cormen, Leiserson, Rivest, and Stein, 2001.

Dynamic closest-pair problem

The dynamic version for the closest-pair problem is stated


as follows:
Given a dynamic set of objects, nd algorithms and
data structures for ecient recalculation of the closest pair of objects each time the objects are inserted
or deleted.
If the bounding box for all points is known in advance
and the constant-time oor function is available, then the
expected O(n) space data structure was suggested that
supports expected-time O(log n) insertions and deletions
and constant query time. When modied for the algebraic decision tree model, insertions and deletions would
require O(log2 n) expected time.[6] 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.

[6] Mordecai Golin, Rajeev Raman, Christian Schwarz,


Michiel Smid, Randomized Data Structures For The Dynamic Closest-Pair Problem, SIAM J. Comput., vo. 26,
no. 4, 1998, preliminary version reported at the 4th Annu.
ACM-SIAM Symp. on Discrete Algorithms, pp. 301
310 (1993)

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

Text and image sources, contributors, and licenses

7.1

Text

Closest pair of points problem Source: https://en.wikipedia.org/wiki/Closest_pair_of_points_problem?oldid=662062733 Contributors:


XJaM, Geary, Altenmann, Tobias Bergemann, Giftlite, Sam Hocevar, Spoon!, Rrenaud, LOL, GregorB, BD2412, Qwertyus, Vegaswikian,
CiaPan, Johndburger, Fulldecent, Gfonsecabr, Salgueiro~enwiki, Magioladitis, David Eppstein, Davecrosby uk, VolkovBot, Loren.wilton,
AgentNN, Addbot, Tide rolls, Luckas-bot, AnomieBOT, Erel Segal, Wachmc, Omnipaedista, Adrignola, SaschaWol, GmeSalazar, AmrinderAroraSW, Mikebolt and Anonymous: 21

7.2

Images

File:Closest_pair.jpg Source: https://upload.wikimedia.org/wikipedia/commons/6/65/Closest_pair.jpg License: Public domain Contributors: ? Original artist: ?


File:Closest_pair_of_points.svg Source: https://upload.wikimedia.org/wikipedia/commons/3/37/Closest_pair_of_points.svg License:
CC0 Contributors: Own work Original artist: Qef

7.3

Content license

Creative Commons Attribution-Share Alike 3.0

You might also like