0% found this document useful (0 votes)
104 views5 pages

CSE-304 Design & Analysis of Algorithm: Recurrence Relation

This document discusses the Master Method for solving recurrence relations of the form T(n) = aT(n/b) + f(n). It presents the three cases of the Master Theorem and provides examples of applying each case to solve recurrence relations. The Master Method allows solving recurrences in a "cookbook" approach by memorizing the three cases.

Uploaded by

Rita Miller
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
104 views5 pages

CSE-304 Design & Analysis of Algorithm: Recurrence Relation

This document discusses the Master Method for solving recurrence relations of the form T(n) = aT(n/b) + f(n). It presents the three cases of the Master Theorem and provides examples of applying each case to solve recurrence relations. The Master Method allows solving recurrences in a "cookbook" approach by memorizing the three cases.

Uploaded by

Rita Miller
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 5

CSE-304

Design & Analysis of Algorithm

Lecture 20
Recurrence Relation
The Master Method
• Based on the Master theorem.
• “Cookbook” approach for solving recurrences of
the form
T(n) = aT(n/b) + f(n)
• a  1, b > 1 are constants.
• f(n) is asymptotically positive.
• n/b may not be an integer, but we ignore floors and ceilings.
• Requires memorization of three cases.
The Master Theorem
Theorem
Theorem4.14.1
Let a  11 and
Leta and bb >> 11be beconstants,
constants,letletf(n)
f(n)be
beaafunction,
function,and
and
Let
LetT(n)
T(n)be
bedefined
definedononnonnegative
nonnegativeintegers
integersby bythe
therecurrence
recurrence
T(n)
T(n)==aT(n/b)
aT(n/b)++f(n),
f(n),where
wherewewecan
canreplace
replacen/b byn/b
n/bby orn/b.
n/bor n/b.
T(n)
T(n)can
canbebebounded
boundedasymptotically
asymptoticallyininthree
threecases:
cases:
1.1. IfIf f(n)
f(n)==O(n
O(nlogba–)) for
forsome constant>>0,0,then
someconstant T(n)==(
thenT(n) (nnloglogbab).a).
logba–

f(n)==
2.2. IfIf f(n) (n(nloglogloga+ T(n)==(
(nnloglogbablg
ba),
ba),then
thenT(n) a n).
lg n).
f(n)==(n
3.3. IfIf f(n) (nlogba+)) for forsome constant>>0,0,
someconstant
b

and
andif,if,for
forsome someconstant
constantcc<<11and
andall allsufficiently
sufficientlylarge
largen,n,
we
wehave a·f(n/b)ccf(n),
havea·f(n/b) f(n),then T(n)==
thenT(n) (f(n)).
(f(n)).
Master Method – Examples
• T(n) = 16T(n/4)+n
– a = 16, b = 4, nlogba = nlog416 = n2.
– f(n) = n = O(nlogba-) = O(n2- ), where  = 1  Case 1.
– Hence, T(n) = (nlogba ) = (n2).

• T(n) = T(3n/7) + 1
– a = 1, b=7/3, and nlogba = nlog 7/3 1 = n0 = 1
– f(n) = 1 = (nlogba)  Case 2.
– Therefore, T(n) = (nlogba lg n) = (lg n)
Master Method – Examples
• T(n) = 3T(n/4) + n lg n
– a = 3, b=4, thus nlogba = nlog43 = O(n0.793)
– f(n) = n lg n = (nlog43 +  ) where   0.2  Case 3.
– Therefore, T(n) = (f(n)) = (n lg n).

• T(n) = 2T(n/2) + n lg n
– a = 2, b=2, f(n) = n lg n, and nlogba = nlog22 = n
– f(n) is asymptotically larger than nlogba, but not
polynomially larger. The ratio lg n is asymptotically
less than n for any positive . Thus, the Master
Theorem doesn’t apply here.

You might also like