Contents
- California Dreaming
- Closest Pair of Points
- Pairs
- DivCon
- Center
- Complexity
- Timing
- Software
- References
Imagine you are driving a car on the Harbor Freeway in southern California with typical Los Angeles traffic conditions. Among the many things you might want to know is which pair of vehicles is nearest each other.
This is an instance of the Closest Pair of Points problem:
- Given the location of n points in the plane, which pair of points is closest to each other?

Closest Pair of Points
It is convenient to represent the points by a vector of complex values. The distance between points z(k) and z(j) is then
d = abs(z(k) - z(j))Here are a few points in the unit square. The closest pair is highlighted.

Pairs
The first algorithm you might think of computes the distance between all possible pairs of points and finds the minimum. This is a brute force approach that requires only a few lines of code.
function d = Pairs(z) % Pairs. % d = Pairs(z) is the minimum distance between any two elements % of the complex vector z. n = length(z); d = Inf; for k = 1:n for j = k+1:n if abs(z(k) - z(j)) < d d = abs(z(k) - z(j)); end end endendDivCon
DivCon stands for Divide and Conquer. In outline, the steps are:
- Divide the set of points into two halves.
- Recursively, find the closest pair in each half.
- Consider the case when the closest pair has one point in each half.
- Terminate the recursion with sets of two or three points.
More...