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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern