This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Suffices to look at points in
the 2kwidth strip around the
median line k2
k1 Divide & Conquer
Scanning the strip
• Sort all points in the strip
by their ycoordinates,
forming q1…qr, r n.
• Let yi be the ycoordinate
of qi
• For i=1 to r
– j=i1
– While yiyj < d • Check the pair qi,qj
• j:=j1 d Analysis  Analysis
Divide & Conquer
• Correctness: easy
• Running time is more
involved
• Can we have many
qj’s that are within
distance k from qi ?
• No
• Proof by packing
argument
October 30, 2003 Lecture 17: Closest Pair k 6 Divide & Conquer  Analysis
Analysis, ctd.
Theorem: there are at most 7
qj’s such that yiyj k.
Proof:
• Each such qj must lie either
in the left or in the right k! k
square
• Within each square, all
points have distance
distance k from others
• We can pack at most 4 such
points into one square, so
we have 8 points total (incl.
qi) qi Divide & Conquer  Analysis Packing bound
• Proving “4” is not obvious
• Wi l l p r o v e “ 5 ”
– Draw a disk of radius k/2
around each point
– Disks are disjoint
– The disksquare intersection
has area
(k/2)2/4 = /16 k2
– The square has area k2
– Can pack at most 16/
5.1
points Divide & Conquer  Analysis
Running time
• Divide: O(n)
• Combine: O(n log n) because we sort by y
• However, we can:
– Sort all points by y at the beginning
– Divide preserves the yorder of points
Then combine takes only O(n) • We get T(n)=2T(n/2)+O(n), so
T(n)=O(n log n)...
View Full
Document
 Fall '08
 UNGOR
 Algorithms, Data Mining, Databases

Click to edit the document details