[英]How to solve recurrence relation
algorithm img is here!算法img来了!
sample(A[], p, r)
{
if(p=r) return 1;
sum = 0;
for(int i = 1; i < n(?); i++)
sum = sum + A[i];
int q = (p+r)/2;
int t = sum + sample(A,p,q) + sample(A, q+1, r);
return t;
}
I use iteration method to solve this question in image.我使用迭代方法来解决图像中的这个问题。 that code is right?
那个代码是对的吗? i can't make recurrence relation.
我无法建立递归关系。 maybe T(n) = T...?
也许 T(n) = T...? where is "n"
“n”在哪里
You are breaking the size of recursion by factor 2, and also have a loop with n
iteration.您将递归的大小打破了 2 倍,并且还有一个带有
n
次迭代的循环。 Hence, asymptotically, T(n) = 2T(n/2) + n = Theta(n log(n))
.因此,渐近地,
T(n) = 2T(n/2) + n = Theta(n log(n))
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.