Download presentation
Presentation is loading. Please wait.
Published byMoris Mitchell Modified over 8 years ago
1
CS 312: Algorithm Analysis Lecture #9: Recurrence Relations - Change of Variable Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License
2
Announcements HW #6 Due Today Questions about Non-homogeneous RR? Feedback from TAs: Be sure to justify your answers / show your work. Project #2 Quick questions? Definition of pseudo-code Early Day: Friday Due: Monday
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 Prove the Master theorem
4
Divide and Conquer
5
Analysis Approach Divide and Conquer Recurrence Relation Non-Homogeneous Recurrence Relation with Geometric Forcing Function LTI Homogeneous Recurrence Relation Change of Variable
6
Analysis of Binary Search
10
Analysis of Binary Search (cont.)
12
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
13
Analysis of merge() procedure merge (U[1..p+1], V[1..q+1], A[1..n]) i,j 1 U[p+1],V[q+1] sentinel for k 1 to p+q do if U[i] < V[ j] then A[k] U[i]; i i + 1 else A[k] V[j]; j j + 1 U A V How long to merge?
14
Analysis of merge() procedure merge (U[1..p+1], V[1..q+1], A[1..n]) i,j 1 U[p+1],V[q+1] sentinel for k 1 to p+q do if U[i] < V[ j] then A[k] U[i]; i i + 1 else A[k] V[j]; j j + 1 U A V How long to merge?
15
Merge sort procedure mergesort (A[1..n]) if n is small enough then insertsort (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?
16
Merge sort procedure mergesort (A[1..n]) if n is small enough then insertsort (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?
17
Merge sort
20
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
21
Efficiency of Mergesort
22
Proof of the Master Theorem How to proceed?
23
Proof of the Master Theorem
25
Proof: case 1
27
Proof: case 2
29
Proof: Conclusion
31
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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.