[英]Recurrence relation: T(n) = 2T(n/2) + log(n)
I have a recurrence relation which is like the following: 我有一个如下的递归关系:
T(n) = 2T(n/2) + log 2 n T(n)= 2T(n / 2)+对数2 n
I am using recursion tree method to solve this. 我正在使用递归树方法来解决此问题。 And at the end, i came up with the following equation: 最后,我想出了以下等式:
T(n)=(2log 2 n)(n-1)-(1*2 + 2*2 2 + ... + k*2 k ) where k=log 2 n. T(n)=(2log 2 n)(n-1)-(1 * 2 + 2 * 2 2 + ... + k * 2 k )其中k = log 2 n
I am trying to find a theta notation for this equation. 我正在尝试为该方程式找到theta表示法。 But i cannot find a closed formula for the sum (1*2 + 2*2 2 + ... + k*2 k ). 但是我找不到总和的封闭公式(1 * 2 + 2 * 2 2 + ... + k * 2 k )。 How can i find a big theta notation for T(n)? 如何找到T(n)的大theta表示法?If you know some calculus you should be able to solve that easily. 如果您知道一些演算,您应该可以轻松解决。
1 + x + x^2 + ... + x^(n+1) = (x^(n+2) - 1) / (x - 1) 1 + x + x ^ 2 + ... + x ^(n + 1)=(x ^(n + 2)-1)/(x-1)
Multiplying by x, x + x^2 + x^3 + ... + x^(n + 2) = (x^(n + 3) - x) / (x - 1) 乘以x,x + x ^ 2 + x ^ 3 + ... + x ^(n + 2)=(x ^(n + 3)-x)/(x-1)
Differentiating the LHS will give you your series for x = 2. Differentiating the RHS will give you the closed form. 区分LHS将为您提供x = 2的序列。区分RHS将为您提供封闭形式。
您应该使用主定理来计算您的复杂度,这会容易得多。
I suppose you are doing some mistake, as per my calculations: 根据我的计算,我想您在犯一些错误:
T(n)=(k-1)*log(n/(2^(k-1)))+2^k*T(n/2^k). T(N)=(K-1)*的log(n /(2 ^(K-1)))+ 2 ^ K * T(N / 2 ^ K)。
Put k=log(n) 放k = log(n)
I can post an image of my solution if you like. 如果您愿意,我可以发布解决方案的图片。 :) :)
These recurrence can be solved with a masters theorem . 这些复发可以用一个大师定理解决。 In your case a = 2
, b = 2
and therefore c = logb(a) = 1
. 在您的情况下, a = 2
, b = 2
,因此c = logb(a) = 1
。
Your f(n) = log n
and because n^c
grows faster than your f
, it dominates the solution and you fall in the first case. 您的f(n) = log n
并且因为n^c
增长快于f
,所以它主导了解决方案,您陷入了第一种情况。 So the complexity is O(n)
. 因此复杂度为O(n)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.