码迷,mamicode.com
首页 > 其他好文 > 详细

master theorem

时间:2017-06-04 00:16:16      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:constant   first   ddc   include   work   ext   media   end   wiki   

The master theorem concerns recurrence relations of the form:

{\displaystyle T(n)=a\;T\!\left({\frac {n}{b}}\right)+f(n)}技术分享 where {\displaystyle a\in \mathbb {N} {\mbox{, }}1<b\in \mathbb {R} }技术分享

In the application to the analysis of a recursive algorithm, the constants and function take on the following significance:

  • n is the size of the problem.
  • a is the number of subproblems in the recursion.
  • n/b is the size of each subproblem. (Here it is assumed that all subproblems are essentially the same size.)
  • f (n) is the cost of the work done outside the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions to the subproblems.

It is possible to determine an asymptotic tight bound in these three cases:

Case 1

Generic form

技术分享 where 技术分享 (using big O notation)

then:

技术分享

Example

技术分享

As one can see from the formula above:

技术分享, so
技术分享, where {\displaystyle c=2}技术分享

Next, we see if we satisfy the case 1 condition:

技术分享.

It follows from the first case of the master theorem that

技术分享

(indeed, the exact solution of the recurrence relation is 技术分享, assuming技术分享).

Case 2

Generic form

If it is true, for some constant k ≥ 0, that:

技术分享 where 技术分享

then:

技术分享

Example

技术分享

As we can see in the formula above the variables get the following values:

技术分享
技术分享 where {\displaystyle c=1,k=0}技术分享

Next, we see if we satisfy the case 2 condition:

技术分享, and therefore, {\displaystyle c=\log _{b}a}技术分享

So it follows from the second case of the master theorem:

技术分享

Thus the given recurrence relation T(n) was in Θ(n log n).

(This result is confirmed by the exact solution of the recurrence relation, which is技术分享, assuming 技术分享.)

Case 3

Generic form

If it is true that:

技术分享 where {\displaystyle c>\log _{b}a}技术分享

and if it is also true that:

技术分享 for some constant {\displaystyle k<1}技术分享 and sufficiently large 技术分享 (often called the regularity condition)

then:

技术分享

Example

技术分享

As we can see in the formula above the variables get the following values:

技术分享
技术分享, where {\displaystyle c=2}技术分享

Next, we see if we satisfy the case 3 condition:

技术分享, and therefore, yes, {\displaystyle c>\log _{b}a}技术分享

The regularity condition also holds:

技术分享, choosing技术分享

So it follows from the third case of the master theorem:

技术分享

Thus the given recurrence relation T(n) was in Θ(n2), that complies with the f (n) of the original formula.

(This result is confirmed by the exact solution of the recurrence relation, which is 技术分享, assuming 技术分享.)

 

 

from wikipedia

---------------------------------------------------------------------------------------------------------------------------------------------

it means lim(n->Infinity)(f(n)/n^(b lg a)) should  1. ->Infinity && f(n)/n^(b lg a)    2. (f(n)/n^(b lg a)< n^x for x>0.

if 1 but not 2 can‘t use the method.  as f(n)/n^(b lg a) = n*lgn/n = lgn. 

master theorem

标签:constant   first   ddc   include   work   ext   media   end   wiki   

原文地址:http://www.cnblogs.com/wujunde/p/6938869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!