Divide and Conquer - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Divide and Conquer

Description:

6. Design and Analysis of Algorithms - Chapter 4. 7. 8 ... Step 5 takes O(n) time (as we saw in the previous section) Step 6 takes O(1) time ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 12
Provided by: Alek170
Category:
Tags: conquer | divide | saw

less

Transcript and Presenter's Notes

Title: Divide and Conquer


1
Divide and Conquer
  • The most well known algorithm design strategy
  • Divide instance of problem into two or more
    smaller instances
  • Solve smaller instances recursively
  • Obtain solution to original (larger) instance by
    combining these solutions

2
Divide-and-conquer technique
a problem of size n
subproblem 2 of size n/2
subproblem 1 of size n/2
a solution to subproblem 1
a solution to subproblem 2
a solution to the original problem
3
(No Transcript)
4
(No Transcript)
5
(No Transcript)
6
(No Transcript)
7
(No Transcript)
8
(No Transcript)
9
(No Transcript)
10
Divide and Conquer - Closest pair
  • Divide the set into two equal sized parts by the
    line l, and recursively compute the minimal
    distance in each part.
  • Let d be the minimal of the two minimal
    distances.
  • Eliminate points that lie farther than d apart
    from l
  • Sort the remaining points according to their
    y-coordinates
  • Scan the remaining points in the y order and
    compute the distances of each point to its five
    neighbors.
  • If any of these distances is less than d then
    update d.
  • Step 2 takes O(1) time
  • Step 3 takes O(n) time
  • Step 4 is a sort that takes O(nlogn) time
  • Step 5 takes O(n) time (as we saw in the previous
    section)
  • Step 6 takes O(1) time
  • O((logn)nlogn)

11
Closest pair - improved algorithm
  • Step 1 Divide the set into..., and recursively
    compute the distance in each part, returning the
    points in each set in sorted order by
    y-coordinate.
  • ....
  • Step 4 Merge the two sorted lists into one
    sorted list in O(n) time.
  • O(nlogn)
Write a Comment
User Comments (0)
About PowerShow.com