Master Theorem

From Notes
Jump to navigation Jump to search

The master theorem provides a general boilerplate solution for solving recurrence relations (like divide and conquer algorithms) that satisfy a particular format.

Definition

Let f be an increasing function satisfying a recurrence relation:

f(n)=af(nb)+cnd

Whenever

  • n=bk for some k1, a1
  • b is an integer > 1
  • c and d are real numbers ≥ 0

Then

f(n)=af(nb)+cnd={Θ(nd)a<bdΘ(ndlogn)a=bdΘ(nlogba)a>bd

Proof

Proposition. If a=bd and n is a power of b, then a function f satisfying the recurrence relation f(n)=af(n/b)+cnd is of the form f(n)=f(1)nd+cndlogbn


Proof. Let k=logbn. Then

f(n)=cnd+ac(nb)d+a2c(nb2)d++ak1c(nbk1)d+akf(1)=akf(1)+j=0k1ajc(nbj)d=akf(1)+j=0k1cnd=akf(1)+kcnd=alogbnf(1)+c(logbn)nd=bdlogbnf(1)+c(logbn)nd=ndf(1)+c(logbn)nd=O(ndlogn)