简体   繁体   English

使用主定理解决分而治之的递归问题

[英]Solving recurrence of divide and conquer using master theorem

Can T(n) = 3T(n/2) + c T(1)=0, solved using master theorem? T(n) = 3T(n/2) + c T(1)=0 可以用主定理求解吗? If yes, I am struggling on understand master theorem now, could someone tell me which case it falls to and why.如果是的话,我现在正在努力理解主定理,有人能告诉我它属于哪种情况以及为什么。

There are different possible approaches for the master theorem.主定理有不同的可能方法。 I like the one proposed by Cormen et al.我喜欢 Cormen 等人提出的那个。 in their book Introduction to Algorithms .在他们的《算法导论》一书中。

  1. If f(n) = O(n^(log b (ae))) for some constant e>0, then T(n) = Θ(n^(log b (a)))如果 f(n) = O(n^(log b (ae))) 对于某个常数 e>0,则T(n) = Θ(n^(log b (a)))
  2. If f(n) = Θ(n^(log b (a))), then T(n) = Θ(n^(log b (a)). lg n)如果f(n) = Θ(n^(log b (a))),则T(n) = Θ(n^(log b (a)).lg n)
  3. If f(n) = Ω(n^(log b (a+e))) for some constant e>0, and if af(n/b) < c.f(n) for some constant c<1 and all sufficiently large n, then T(n) = Θ(f(n))如果 f(n) = Ω(n^(log b (a+e))) 对于某个常数 e>0,如果 af(n/b) < c.f(n) 对于某个常数 c<1 和所有n 足够大,则T(n) = Θ(f(n))

Now we need to compare f(n) with n^(log b (a)) .现在我们需要比较f(n)n^(log b (a))

  • if f(n) is polynomially smaller than n^(log b (a)) , it falls under the 1st case如果f(n)多项式小于n^(log b (a)) ,则属于第一种情况
  • if n^(log b (a)) is polynomially smaller than f(n) , it falls under the 3rd case如果n^(log b (a))多项式上小于f(n) ,则属于第三种情况
  • if f(n) and n^(log b (a)) are the same size, it falls under the 2nd case如果f(n)n^(log b (a))大小相同,则属于第二种情况

Note that the three cases do not cover all the possibilities for f(n).请注意,这三种情况并未涵盖 f(n) 的所有可能性。 There is a gap between cases 1 and 2 when f(n) is smaller than n^(log b (a)) but not polynomially smaller.当 f(n) 小于n^(log b (a))但不是多项式更小时,情况 1 和情况 2 之间存在差距。 Similarly, there is a gap between cases 2 and 3 when f(n) is larger than n^(log b (a)) but not polynomially larger.类似地,当 f(n) 大于n^(log b (a))但不是多项式更大时,情况 2 和情况 3 之间存在差距。 If the function f(n) falls into one of these gaps, or if the regularity condition in case 3 fails to hold, you cannot use the master method to solve the recurrence.如果 function f(n) 落入其中之一,或者情况 3 中的正则性条件不成立,则无法使用 master 方法求解递归。

Now to solve the recurrence in question...现在要解决有问题的复发......

a=3, b=2, f(n) = c = n^0 a=3, b=2, f(n) = c = n^0

so we have n^(log2(3)) ≈ n^(1.58) which is polynomially larger than n^0, falling under the 1st case.所以我们有 n^(log2(3)) ≈ n^(1.58) 多项式大于 n^0,属于第一种情况。 Then the time complexity is T(n) = Θ(n^(log b (a))) --> T(n) = Θ(n^1.58)那么时间复杂度就是T(n) = Θ(n^(log b (a))) --> T(n) = Θ(n^1.58)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM