lecture 33 cse 331 nov 17, 2010. online office hours tonight @9 alex will host the office hours

14
Lecture 33 CSE 331 Nov 17, 2010

Post on 22-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Lecture 33

CSE 331Nov 17, 2010

Page 2: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Online office hours tonight @9

Alex will host the office hours

Page 3: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Next Monday’s lecture

I’ll be out of town

Jeff will teach the lecture

Page 4: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Feedback Forms

Link for the survey on the blog

Page 5: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

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

Page 6: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Integer Multiplication

Input: a = (an-1,..,a0) and b = (bn-1,…,b0)

Output: c = a x b

a = 1101 b = 1001

c =1110101

a = a12[n/2] + a0 a1 = 11 and a0 = 01

b = b12[n/2] + b0 b1 = 10 and b0 = 01

Page 7: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

First attempt

Mult over n bits

Mult over n bits

Multiplication over n/2 bit inputsMultiplication over n/2 bit inputs

Shift by O(n) bitsShift by O(n) bits

Adding O(n) bit numbersAdding O(n) bit numbers

T(n) ≤ 4T(n/2) + cn T(1) ≤ c

T(n) is O(n2)T(n) is O(n2)

Page 8: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

The key identity

Page 9: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

The final algorithmInput: a = (an-1,..,a0) and b = (bn-1,…,b0)

If n = 1 return a0b0

a1 = an-1,…,a[n/2] and a0 = a[n/2]-1,…, a0

Compute b1 and b0 from b

Mult (a, b)

Let p = Mult (x, y), D = Mult (a1, b1), E = Mult (a0, b0)

T(1) ≤ c

T(n) ≤ 3T(n/2) + cn

O(nlog 3) = O(n1.59) run time

O(nlog 3) = O(n1.59) run time

Page 10: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours
Page 11: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

(Old) Reading AssignmentSec 5.2 of [KT]

Page 12: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Rankings

Page 13: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

How close are two rankings?

Page 14: Lecture 33 CSE 331 Nov 17, 2010. Online office hours tonight @9 Alex will host the office hours

Today’s agenda

Formal problem: Counting inversions

Divide and Conquer algorithm