You are on page 1of 7

Divide and Conquer

In general, run time is T (n)=bT ( n )+ f (n)

b is number of subproblems

c is the subproblem size

f(n) is the non-recursive time to

Equation 3.8

divide into subproblems


merge subproblem solutions
combination of the two

Order of T(n) depends on the balance of work

how are nonrecursive cost distributed

cost of leaves

Critical Exponent

Recursion tree properties

lg (n)
base case (leaves) at depth D=
lg (c)
D
L=b
nodes (leaves) at depth D are
lg(b)
lg n
lg(c)

or in log form lg(L)=D lg(b)=

Coefficient is called the critical exponent

lg(b)
E=
lg(c)

Lemma 3.14

The number of leaves in the recursion tree for


Equation 3.8 is approximately L=n E where E is
the critical exponent definition is the previous
slide
Cost of recursion tree is at least L=n E

Lemma 3.15

With the previous notation


1)The recursion tree has depth
about that many row-sums

, so there are
D=lg (n)/lg(c)

2)The zeroth row-sum is F(n), the non-recursive cost of


the root
3)The Dth row-sum is n E, assuming the base cases cost
1 or (n E )
4)The value of T(n), the solution of Equation 3.8, is the
sum of the nonrecursive costs of all the nodes in the
tree, which is the sum of the row-sums

Theorem 3.16: Little Master


Theorem

Assuming the notation in previous slides and T(n)


defined in Equation 3.8

1)If the row-sums form an increasing geometric


series, then T (n)(n E )
2)If the row-sums remain about constant,
T (n)(f (n)log (n))

3)If the row-sums form a decreasing geometric


series, then T (n)(f (n)) (proportional to the nonrecursive costs.

Theorem 3.17: Master Theorem

The recurrence equation

n
T (n)=bT ( )+ f (n)
c

has forms of solution as follows:

1)If f (n)O(n E )for some positive then


T (n)(n E ) which is proporational to the number of leaves in the
recursion tree
E

2)If f (n)(n )for some positive

, then

T (n)(f (n)log (n))

as all node depths contribute about equally


3) If f (n)(n

E +

)for some positive , then


T (n)(f (n)) which is proportional to the nonrecursive cost at the

oot of the rcursion tree.

Chip and Conquer

T (n)=bT (nc)+f (n)

Since subproblem size decrease by a constant the tree depth is about D = n/c

Even if f(n) = 1
n/c

T (n)= b f (ncd )=b


d

d=0

n/ c

n/ c

f (ch)
bh
h=0

which is exponential in b

If b = 1 better case
n/c

n/c

T (n)= f (ncd)= f (ch)


d=0

If f(n) is polynomial

h=0

1
f ( x) dx

c 0

na then T (n)(n a+1 )