Algo Mod5 Recurrences
Algo Mod5 Recurrences
ISSAM ALHADID
Modification date 25/2/2019
Running Time: O(n4)
???
???
Soln. ????
when an algorithm contains a recursive call to
itself, its running time can often be described
by a recurrence.
A recurrence is an equation or inequality
(variance ) that describes a function in terms
of its value on smaller inputs.
For example, we saw that the worst-case
running time T (n) of the MERGE-SORT
procedure could be described by the
recurrence
Merge sort
Iteration method:
◦ Expand the recurrence k times.
◦ Stop the recurrence at smallest value (0 or
1).
◦ Work some algebra to express as a
summation and solve the summation, if
any exist.
Given: a divide and conquer algorithm:
An algorithm that divides the problem of size
n into a sub-problems, each of size n/b.
Let the cost of each stage (i.e., the work to
divide the problem + combine solved sub-
problems) be described by the function f(n).
Examples….
if T(n) = aT(n/b) + f(n) where a ≥ 1 & b > 1
T(n) can be bounded asymptotically as follows:
ε: Epsilon
ε >0
The function divides the problem of size n into a
subproblems each of size n/b.
◦If f(n) falls into one of these gaps, the master method
cannot be used to solve the recurrence.
regulatory condition : is used to make sure that
the parent does at least as much as the children.
This says that f(n) (the amount of work done in
the root) needs to be at least as big as the sum
of the work done in the lower levels
But what if the function didn't fulfill the regularity
condition?
Ex. cos(n)*cos(n) instead of n*n?
Then the work done on the lower levels might be
bigger than the work done in the root so you are
not certain that the root dominates.
T(n) = 9T(n/3) + n
T(n) = T(2n/3) + 1
T(n) = 3T(n/4) + n lg n
T(n) = 2T(n/2) + n lg n
Example: T(n) = T(2n/3)+T(n/3)+n