0% found this document useful (0 votes)
27 views8 pages

1.5 Recursion

The document discusses the Master Theorem for analyzing the time complexity of recursive functions. It presents the three cases of the Master Theorem for solving T(n) = aT(n/b) + f(n): 1) If f(n) = O(n^logba-ε), then T(n) = Θ(n^logba) 2) If f(n) = Θ(n^logba), then T(n) = Θ(n^logba log n) 3) If f(n) = Ω(n^logba+ε), then T(n) = Θ(f(n)) It then works

Uploaded by

kriti jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views8 pages

1.5 Recursion

The document discusses the Master Theorem for analyzing the time complexity of recursive functions. It presents the three cases of the Master Theorem for solving T(n) = aT(n/b) + f(n): 1) If f(n) = O(n^logba-ε), then T(n) = Θ(n^logba) 2) If f(n) = Θ(n^logba), then T(n) = Θ(n^logba log n) 3) If f(n) = Ω(n^logba+ε), then T(n) = Θ(f(n)) It then works

Uploaded by

kriti jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Recursion-II

DR. SHWETA SHARMA


Master Theorem
T(n) = aT(n/b) + f(n)

where, T(n) has the following asymptotic bounds:

1. If f(n) = O (nlogba-ϵ), then T(n) = Θ(nlogb a)

2. If f(n) = Θ (n logba), then T(n) = Θ(nlogba log n)


𝑛
3. If f(n) = Ω (n logba+ϵ), and if ϵ > 0 is a constant and if a f( ) <= c f(n)
𝑏
for some constant c< 1, then T(n) = Θ(f(n))

DR. SHWETA SHARMA, PEC CHANDIGARH 2


Ques 1
𝑛 a=2, b=2, f(n)=n
T(n) = 2T ( ) +n
2
Find nlogba
Ans: nlog2n = nlog22
=n

Case2:
Θ(nlogba log n)
=Θ(nlog n)
DR. SHWETA SHARMA, PEC CHANDIGARH 3
Ques 2
𝑛
a=4, b=2, f(n)=n
T(n) = 4T ( ) +n
2
Find nlogba
Ans: n2 = nlog24
=n2 =n2-ϵ
Case1:
Θ(nlogba)
=Θ(n2)

DR. SHWETA SHARMA, PEC CHANDIGARH 4


Ques 3
a=16, b=4, f(n)=n3
𝑛
T(n) = 16T ( ) +n3 Find nlogba
4
= nlog416
Ans: n3 =n2 =n2+ϵ
Case3:
𝑛 𝑛 3 1
a f( )
= 16 = n3
𝑏 4 4
c<1
Θ(f(n))= Θ(n3)
DR. SHWETA SHARMA, PEC CHANDIGARH 5
Ques 4
𝑛
T(n) = 49T ( ) +n
7

Ans: n2

DR. SHWETA SHARMA, PEC CHANDIGARH 6


Ques 5
𝑛
T(n) = 2T ( ) +logn
2

Can’t implement Master’s Theorem

DR. SHWETA SHARMA, PEC CHANDIGARH 7


Thank you!

DR. SHWETA SHARMA, PEC CHANDIGARH 8

You might also like