Professional Documents
Culture Documents
BY MASTER METHOD
ALGORITHM DESIGNING APPROACH
There are two approaches which can be used to write
algorithms:
(1) if n c
T ( n)
aT n / b D ( n) C (n) otherwise
SOLVING RECURRENCES
Hence, solving recurrences means finding the
asymtotic bounds (big-O, big-Ω, and big-Θ)
for the function T(n).
SOLVING RECURRENCES
Recursion-tree method converts recursion into a
tree whose nodes represent the “subproblems” and
their costs.
Substitution method – we guess a bound and then
use mathematical induction to prove our guess.
Master method provides bounds for recurrences
of the form :
T (n) aT (n / b) f (n); a 1, b 1
f (n) is a given function
RECURSION TREE METHOD
T (n) aT (n / b) f (n); a 1, b 1
logb a
n
if f (n) O n
logb a
0
logb a c 1
T (n) n lg n if f (n) n
logb a
a 1
b 1
f ( n)
if f (n) n
logb a
AND
af (n / b) cf (n) for large n
EXAMPLE : USING THE MASTER
METHOD
T(n)
= 9T(n/3) + n
a=9, b=3, f(n) = n
nlog a = nlog 9 = n2
b 3
T (n) n logb a when f (n) O n logb a
T(n) = 2T(n/2) + n
USING THE MASTER METHOD
T(n) = 2T(n/2) + n
USING THE MASTER METHOD
T(n)= 16T(n/4) + n!
a=16, b=4 f(n) = n!
T(n)= 16T(n/4) + n!
a=16, b=4 f(n) = n!
(nlog 16 ) = (n2 )
4
T(n)= 16T(n/4) + n!
a=16, b=4 f(n) = n!
Ω (nlog 16 + ) = Ω (n2+ )
4