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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
Anonymous Feedback Form
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 )
Image of page 3

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

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

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

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

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

View Full Document Right Arrow Icon
Image of page 8
Image of page 9

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern