首页 > 其他 > 详细

Master Theorem

时间:2015-10-07 06:17:17      阅读:330      评论:0      收藏:0      [点我收藏+]

Master theorem provides a solution in asymptotic terms to solve time complexity problem of most divide and conquer algorithms.

Recurrence relations of the form:

T(n) = a T(n/b) + f(n) where a >= 1 and b > 1

Case 1:

f(n) = O(nc) where c < loga

Then: T(n) = Θ(nlogb a)

Case 2:

f(n) = Θ(nlogkn) where c = logb a
Then: T(n) = Θ(nc logk+1n)

Case 3:

f(n) = Ω(nc) where c > logb a

a f(n/b) <= k f(n) for some constant k < 1 and sufficiently large n

Then: T(n) = Θ(f(n)) 

 

Examples


 

 1. T(n) = 2 T(n/2) + n2

 a = 2, b = 2, f(n) = n -> c = 2 > logb a

And 2 (n2 / 4) <= k n2, choosing k = 1/2

2. Binary Search

T(n) = T(n/2) + O(1)

T(n) = O(log n)

 

3. Merge Sort

T(n) = 2 T(n/2) + O(n)

T(n) = O(n log n)

 

Notes


 

There are some conditions where we cannot apply master theorem.

1. a < 1 or b < 1

2. f(n) is not positive

3. f(n) = n / (log n)

Because 1/(log n) < nε for any constant ε > 0.

 

Master Theorem

原文:http://www.cnblogs.com/ireneyanglan/p/4858153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!