1 / 28

CS 312: Algorithm Analysis

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License . CS 312: Algorithm Analysis. Lecture #9: Solving Divide and Conquer Recurrence Relations with Change of Variable. Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick.

kalani
Download Presentation

CS 312: Algorithm Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. CS 312: Algorithm Analysis Lecture #9: Solving Divide and Conquer Recurrence Relations with Change of Variable Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick

  2. Announcements • HW #6 Due Today • Questions about Non-homogeneous RR? • Project #2 • Questions? • Early Day: Wednesday • Due: Friday

  3. Objectives • Understand how to analyze recurrence relations that are typical of divide and conquer algorithms • Learn to use the “change of variable” technique to solve such recurrences • Review Merge sort (quickly!) • Theoretical analysis using RRs • Time permitting, prove the Master theorem

  4. Divide and Conquer

  5. Analysis Approach: Reduction Divide and Conquer Recurrence Relation Change of Variable Non-Homogeneous Recurrence Relation with Geometric Forcing Function LTI Homogeneous Recurrence Relation

  6. Analysis of Binary Search

  7. Analysis Approach: Reduction Divide and Conquer Recurrence Relation Change of Variable Non-Homogeneous Recurrence Relation with Geometric Forcing Function “Unwindthe Stack” LTI Homogeneous Recurrence Relation

  8. Analysis of Binary Search (cont.)

  9. 3 1 4 1 5 9 2 6 5 3 5 8 9 3 1 4 1 5 9 2 6 5 3 5 8 9 2 3 5 5 6 8 9 1 1 3 4 5 9 1 1 2 3 3 4 5 5 5 6 8 9 9 Review: Merge sort • Split the array in 1/2 • Sort each 1/2 • Merge the sorted halves • Adhoc(): Use insertion sort when sub-arrays are small

  10. 3 1 4 1 5 9 2 6 5 3 5 8 9 3 1 4 1 5 9 2 6 5 3 5 8 9 2 3 5 5 6 8 9 1 1 3 4 5 9 1 1 2 3 3 4 5 5 5 6 8 9 9 Analysis of merge() proceduremerge (U[1..p+1], V[1..q+1], A[1..n]) i,j 1 U[p+1],V[q+1]  sentinel for k  1 top+qdo if U[i] < V[ j] then A[k]  U[i]; i  i + 1 else A[k]  V[j]; j  j + 1 How long to merge? U V A

  11. Merge sort proceduremergesort (A[1..n]) if n is small enough theninsertsort (A) else array U[1..1+floor(n/2)], V[1..1+ceil(n/2)] U[1..floor(n/2)]  A[1..floor(n/2)] V[1..ceil(n/2)]  A[1+floor(n/2)..n] mergesort (U) mergesort (V) merge (U,V,A) What is the efficiency of Mergesort?

  12. Merge sort

  13. Using the Master Theorem a = number of sub-instances that must be solved n = original instance size (variable) n/b = size of subinstances d = polynomial order of g(n), where g(n) = cost of dividing and recombining

  14. Efficiency of Mergesort

  15. Another Useful Logarithm Identity Proof: Statement Reason • and are inverses • commutativity of • and are inverses

  16. (Sketch of the)Proof of the Master Theorem How to proceed?

  17. Proof of the Master Theorem

  18. Proof of the Master Theorem

  19. Proof: case 1

  20. Proof: case 2

  21. Proof: case 2

  22. Proof: Conclusion

  23. Proof: Conclusion

  24. Assignment • Read: Section 2.3 in the textbook • HW #7: • Part III Exercises (Section 3.2) • Analyze 3-part mergesort using recurrence relations techniques • Problem 2.4 in the textbook (using the master theorem where possible)

More Related