Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 34 CSE 331 Nov 23, 2009. Homework related stuff Graded HW 8+9, solutions to HW 9 the week after Thanksgiving.

Similar presentations


Presentation on theme: "Lecture 34 CSE 331 Nov 23, 2009. Homework related stuff Graded HW 8+9, solutions to HW 9 the week after Thanksgiving."— Presentation transcript:

1 Lecture 34 CSE 331 Nov 23, 2009

2 Homework related stuff Graded HW 8+9, solutions to HW 9 the week after Thanksgiving

3 Closest pairs of points Input: n 2-D points P = {p 1,…,p n }; p i =(x i,y i ) Output: Points p and q that are closest d(p i,p j ) = ( (x i -x j ) 2 +(y i -y j ) 2 ) 1/2

4 A property of Euclidean distance d(p i,p j ) = ( (x i -x j ) 2 +(y i -y j ) 2 ) 1/2 yiyi xixi xjxj yjyj

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

6 Recursively find closest pairs Q R

7 An aside: maintain sorted lists P x and P y are P sorted by x-coord and y-coord Q x, Q y, R x, R y can be computed from P x and P y in O(n) time

8 An easy case Q R > δ All “crossing” pairs have distance > δ

9 Life is not so easy though Q R

10 Euclid to the rescue (?) d(p i,p j ) = ( (x i -x j ) 2 +(y i -y j ) 2 ) 1/2 yiyi xixi xjxj yjyj

11 Life is not so easy though Q R δ δ > δ> δ > δ

12 All we have to do now Q R δ δ S Figure if a pair in S has distance < δ

13 The algorithm so far… Input: n 2-D points P = {p 1,…,p n }; p i =(x i,y i ) Sort P to get P x and P y Q is first half of P x and R is the rest Closest-Pair (P x, P y ) Compute Q x, Q y, R x and R y (q 0,q 1 ) = Closest-Pair (Q x, Q y ) (r 0,r 1 ) = Closest-Pair (R x, R y ) δ = min ( d(q 0,q 1 ), d(r 0,r 1 ) ) S = points (x,y) in P s.t. |x – x*| < δ return Closest-in-box (S, (q 0,q 1 ), (r 0,r 1 )) If n < 4 then find closest point by brute-force Assume can be done in O(n) O(n log n) O(n) O(n log n) + T(n) T(< 4) = c T(n) = 2T(n/2) + cn O(n log n) overall

14 Today’s agenda Implement Closest-in-box in O(n) time


Download ppt "Lecture 34 CSE 331 Nov 23, 2009. Homework related stuff Graded HW 8+9, solutions to HW 9 the week after Thanksgiving."

Similar presentations


Ads by Google