CSE331 Lecture 29

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

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

Lecture 29 CSE 331 Nov 6, 2011

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

View Full Document
Anonymous Feedback Form
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 )

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

View Full Document
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
Run time recurrence T(n) c if n 2 2*T(n/2) + c*n otherwise

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

View Full Document
Today’s agenda Solve the recurrence Multiplying two integers
Divide and Conquer Divide up the problem into at least two sub-problems

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

View Full Document

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

View Full Document
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
Ask a homework question - tutors are online