CSE331 Lecture 29

CSE331 Lecture 29 - Recursively solve the sub-problems...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 29 CSE 331 Nov 6, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Anonymous Feedback Form
Background image of page 2
Mergesort algorithm Input: a 1 , a 2 , …, a n Output: Numbers in sorted order MergeSort ( a, n ) If n = 1 return the order a 1 a L = a 1 ,…, a [n/2] a R = a [n/2]+1 ,…, a n return MERGE ( MergeSort ( a L , [n/2] ), MergeSort ( a R , n-[n/2] ) ) If n = 2 return the order min(a 1 ,a 2 ); max(a 1 ,a 2 )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Correctness Input: a 1 , a 2 , …, a n Output: Numbers in sorted order MergeSort ( a, n ) If n = 2 return the order min(a 1 ,a 2 ); max(a 1 ,a 2 ) a L = a 1 ,…, a [n/2] a R = a [n/2]+1 ,…, a n return MERGE ( MergeSort ( a L , [n/2] ), MergeSort ( a R , n-[n/2] ) ) By inductio n on n By inductio n on n Inductive step follows from correctness of MERGE Inductive step follows from correctness of MERGE If n = 1 return the order a 1
Background image of page 4
Run time recurrence T(n) c if n 2 2*T(n/2) + c*n otherwise
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Today’s agenda Solve the recurrence Multiplying two integers
Background image of page 6
Divide and Conquer Divide up the problem into at least two sub-problems
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Recursively solve the sub-problems “Patch up” the solutions to the sub-problems for the final solution Improvements on a smaller scale Greedy algorithms: exponential poly time (Typical) Divide and Conquer: O(n 2 ) asymptotically smaller running time Multiplying two numbers Given two numbers a and b in binary a=(a n-1 ,..,a ) and b = (b n-1 ,…,b ) Compute c = a x b Running time of primary school algorithm? Running time of primary school algorithm? The current algorithm scheme Mult over n bits Mult over n bits Multiplication over n/2 bit inputs Multiplication over n/2 bit inputs Shift by O(n) bits Shift by O(n) bits Adding O(n) bit numbers Adding O(n) bit numbers T(n) ≤ 4 T(n/2) + cn T(1) ≤ c T(n) is O(n 2 ) T(n) is O(n 2 )...
View Full Document

This note was uploaded on 12/11/2011 for the course CSE 331 taught by Professor Rudra during the Fall '11 term at SUNY Buffalo.

Page1 / 10

CSE331 Lecture 29 - Recursively solve the sub-problems...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online