Recurrence Relations
Usually we'll deal with work functions that tell us something about how much
work T(n) an algorithm A does depending on the size n of the problem.
Typically T(n) will denote the amount of work done by A, in the worst case, on
a problem of size n or less. In addition, we'll assume T(n) > 0 for all n >
0.
Suppose n = 2m
Suppose also, for some positive constant c and integer q > 2
(1) T(n) < qT(n/2) + cn
when n > 1 and
(2) T(1) = c
(An example of this would be where T(n) < 3T(n/2) + 8.75n for n > 1 and
T(1) = 8.75)
By line (1), T(2) < qT(1) + 2c, which by line (2) is cq+2c = c(q+2)
By line (1), T(4) < qT(2) + 4c < q(c(q+2)) + 4c
= c(q2+2q+4)
By line (1), T(8) < qT(4) + 8c < q(c(q2+2q+4)) + 8c
= c(q3+2q2+4q+8)
So we see there is a pattern:
T(2m) < c(qm + 2qm-1 + ...
+ 2m-1q + 2m)
That is the same as:
T(2m) < c2m((q/2)m + (q/2)m-1 +
... + (q/2) + 1)
= c2m((q/2)m+1-1)/((q/2)-1)
(By the way, because q!=2, (q/2)-1 is not zero)
Now, c2m((q/2)m+1-1)/((q/2)-1) is
Θ(nrlog(n)), where r = q/2.
Also ... this may seem strange, but since
log(rlog(n)) = log(n)log(r) = log (nlog(r)),
we see that
rlog(n) = nlog(r) = nlog(q)-1
Therefore T(n) is O(nlog(q))
Since q > 2, O(nlog(q)) is "polynomial time".
So, for example, when q=4, that means log(q)=2 and T(n) is O(n2).
And if q=3, then log(q) is less than 1.59, so in that case T(n) is
O(n1.59)
Note that the calculation above is valid if q=1. When q=1 we find that
T(2m) < c(qm + 2qm-1 + ... + 2m-1q + 2m)
= c(1 + 2 + 4 + ... + 2m-1 + 2m) = c(2m+1-1)
= 2c(2m-(1/2)) = 2c(n-(1/2))
So it's clear that T(n) is O(n) when q=1.
When q=2, we can carry the derivation above to the point where we get:
T(2m) < c2m((q/2)m + (q/2)m-1 + ... + (q/2) + 1)
and at this point it becomes clear that
T(2m) < c2m(1m + 1m-1 + ... +
11 + 10)
and this just says that
T(2m) < c2m(1m + 1m-1 + ... +
11 + 10)
= c(m+1)2m
Since n=2m, this last expression is clearly O(nlog(n)).
Suppose we have a recurrence where n = 2m and for some positive
constant c
(3) T(n) < 2T(n/2) + cn2
when n > 1 and
(4) T(1) = c
In this case we have
T(2) < 2T(1) + c22 < c(2+22) = c(2+4)
T(4) < 2T(2) + c42 < 2c(2+22) + c42 = c(4+8+16)
T(8) < 2T(4) + c82 < 2c(4+8+16) + c64 = c(8+16+32+64)
The pattern developing is:
T(2m) < c(2m + 2m+1 + ...+
2m+m)
= c2m (1 + 2 + 4 + 8 + ...+ 2m) =
c2m(2m+1-1)
This is clearly O(n2).