lecture 28 cse 331 nov 9, 2015. mini project report due wed

9
Lecture 28 CSE 331 Nov 9, 2015

Upload: wesley-barnett

Post on 18-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Lecture 28

CSE 331Nov 9, 2015

Page 2: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Mini project report due WED

Page 3: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Piazza Participation Cutoffs

Page 4: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Mergesort algorithmInput: a1, a2, …, an Output: Numbers in sorted order

MergeSort( a, n )

aL = a1,…, an/2

aR = an/2+1,…, an

return MERGE ( MergeSort(aL, n/2), MergeSort(aR, n/2) )

If n = 1 return the order a1

Page 5: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

CorrectnessInput: a1, a2, …, an Output: Numbers in sorted order

MergeSort( a, n )

aL = a1,…, an/2

aR = an/2+1,…, an

return MERGE ( MergeSort(aL, n/2), MergeSort(aR, n/2) )

By induction

on n

By induction

on n

Inductive step follows from correctness of MERGEInductive step follows from correctness of MERGE

If n = 1 return the order a1

Page 6: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Rest of today’s agenda

Analyze runtime of mergesort algorithm

Page 7: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

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

Page 8: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Improvements on a smaller scale

Greedy algorithms: exponential poly time

(Typical) Divide and Conquer: O(n2) asymptotically smaller running time

Page 9: Lecture 28 CSE 331 Nov 9, 2015. Mini project report due WED

Multiplying two numbers

Given two numbers a and b in binary

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

Compute c = a x bRunning time

of primary school

algorithm?

Running time of primary

school algorithm?