ClosestPair Problem by Divide and Conquer - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

ClosestPair Problem by Divide and Conquer

Description:

Assume that they have been sorted in ascending order of their x coordinate. ... of their x-coordinates with ties resolved by increasing order of y coordinates. ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 8
Provided by: michael1537
Category:

less

Transcript and Presenter's Notes

Title: ClosestPair Problem by Divide and Conquer


1
Closest-Pair Problem by Divide and Conquer
  • Brute-force algorithm (in Chapter 3) takes
    time because the distance between all
    possible pair of points are computed and compared
  • Divide-and-conquer strategy can be used to
    achieve more efficient algorithm
  • Given n points
  • Assume that they have been sorted in ascending
    order of their x coordinate. Sorting complexity
    (mergesort)
  • Then we divide n points into two subsets S1 and
    S2 of n/2 points by a vertical line xc. All the
    points in S1 are located to the left of or on
    this line and all the points in S2 are located to
    the right or on this line. Complexity in finding
    this line

2
Recursive Algorithm
  • Find the closest pair in S1 and S2 separately,
    denoting the closest distance in S1 and S2 are d1
    and d2.
  • However, mind1,d2 is not the desired distance
    between the closest pair among all n points, why?
  • Closest pair may be located in different side of
    the partitioning line!
  • How to solve this problem?

3
Solution
  • Suppose these n points are also sorted according
    to their y-coordinate. This can be done in
    if S1 and S2 were y-sorted.
  • Then we can construct the y-sorted version of
    points in C1 and C2 (two strips shown in the
    above figure) in
  • Merge y-sorted version of points in C1 and C2
    into a single sorted list, check each elements
    distance to constant of its neighboring
    elements in
  • If there is any such distance is less than d,
    update the shortest distance and the closest pair
  • Recursive equation is

4
Convex-Hull Problem
  • Find the smallest convex polygon that contains n
    points in a plane. Brute-force convex-hull
    algorithm
  • Divide and Conquer quickhull
  • Given n points
    sorted in
    increasing order of their x-coordinates with ties
    resolved by increasing order of y coordinates.
  • First, leftmost point and rightmost point
    must belong to the convex hull
  • Connecting and , we have a vector
    , which partitions the plane into two
    semi-planes and the remaining points into left
    point sets and right point sets.

5
Quickhull
  • The upper/lower parts of the convex hull are
    called upper/lower hull, which can be constructed
    in the similar fashion (recursive algorithm)

6
QuickHull
  • Compute upper hull
  • find point Pmax that is farthest away from line
    P1P2
  • compute the hull of the points to the left of
    line P1Pmax
  • compute the hull of the points to the left of
    line PmaxP2
  • Compute lower hull in a similar manner

Pmax
P2
P1
7
Efficiency of QuickHull algorithm
  • Finding point farthest away from line P1P2 can be
    done in linear time
  • This gives same efficiency as quicksort
  • Worst case T( n2)
  • Average case T( n log n)
  • If points are not initially sorted by
    x-coordinate value, this can be accomplished in
    T( n log n) no increase in asymptotic
    efficiency class
  • Other algorithms for convex hull
  • Grahams scan
  • DCHull
  • also in T( n log n)
Write a Comment
User Comments (0)
About PowerShow.com