The Master Theorem(s)

Master Theorem Subtract-and-Conquer

Given the recurrence T(n)= \begin{cases} g(n) & \text{if } 0\leq n < n_0\ ,\\ a\cdot T(n-b)+ f(n) &\text{if } n \geq n_0\ , \end{cases} with a,b, n_0, \gamma all non-negative constants, g an arbitrary function and f(n)=\Theta(n^\gamma), the closed form of T is

T(n)= \begin{cases} \Theta(n^\gamma) &\text{if } a < 1\ ,\\ \Theta(n^{\gamma+1})&\text{if } a = 1\ ,\\ \Theta(a^{n/b})&\text{if } a > 1\ . \end{cases}

Master Theorem Divide-and-Conquer

Given the recurrence T(n)= \begin{cases} g(n) & \text{if } 0\leq n < n_0\ ,\\ a\cdot T\left(\frac{n}{b}\right)+ f(n) &\text{if } n \geq n_0\ , \end{cases} with a\geq 1,b> 1, n_0, \gamma all non-negative constants, g an arbitrary function and f(n)=\Theta(n^\gamma), the closed form of T is

T(n)= \begin{cases} \Theta(n^\gamma) &\text{if $a<b^\gamma$ (equivalently, $\log_b a <\gamma$)}\ ,\\ \Theta(n^{\gamma}\log n)&\text{if $a=b^\gamma$ (equivalently, $\log_b a =\gamma$)}\ ,\\ \Theta(a^{\log_b n})=\Theta(n^{\log_b a})&\text{if $a>b^\gamma$ (equivalently, $\log_b a >\gamma$)}\ . \end{cases}

The statement above still holds if instead of \frac{n}{b} in the recurrence, there is any function in \frac{n}{b}+O(1), for instance \lceil \frac{n}{b}\rceil or \lfloor \frac{n}{b}\rfloor.1

In particular, the recurrence giving the worst case running time of the MergeSort algorithm, i.e.

T(n)=T\left(\left\lfloor\frac{n}{2}\right\rfloor\right)+T\left(\left\lceil\frac{n}{2}\right\rceil\right)+\Theta(n)

and the recurrence

S(n)=2S\left(\frac{n}{2}\right)+\Theta(n)

both have the same solution, i.e. T(n)=S(n)=\Theta(n\log n). Btw, no comparison-based sorting algorithm could have a wort case running time better than \Theta(n\log n).

Footnotes

  1. This is a consequence of the Akra-Bazzi Theorem, a generalization of the Master Theorem used to handle much more general forms of recurrences.↩︎