Find Closet Pairs -- To be continue

来源:互联网 发布:grace评分软件下载 编辑:程序博客网 时间:2024/05/17 01:57

Sweep line algorithm: a vertical line that is conceptually "swept" across the plane. To better understand this algorithm, it is better to compare it with divide-and-conquer

1: Closet Pair on the line (1-D)

    Consider a set of points S on a line, the goal is to find which two of these points are minimally distant from each other.  To solve this problem, we can partition this set into two parts by some point m. We call the left half as S,_1 right half as S_2, Assume that {p1, p2} are the points that is the closet pair in S_1, and {q1, q2} are the point that is the closet pair in S_2, d as the smaller of these two solutions. We can conclude that: There are three possibilities that might make the minimum distance d:

1: {p1, p2},  2: {q1, q2}, 3: some pair {p3, q3} (p3 is from left half S_1, q3 is from right half S_2) 

      



Key Observation: If the closet pair has one point from S_1 and one from S_2, then, both of these points must be within d of the midpoint m.

Final Observation: Since the minimum distance among the sub-solutions was d, there can be only a maximum of one point within d of m in each subsets. Hence, in order to see which of the three options is the correct closet pair, we need to test each pair of points to see if there is a pair {p3, q3} that defines a pair closer than d. The whole time complexity is NlgN.


2: Given a set of points {p1, ... pn} find the pair of points {pi, ... pj} that are closet together. (2-D)

    First method: Divide and Conquer

    Suppose we have the following points, and we first divide them into two parts. There are there possibilities: d is the smallest one, q is the smallest one or p is the smallest one.  If d or p is the smallest one, we can get the minimum number through comparing d= min{d, p}, however, the trouble part is what if the q is the smallest one, the naive divide and conquer can't cover this case. 

   





2: Given a set of rectangles, find the most overlapped points. 

0 0