Divide-and-conquer theorem

In general, the time complexity of divide-and-conquer algorithms is determined by 3 things: the number and size of the subproblems, and the amount of work needed to bring them together.

If a problem of size n is divided into a problems each of size n/c, and it takes bn work to bring together the solutions of the subproblems, then

        T(n) = aT(n/c) + bn, when n > 1
        T(n) = b, when n = 1

For real problems, a,b,c are non-negative.   In this case, when n is a power of c, we have...

D&C Theorem

        T(n) = Θ( n ) , when a < c
        T(n) = Θ( n log n ) , when a = c
        T(n) = Θ( nlogca ), when a > c 

Proof of the D&C Theorem

Let n = cm, and therefore m = logcn.  By expanding the recurrence, we get:

T(n) = aT(n/c) + bn
        = a[aT(n/c2) + b(n/c)] + bn
        = a2T(n/c2) + bn[1 + a/c]
        = a2[aT(n/c3) + b(n/c2)] + bn[1 + a/c]
        = a3T(n/c3) + bn[1 + a/c + (a/c)2]
        . . .
        = amT(n/cm) + bn[1 + a/c + (a/c)2 + ... + (a/c)m-1]
( Note that T(1) = b and that amb = amb(n/cm) = bn(a/c)m. )
        = bn[1 + a/c + (a/c)2 + ... + (a/c)m].

Therefore, T(n) = bni = 0 to logcn (a/c)i.

  1. When a < c, the summation converges to be less than 2, and so T(n) = O(n).
  2. When a = c, each term in the summation is 1 and there are O(log n) terms. Therefore, T(n) = O(n log n).
  3. When a > c, we have a finite divergent series.
    T(n) =   [ bn - bn(a/c)m+1 ] /( 1 - a/c )
            =   [ bn(a/c)m+1 - bn ] /( a/c - 1 )
            <   [ (a/c)bn(a/c)m ] /( a/c - 1 )     =   [ b / (1 - c/a) ]am

    Thus, T(n) = O(am).   Also, from above we have that T(n) = Ω(am).
    Therefore, T(n) = Θ(am).

    Since am = alogcn = nlogca, we conclude that T(n) = Θ( nlogca ).

D&C Theorem when n is not a power of c

The underlying problem can be padded to make a larger-sized problem having the same solution.
We will show that
    T(n) ≤ a(nk), for some constant a, when n = cm (for integer m)
implies
    T(n) ≤ b(nk), for some constant b, for any n (not just integer powers of c).

Proof. Let n = r cm, for 1 < r < c.
Then T(n) ≤ T(cm+1) ≤ a(cm+1)k = a((c/r)n)k = a(c/r)knk
Finally, note that b = a(c/r)k is a constant.

The Master D&C Theorem

(generalized slightly from CLR page 94)

If T(n) = aT(n/b) + f(n),
                where a ≥ 1,   b > 1,   f(n) asymptotically > 0,
                and n/b means either the floor or ceiling of (n/b)

then T(n) =
        Θ( nlogba ), when f(n) = O ( nlogba-ε )
        Θ( nlogba logk+1n ), when f(n) = Θ( nlogba logkn ), for k ≥ 0
        Θ( f(n)  ), when f(n) = Ω( nlogba )
and af(n/b) ≤ cf(n), for some c < 1, for all n > n0


Dan Hirschberg
Last modified: Feb 19, 2004