Computer Sciences Department 1
Objectives
• Recurrences.
Substitution Method,
Recursion-tree method,
Master method
Computer Sciences Department 4
Recurrence
Computer Sciences Department 5
A recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs.
Example: MERGE-SORT procedure could be described by
the recurrence:
recurrence
Computer Sciences Department 6
Substitution Method,
Recursion-tree method,
Master method
Recurrence Methods
Computer Sciences Department 7
The substitution method for solving recurrences entails two steps: 1. Guess the form of the solution. 2. Use mathematical induction to find the
constants and show that the solution works. The substitution method can be used to
establish either upper or lower bounds on a recurrence.
The substitution method
Computer Sciences Department 8
Computer Sciences Department 9
As an example, let us determine an upper bound on the recurrence
lgn/2=lgn-lg2
Computer Sciences Department 10
A recursion tree is best used to generate a good guess, which is then verified by the substitution method.
Using recursion trees to generate good guesses.
The recursion-tree method
Computer Sciences Department 11
Solution
Computer Sciences Department 12
Solution
Computer Sciences Department 13
Solution
Computer Sciences Department 14
Solution
Computer Sciences Department 15
Solution
Computer Sciences Department 16
For example
We start by focusing on finding an upper bound for the solution.
create a recursion tree for the recurrence
we assume that n is an exact power of 4
Computer Sciences Department 17
Computer Sciences Department 18
Computer Sciences Department 19guess
Computer Sciences Department 20
Computer Sciences Department 21
The master method
Computer Sciences Department 22
Computer Sciences Department 23
and
and
Conditions of using the master method
1
2
3
5
4
and
Computer Sciences Department 24
Computer Sciences Department 25
?
Try
Computer Sciences Department 26
TRY (LAB)
Computer Sciences Department 27
Computer Sciences Department 28
Computer Sciences Department 29
Proof of the master theorem (no need)