note03 - Outline 1 Divide and Conquer Strategy 2 Master...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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. 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 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 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 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....
View Full Document

This document was uploaded on 10/05/2010.

Page1 / 233

note03 - Outline 1 Divide and Conquer Strategy 2 Master...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online