1 / 17

The Divide-and-Conquer Strategy

The Divide-and-Conquer Strategy. 報告者 : 郭育婷. The 2-Dimesional Maxima Finding Problem. 何謂 Dominates ?. A point (x1, y1) dominates (x2, y2) if x1 > x2 and y1 > y2. Y. A. A dominates B. B. X. The 2-Dimesional Maxima Finding Problem. 何謂 Maxima ?.

Download Presentation

The Divide-and-Conquer Strategy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Divide-and-Conquer Strategy 報告者:郭育婷

  2. The 2-Dimesional Maxima Finding Problem 何謂 Dominates ? • A point (x1, y1) dominates (x2, y2) if x1 > x2 and y1 > y2. Y A A dominates B B X

  3. The 2-Dimesional Maxima Finding Problem 何謂 Maxima ? • A point is called a maxima if no other point dominates it. Y 兩兩比較 Time Complexity:O(n2) X

  4. Maxima Finding Algorithm Input: A set S of n planar points. Output:The maximal points of S. Step 1: If S contains only one point, return it as the maxima. Otherwise, find a line L perpendicular to the X-axis which separatesthe set of points into two subsets SLand SR, each consisting of n/2 points. Step 2: Recursively find the maximal points of SL and SR . • Step 3: Project the maximal points of SLandSRonto L and sort these points according to their y-values. Conduct a linear scan on the projections and discard each of the maximal points of SLif its y-value is less than the y-value of some maximal point of SR.

  5. Y Y X X Maxima Finding Algorithm Illustration Step 1 If only one point else Time Complexity:O(n) L SL SR maxima

  6. Y X Maxima Finding Algorithm Illustration Step 2 Time Complexity:2T(n/2) L L SL SR

  7. Maxima Finding Algorithm Illustration Step 3 Time Complexity:O(nlogn) Y L SL SR X

  8. Maxima Finding Time complexity Time complexity: T(n) Step 1: O(n) Step 2: 2T(n/2) Step 3: O(nlogn) Assume n = 2k T(n)=O(nlogn)+O(nlog2n) =O(nlog2n)

  9. Maxima Finding Time complexity After presorting Time complexity: O(nlogn)+T(n) Step 1: O(n) Step 2: 2T(n/2) Step 3: O(n) Assume n = 2k T(n)=O(nlogn) Time complexity =O(nlogn)+T(n) = O(nlogn)+O(nlogn)= O(nlogn)

  10. Y X X The Closest Pair Problem 何謂 Closest Pair ? • Given a set S of n points, find a pair of points which are closest together(在一個有 n 個點的集合 S 中,找最靠近的兩個點) 1-D version: 2-D version: Time Complexity:O(nlogn)

  11. Closest Pair Algorithm Input: A set S of n planar points. Output: The distance between two closest points. Step 1: Sort points in S according to their y-values and x-values. Step 2: If S contains only one point, return infinity as its distance. Step 3: Find a median line L perpendicular to the X-axis to divide S into SL and SR, with equal sizes. Step 4: Recursively apply Steps 2 and 3 to solve the closest pair problems of SL and SR. Let dL(dR) denote the distance between the closest pair in SL (SR). Let d = min(dL, dR). Step 5: For a point P in the half-slab bounded by L-d and L, let its y-value be denoted as yP . For each such P, find all points in the half-slab bounded by L and L+d whose y-value fall within yP+d and yP-d. If the distance dbetween P and a point in the other half-slab is less than d, let d=d. The final value of d is the answer

  12. Y Y X X Closest Pair Algorithm Illustration Step 1 先針對每個點X軸的值和Y軸的值做排序 Step 3 Step 2 If only one point Time Complexity:O(n) L SL SR d = ∞

  13. Y X Closest Pair Algorithm Illustration Step 4 Time Complexity:2T(n/2) L L SL SR

  14. Y X Closest Pair Algorithm Illustration Step 5 L SL SR dL dR d=min(dL,dR) L-d L+d Brute-force way = n2/4 , not good

  15. 2d d Closest Pair Algorithm Illustration Fortunately, the merging step can be accomplished in O(n) time. Y P X

  16. Closest Pair Time complexity Time complexity: Step 1: O(nlogn) Step 2~5: T(n) = 2T(n/2)+S(n)+M(n) T(n)=O(nlogn) Total time-complexity =O(nlogn)+T(n) = O(nlogn)+O(nlogn)= O(nlogn)

  17. 報告完畢~

More Related