1 / 24

Lecture 31

Lecture 31. CSE 331 Nov 13, 2017. Mini project video due TODAY. Two changes in HWs. Closest pairs of points. Input: n 2-D points P = { p 1 ,…, p n }; p i =( x i , y i ). d(p i ,p j ) = ( ( x i -x j ) 2 +( y i -y j ) 2 ) 1/2. Output: Points p and q that are closest.

jackie
Download Presentation

Lecture 31

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. Lecture 31 CSE 331 Nov 13, 2017

  2. Mini project video due TODAY

  3. Two changes in HWs

  4. Closest pairs of points Input: n 2-D points P = {p1,…,pn}; pi=(xi,yi) d(pi,pj) = ( (xi-xj)2+(yi-yj)2)1/2 Output: Points p and q that are closest

  5. Dividing up P R Q First n/2 points according to the x-coord

  6. Recursively find closest pairs R Q δ = min (blue, green)

  7. An aside: maintain sorted lists Px and Pyare P sorted by x-coord and y-coord Qx, Qy, Rx, Rycan be computed from Px and Pyin O(n) time

  8. An easy case R > δ Q All “crossing” pairs have distance > δ δ = min (blue, green)

  9. Life is not so easy though R Q δ = min (blue, green)

  10. Euclid to the rescue (?) yj d(pi,pj) = ( (xi-xj)2+(yi-yj)2)1/2 yi xj xi The distance is larger than the x or y-coord difference

  11. Life is not so easy though δ δ >δ R Q > δ > δ δ = min (blue, green)

  12. All we have to do now δ δ R Q S Figure if a pair in S has distance <δ δ = min (blue, green)

  13. The algorithm so far… O(n log n) + T(n) Input: n 2-D points P = {p1,…,pn}; pi=(xi,yi) Sort P to get Px and Py O(n log n) T(< 4) = c Closest-Pair (Px, Py) T(n) = 2T(n/2) + cn If n < 4 then find closest point by brute-force Q is first half of Pxand R is the rest O(n) Compute Qx, Qy, Rxand Ry O(n) (q0,q1) = Closest-Pair (Qx, Qy) O(n log n) overall (r0,r1) = Closest-Pair (Rx, Ry) O(n) δ = min ( d(q0,q1), d(r0,r1) ) O(n) S = points (x,y) in P s.t. |x – x*| < δ return Closest-in-box (S, (q0,q1), (r0,r1)) Assume can be done in O(n)

  14. Rest of today’s agenda Implement Closest-in-box in O(n) time

  15. High level view of CSE 331 Problem Statement Problem Definition Three general techniques Algorithm “Implementation” Data Structures Analysis Correctness+Runtime Analysis

  16. Greedy Algorithms Natural algorithms Reduced exponential running time to polynomial

  17. Divide and Conquer Recursive algorithmic paradigm Reduced large polynomial time to smaller polynomial time

  18. A new algorithmic technique Dynamic Programming

  19. Dynamic programming vs. Divide & Conquer

  20. Same same because Both design recursive algorithms

  21. Different because Dynamic programming is smarter about solving recursive sub-problems

  22. End of Semester blues Can only do one thing at any day: what is the optimal schedule to obtain maximum value? Write up a term paper (10) Party! (2) Exam study (5) 331 HW (3) Project (30) Monday Tuesday Wednesday Thursday Friday

  23. Previous Greedy algorithm Order by end time and pick jobs greedily Greedy value = 5+2+3= 10 Write up a term paper (10) OPT = 30 Party! (2) Exam study (5) 331 HW (3) Project (30) Monday Tuesday Wednesday Thursday Friday

  24. Today’s agenda Formal definition of the problem Start designing a recursive algorithm for the problem

More Related