Download presentation
Presentation is loading. Please wait.
1
Lecture 31 CSE 331 Nov 11, 2011
2
HW 8 due today I will not take any HW after 1:15pm
Q1 and Q 2 in separate piles I will not take any HW after 1:15pm
3
Other HW related stuff Solutions to HW 8 on Monday
HW 7 should be available for pickup from Monday HW 9 has been posted on the blog
4
Review Session Details
5
Optimal MST algorithms
6
Need 2 blog volunteers
7
Counting Inversions Input: n distinct numbers a1,a2,…,an
Inversion: (i,j) with i < j s.t. ai > aj Output: Number of inversions
8
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
9
Three kinds of inversion
10 7 21 20 100 1 Non-crossing inversions are counted recursively
10
Today’s agenda Divide and Conquer algorithm for counting the # inversions
11
HW 8 due today I will not take any HW after 1:15pm
Q1 and Q 2 in separate piles I will not take any HW after 1:15pm
12
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)
13
Rest of today’s agenda MERGE-COUNT Computing closest pair of points
14
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
15
Group Talk time O(n2) 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.