Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 29 CSE 331 Nov 8, 2017.

Similar presentations


Presentation on theme: "Lecture 29 CSE 331 Nov 8, 2017."— Presentation transcript:

1 Lecture 29 CSE 331 Nov 8, 2017

2 Mini project video due Mon

3 Anonymous feedback

4 Some links

5 HW 5 grading Should be done by today

6 Rankings

7 How close are two rankings?

8 Rest of today’s agenda Formal problem: Counting inversions
Divide and Conquer algorithm

9 Divide and Conquer Divide up the problem into at least two sub-problems Solve all sub-problems: Mergesort Recursively solve the sub-problems Solve some sub-problems: Multiplication Solve stronger sub-problems: Inversions “Patch up” the solutions to the sub-problems for the final solution

10 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)


Download ppt "Lecture 29 CSE 331 Nov 8, 2017."

Similar presentations


Ads by Google