Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 34 CSE 331 Nov 19, 2010. HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm.

Similar presentations


Presentation on theme: "Lecture 34 CSE 331 Nov 19, 2010. HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm."— Presentation transcript:

1 Lecture 34 CSE 331 Nov 19, 2010

2 HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm

3 No new HW out this week Solutions to HW 9 at the end of the lecture

4 Graded HW 8 Individual pickups from next week Jeff: Recitations and Wed office hours Alex: Tuesday and Thursday office hours

5 My office hour today Canceled after 2:35 pm

6 Next Monday’s lecture I’ll be out of town: no office hours either Jeff will teach the lecture

7 Last plug for Feedback Forms Link for the survey on the blog

8 Counting Inversions Input: n distinct numbers a 1,a 2,…,a n Inversion: (i,j) with i a j Output: Number of inversions

9 Divide and Conquer Divide up the problem into at least two sub-problems Recursively solve the sub-problems “Patch up” the solutions to the sub-problems for the final solution Solve the stronger problem of counting inversions + sorting

10 Three kinds of inversion 10 7 2120 1001 Non-crossing inversions are counted recursively

11 Mergesort-Count algorithm Input: a 1, a 2, …, a n Output: Numbers in sorted order+ #inversion MergeSortCount( a, n ) If n = 2 return the order ( a1 > a2, min(a 1,a 2 ); max(a 1,a 2 )) a L = a 1,…, a n/2 a R = a n/2+1,…, a n return (c+c L +c R,a) (c L, a L ) = MergeSortCount(a L, n/2) (c R, a R ) = MergeSortCount(a R, n/2) (c, a) = MERGE-COUNT(a L,a R ) Counts #crossing-inversions+ MERGE O(n) T(2) = c T(n) = 2T(n/2) + cn O(n log n) time

12 HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm

13 Today’s agenda MERGE-COUNT Computing closest pair of points

14 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

15 Group Talk time O(n 2 ) time algorithm? 1-D problem in time O(n log n) ?

16 Sorting to rescue in 2-D? Pick pairs of points closest in x co-ordinate Pick pairs of points closest in y co-ordinate Choose the better of the two

17 Rest of today’s agenda Divide and Conquer based algorithm


Download ppt "Lecture 34 CSE 331 Nov 19, 2010. HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm."

Similar presentations


Ads by Google