This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Recurrences David Kauchak Recurrence: a function that is defined with respect to itself on smaller inputs. • Why are we concerned with recurrences? The computational costs of divide and conquer algorithms and, in general, recurive algorithms, can often be described easily using recur- rences. • The problem? Recurrences are easy to define, but they don’t readily express the actual computational cost of the algorithm. We want to remove the self-recurrence and determine a more understandable form of the func- tion. • The methods Each approach will provide you with a different way for analyzing re- currences. Depending on the situation, one or more of the approaches may be applicable. – Substitution method: When we have a good guess of the solution, we start with that then prove that it is correct – Recursion-tree method: If we don’t have a good guess of the solution, looking at the recursion tree can help us. Then, we prove it is correct with the substitution method. – Master method: Provides solutions for recurrences of the form: T ( n ) = aT ( n/b ) + f ( n ) • The substitution method: Guess the form of the solution. Assume it’s correct and show that the solution is appropriate using a proof by induction. 1 – T ( n ) = braceleftBigg d if n = 1 T ( n ) = T ( n/ 2) + d otherwise Halves the input at each iteration and does a constant amount of work, e.g. binary search - Guess: O (log 2 n ) To show that T ( n ) = O (log 2 n ), we need to find constants c and n such that...
View Full Document
- Summer '09
- Algorithms, Recurrence relation, Introduction to Algorithms, Charles E. Leiserson