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

Post on 22-Dec-2015

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Lecture 33

CSE 331Nov 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

Feedback Forms

Link for the survey on the blog

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

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

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)

The key identity

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

(Old) Reading AssignmentSec 5.2 of [KT]

Rankings

How close are two rankings?

Today’s agenda

Formal problem: Counting inversions

Divide and Conquer algorithm

top related