CSE331 Lecture 31

CSE331 Lecture 31 - 1 ,a 2 ); max(a 1 ,a 2 )) a L = a 1 ,,...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 31 CSE 331 Nov 11, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
HW 8 due today Q1 and Q 2 in separate piles I will not take any HW after 1:15pm
Background image of page 2
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
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Review Session Details
Background image of page 4
Optimal MST algorithms
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Need 2 blog volunteers
Background image of page 6
Counting Inversions Input: n distinct numbers a 1 ,a 2 ,…,a n Inversion: (i,j) with i < j s.t. a i > a j Output: Number of inversions
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 8
Three kinds of inversion 10 7 21 20 100 1 Non-crossing inversions are counted recursively
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Today’s agenda Divide and Conquer algorithm for counting the # inversions
Background image of page 10
HW 8 due today Q1 and Q 2 in separate piles I will not take any HW after 1:15pm
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mergesort-Count algorithm Input: a 1 , a 2 , …, a n Output: Numbers in sorted order+ #inversion MergeSortCount ( a, n ) If n = 2 return ( a1 > a2 , min(a
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 Counts #crossing-inversions+ MERGE O(n) O(n) T(2) = c T(n) = 2T(n/2) + cn O(n log n) time O(n log n) time If n = 1 return ( 0 , a 1 ) Rest of todays agenda MERGE-COUNT Computing closest pair of points 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 Group Talk time O(n 2 ) time algorithm? 1-D problem in time O(n log n) ? 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 Rest of todays agenda Divide and Conquer based algorithm...
View Full Document

This note was uploaded on 12/11/2011 for the course CSE 331 taught by Professor Rudra during the Fall '11 term at SUNY Buffalo.

Page1 / 17

CSE331 Lecture 31 - 1 ,a 2 ); max(a 1 ,a 2 )) a L = a 1 ,,...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online