Let yi be the y coordinate of qi for i1 to r ji 1

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Suffices to look at points in the 2k-width strip around the median line k2 k1 Divide & Conquer Scanning the strip • Sort all points in the strip by their y-coordinates, forming q1…qr, r n. • Let yi be the y-coordinate of qi • For i=1 to r – j=i-1 – While yi-yj < d • Check the pair qi,qj • j:=j-1 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 yi-yj 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 disk-square 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 y-order 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

Ask a homework question - tutors are online