Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 30 CSE 331 Nov 8, 2013. HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR.

Similar presentations


Presentation on theme: "Lecture 30 CSE 331 Nov 8, 2013. HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR."— Presentation transcript:

1 Lecture 30 CSE 331 Nov 8, 2013

2 HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR SOURCES

3 Related HW stuff HW 8 has been posted on piazza Solutions to HW 7 at the END of the lecture Can pick up graded HW 6 from Monday

4 Integer Multiplication Input: a = (a n-1,..,a 0 ) and b = (b n-1,…,b 0 ) Output: c = a x b a = 1101 b = 1001 c =1110101

5 Some notation Dec(a) = Dec(a 1 )  2 [n/2] + Dec(a 0 ) a 1 = 11 and a 0 = 01 Dec(a) = a n-1  2 n-1 + a n-2  2 n-2 +…+ a 1  2+ a 0 a = 1101 Dec(a) = 13 a 1 = (a n-1,..,a [n/2] ) a 0 =(a [n/2]-1,…,a 0 ) Dec(a) = a n-1  2 n-1 +…+ a [n/2]  2 [n/2] +a [n/2]-1  2 [n/2]-1 +…+ a 0 = 2 [n/2]  (a n-1  2 n-[n/2]-1 +…+ a [n/2] ) + a [n/2]-1  2 [n/2]-1 +…+ a 0

6 The algorithm so far… Mult over n bits Multiplication over n/2 bit inputs Shift by O(n) bits Adding O(n) bit numbers T(n) ≤ 4T(n/2) + cn T(1) ≤ c T(n) is O(n 2 )

7 Today’s agenda Design a better Divide and Conquer Multiplication Algorithm

8 HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR SOURCES

9 The key identity

10 The final algorithm Input: a = (a n-1,..,a 0 ) and b = (b n-1,…,b 0 ) If n = 1 return a 0 b 0 a 1 = a n-1,…,a [n/2] and a 0 = a [n/2]-1,…, a 0 Compute b 1 and b 0 from b Mult (a, b) Let p = Mult (x, y), D = Mult (a 1, b 1 ), E = Mult (a 0, b 0 ) T(1) ≤ c T(n) ≤ 3T(n/2) + cn O(n log 3 ) = O(n 1.59 ) run time O(n log 3 ) = O(n 1.59 ) run time

11

12 (Old) Reading Assignment Sec 5.2 of [KT]

13 Rankings

14 How close are two rankings?

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

16 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 all sub-problems: Mergesort Solve some sub-problems: Multiplication Solve stronger sub-problems: Inversions


Download ppt "Lecture 30 CSE 331 Nov 8, 2013. HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR."

Similar presentations


Ads by Google