Sie sind auf Seite 1von 2

COMP2211Analysis of Algorithms, Sem II, 2016Tutorial 4

UNIVERSITY OF THE WEST INDIES


Department of Computing
COMP2211Analysis of Algorithms
Sem II, 2016
Lecturer(s): Daniel Coore
Tutorial 4

Solving Recurrences
Summary
Recursion Trees
Using the Master Theorem

Solving Recurrences
Recall that from the previous tutorial, we had analysed the implementations of four functions called
f1, f2, f3, f4 to obtain recurrence relations for functions representing their time complexities.
These functions were called T1 (n), T2 (n), T3 (n), T4 (n), respectively. The recurrences obtained were:

T1 (n) =

1
ifn = 0
4 + T1 (n 1) if n > 0

T2 (n) =

1
ifn = 0
5 + 2T2 (n 1) if n > 0

T3 (n) =

1
ifn = 0
4 + T3 (n 1) if n > 0

T4 (n) =

1 + T2 (n)
ifn = 0
3 + T1 (n) + T4 (n/2) if n > 0

Now we turn our attention to obtaining closed forms for each of those functions by using a recursion
tree to solve each.
Remember that our primary objective is to obtain an order of growth, rather than an exact function.
Therefore if a sum becomes tedious, it is acceptable to ignore details that will not change its order
of growth, but that will simplify the computation of the recursion tree.
1. Explain how it might be possible that two algorithms have identical time complexity functions
(not just orders of growth), and yet their actual running times, measured in seconds, may
differ.
2. Use a recursion tree to obtain the order of growth of each of T1 , T2 , T3 .

COMP2211Analysis of Algorithms, Sem II, 2016Tutorial 4

3. Although f1, f2 and f3 all compute the same function, their time complexities do not all have
the same order of growth. Explain what about the way that they have been implemented has
determined this difference.
4. Use your solutions to T1 , T2 , T3 in order to solve the recurrence relation defining T4 .

Master Theorem
Assume that T (n) = 1 for n 1, and that for n > 1, T (n) is governed by the expression given in
a row of Table 1. For each expression in Table 1, fill out the value of the critical exponent, the
case of the Master Theorem that applies, and the final answer for T (n). If the Master Theorem is
inappropriate for the recurrence, put NA in the critical exponent column; if the Master Theorem
is appropriate, but fails to solve the recurrence, then put NA in the case column. (Optional: In
either of those cases, see whether you can determine the order of growth of T (n) anyway.)
Recurrence Expression
T (n) = 3T (n/2) + n
T (n) = 3T ((n 1)/2) + n2
T (n) = T ((n 1)/2) + lg n
T (n) = 2T (n/3) + lg n
T (n) = 4T ((n 2)/3) + n lg n
T (n) = T (n 1) + n
T (n) = 8T (n/2) + n3
T (n) = T (n 1/2) + n2

Case

Order of Growth

Table 1: Use the Master Theorem to solve the recurrences if possible. If not, then indicate it by
placing NA in the appropriate column, depending on the reason.

Das könnte Ihnen auch gefallen