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

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

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

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

View Full Document
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
Algorithm design is more an art, less so a science.

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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.

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.

{[ 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