MAZ - Recurrences
MAZ - Recurrences
two steps
guess the form of the solution
use mathematical induction to find the constants and show that the
solution works
can be applied when it is easy to guess the form of the answer
can be used to establish either upper or lower bounds on a recurrence
say, determine an upper bound on the recurrence
T (n) = 2T (bn/2c) + n
it holds when c ≥ 1
need to show it also holds for boundary conditions
for n = 1 T (1) = 0 which is at odds with T (1) = 1; base case fails
requires to prove T (n) ≤ cn lg n for n ≥ n0
appropriate value of c and n0 must be chosen, here c ≥ 2 and
n ≥ n0 (= 2)
T (2m ) = 2T (2m/2 ) + m
S(m) = 2S(m/2) + m
assume n is power of 4
cn2 term at the root represents the cost at the top level of recursion
three subtrees of the root represent the cost incurred by the
subproblems of size n/4
continue expanding each node in the tree by breaking it into its
constituent parts determined by the recurrence
subproblem sizes decrease as move further from the root, must reach
a boundary condition
the subproblem size for a node at depth i is n/4i
the subproblem size hits n = 1 when n/4i = 1 or when i = log4 n
tree has log4 n + 1 levels (0, 1, 2, . . . , log4 n)
the cost at each level of tree has three times more nodes than the
level above
the number of nodes at depth i is 3i
subproblem sizes reduce by a factor of 4 for each level move down
from the root
each node at depth i (i = 0, 1, 2, . . . , log4 n − 1) has cost of c(n/4i )2
cn2
.↓&
c( n4 )2 c( n4 )2 c( n4 )2
.↓& .↓& .↓&
n n n n n n n n
T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 )
.↓& .↓& .↓& .↓& .↓& .↓& .↓& .↓&
.. .. .. .. .. .. .. .. .. .. .. ..
............
T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1) T (1)
last formula looks messy, take advantage of small amounts of
sloppiness
log4 n−1
3 i 2
X
T (n) = cn + Θ(nlog4 3 )
16
i=0
∞
3 i 2
X
< cn + Θ(nlog4 3 )
16
i=0
1
= cn2 + Θ(nlog4 3 )
1 − (3/16)
16 2
= cn + Θ(nlog4 3 ) = O(n2 )
13