Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 32 CSE 331 Nov 14, 2011.

Similar presentations


Presentation on theme: "Lecture 32 CSE 331 Nov 14, 2011."— Presentation transcript:

1 Lecture 32 CSE 331 Nov 14, 2011

2 HW related stuff HW 8 solutions at the end of the lecture
HW 7 available for pickup

3 Review Sessions this week
Tuesday, 1:00-1:50pm– Jesse Commons 9 (Review of covered material) Friday, 11:30am-12:20pm– Atri Bell 242 (problem solving session) For more details, check out for the blog post

4 Need a blog and scribe volunteer

5 Counting Inversions Input: n distinct numbers a1,a2,…,an
Inversion: (i,j) with i < j s.t. ai > aj Output: Number of inversions

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

7 Three kinds of inversion
10 7 21 20 100 1 Non-crossing inversions are counted recursively

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

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

10 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

11 Group Talk time O(n2) time algorithm? 1-D problem in time O(n log n) ?

12 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

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


Download ppt "Lecture 32 CSE 331 Nov 14, 2011."

Similar presentations


Ads by Google