Professional Documents
Culture Documents
CMSC 451: Closest Pair of Points: Slides By: Carl Kingsford
CMSC 451: Closest Pair of Points: Slides By: Carl Kingsford
Problem
Given a set of points {p1 , . . . , pn } find the pair of points {pi , pj }
that are closest together.
Goal
Split the points with line L so that half the points are on each side.
dleft
dright
L
Merge: the hard case
dleft
d
L
Theorem
Suppose Sy = p1 , . . . , pm . If dist(pi , pj ) < d then j − i ≤ 15.
d/2
1 2 3
How many points in each box?
4 5 6 7
8 9 10 11
12 13 14 15
Proof, 1
d/2
1 2 3
How many points in each box?
4 5 6 7
At most 1 because each box is
completely contained in one half
8 9 10 11
and no two points in a half are
closer than d.
12 13 14 15
Proof, 2
d/2
• Then, at least 3 full rows
1 2 3 separate them (the packing
shown is the smallest
4 5 6 7
possible).
8 9 10 11
• But the height of 3 rows is
> 3d/2, which is > d.
12 13 14 15
• So the two points are father
than d apart.
Linear Time Merge
ClosestPair(Px, Py):
if |Px| == 2: return dist(Px[1],Px[2]) // base
d1 = ClosestPair(FirstHalf(Px,Py)) // divide
d2 = ClosestPair(SecondHalf(Px,Py))
d = min(d1,d2)