Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 30 CSE 331 Nov 9, 2011.

Similar presentations


Presentation on theme: "Lecture 30 CSE 331 Nov 9, 2011."— Presentation transcript:

1 Lecture 30 CSE 331 Nov 9, 2011

2 Online Office Hr @10:00-10:30pm

3 Possible review session

4 Need a scribe volunteer

5 Integer Multiplication
Input: a = (an-1,..,a0) and b = (bn-1,…,b0) a = b = 1001 Output: c = a x b c =

6 Some notation Dec(a) = Dec(a1)2[n/2] + Dec(a0)
Dec(a) = an-12n-1+ an-22n-2+…+ a12+ a0 a = Dec(a) = 13 a1 = (an-1,..,a[n/2]) a0=(a[n/2]-1,…,a0) a1 = 11 and a0 = 01 Dec(a) = an-12n-1+…+ a[n/2]2[n/2]+a[n/2]-12[n/2]-1 +…+ a0 = 2[n/2] (an-12n-[n/2]-1+…+ a[n/2]) + a[n/2]-12[n/2]-1 +…+ a0 Dec(a) = Dec(a1)2[n/2] + Dec(a0)

7 Today’s agenda Design Divide and Conquer Multiplication Algorithm

8 The algorithm so far… Shift by O(n) bits Adding O(n) bit numbers Mult over n bits a  b = a1b1 22[n/2] + (a1b0+a0b1)2[n/2] + a0b0 Multiplication over n/2 bit inputs T(n) is O(n2) T(n) ≤ 4T(n/2) + cn T(1) ≤ c

9 The key identity a1b0+a0b1= (a1+a0)(b1+b0) - a1b1 - a0b0

10 The final algorithm Input: a = (an-1,..,a0) and b = (bn-1,…,b0) T(1) ≤ c Mult (a, b) If n = 1 return a0b0 T(n) ≤ 3T(n/2) + cn a1 = an-1,…,a[n/2] and a0 = a[n/2]-1,…, a0 Compute b1 and b0 from b O(nlog 3) = O(n1.59) run time x = a1 + a0 and y = b1 + b0 Let p = Mult (x, y), D = Mult (a1, b1), E = Mult (a0, b0) All green operations are O(n) time F = p - D - E return D  22[n/2] + F  2[n/2] + E a  b = a1b1 22[n/2] +( (a1+a0)(b1+b0) - a1b1 - a0b0 ) 2[n/2] + a0b0

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


Download ppt "Lecture 30 CSE 331 Nov 9, 2011."

Similar presentations


Ads by Google