note03 - Outline 1 2 3 4 5 6 7 8 Divide and Conquer...

Info icon This preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Outline 1 Divide and Conquer Strategy 2 Master Theorem 3 Matrix Multiplication 4 Strassen’s MM Algorithm 5 Complexity of a Problem 6 Selection Problem 7 Summary 8 Computational Geometry c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 1 / 55
Image of page 1

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

View Full Document Right Arrow Icon
Divide and Conquer Strategy (1) a c b t s (2) c s b a t s* t* c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 2 / 55
Image of page 2
Algorithm design is more an art, less so a science.
Image of page 3

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

View Full Document Right Arrow Icon
Merge Sort MergeSort Input: an array A [ 1 .. n ] Output: Sort A into increasing order. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 55
Image of page 4
Merge Sort MergeSort Input: an array A [ 1 .. n ] Output: Sort A into increasing order. Use a recursive function MergeSort( A , p , r ) . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 55
Image of page 5

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

View Full Document Right Arrow Icon
Merge Sort MergeSort Input: an array A [ 1 .. n ] Output: Sort A into increasing order. Use a recursive function MergeSort( A , p , r ) . It sorts A [ p .. r ] . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 55
Image of page 6
Merge Sort MergeSort Input: an array A [ 1 .. n ] Output: Sort A into increasing order. Use a recursive function MergeSort( A , p , r ) . It sorts A [ p .. r ] . In main program, we call MergeSort( A , 1 , n ) . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 55
Image of page 7

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

View Full Document Right Arrow Icon
Merge Sort MergeSort( A , p , r ) 1: if ( p < r ) then 2: q = ( p + r ) / 2 3: MergeSort( A , p , q ) 4: MergeSort( A , q + 1 , r ) 5: Merge( A , p , q , r ) 6: else 7: do nothing 8: end if c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 55
Image of page 8
Merge Sort MergeSort( A , p , r ) 1: if ( p < r ) then 2: q = ( p + r ) / 2 3: MergeSort( A , p , q ) 4: MergeSort( A , q + 1 , r ) 5: Merge( A , p , q , r ) 6: else 7: do nothing 8: end if Divide A [ p .. r ] into two sub-arrays of equal size . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 55
Image of page 9

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

View Full Document Right Arrow Icon
Merge Sort MergeSort( A , p , r ) 1: if ( p < r ) then 2: q = ( p + r ) / 2 3: MergeSort( A , p , q ) 4: MergeSort( A , q + 1 , r ) 5: Merge( A , p , q , r ) 6: else 7: do nothing 8: end if Divide A [ p .. r ] into two sub-arrays of equal size . Sort each sub-array by recursive call. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 55
Image of page 10
Merge Sort MergeSort( A , p , r ) 1: if ( p < r ) then 2: q = ( p + r ) / 2 3: MergeSort( A , p , q ) 4: MergeSort( A , q + 1 , r ) 5: Merge( A , p , q , r ) 6: else 7: do nothing 8: end if Divide A [ p .. r ] into two sub-arrays of equal size . Sort each sub-array by recursive call. Merge( A , p , q , r ) is a procedure that, assuming A [ p .. q ] and A [ q + 1 .. r ] are sorted, merge them into sorted A [ p .. r ] It can be done in Θ( k ) time where k = r - p is the number of elements to be sorted. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 55
Image of page 11

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

View Full Document Right Arrow Icon
Analysis of MergeSort Let T ( n ) be the runtime function of MergeSort( A [ 1 .. n ] ). Then: T ( n ) = O ( 1 ) if n = 1 2 T ( n / 2 ) + Θ( n ) if n > 1 c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 5 / 55
Image of page 12
Analysis of MergeSort Let T ( n ) be the runtime function of MergeSort( A [ 1 .. n ] ). Then: T ( n ) = O ( 1 ) if n = 1 2 T ( n / 2 ) + Θ( n ) if n > 1 If n = 1 , MergeSort does nothing, hence O ( 1 ) time.
Image of page 13

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

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the 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