This preview shows page 1. Sign up to view the full content.
Unformatted text preview: to store dynamic set S.
Total running time: O(n lg n). Correctness
Theorem: If there is an intersection,
the algorithm finds it. Correctness
Theorem: If there is an intersection,
the algorithm finds it.
Proof: Let X be the leftmost intersection point.
Assume for simplicity that
• only two segments s1, s2 pass through X, and
• no two points have the same xcoordinate.
At some point before we reach X,
s1 and s2 become consecutive in the order of S.
Either initially consecutive when s1 or s2 inserted,
or became consecutive when another deleted. Closest Pair
Closest Pair
• Find a closest pair among p1…pn !Rd
• Easy to do in O(dn2) time
– For all pi pj, compute pi – pj and choose
the minimum • We will aim for better time, as long as d is
“small”
• For now, focus on d=2
October 30, 2003 Lecture 17: Closest Pair 2 Divide & Conquer Divide and conquer • Divide:
– Compute the median of xcoordinates
– Split the points into PL and
PR, each of size n/2 • Conquer: compute the
closest pairs for PL and PR
• Combine the results (the
h a r d p a r t) Divide & Conquer
Combine 2k • Let k=min(k1,k2)
• Observe:
– Need to check only pairs which
cross the dividing line
– Only interested in pairs within
distance < k...
View
Full
Document
 Fall '08
 UNGOR
 Algorithms, Data Mining, Databases

Click to edit the document details