【发布时间】:2019-06-20 03:01:49
【问题描述】:
递归算法的时间复杂度为
Given a recursion algorithm, its time complexity O(T) is typically
the product of the number of recursion invocations (denoted as R)
and the time complexity of calculation (denoted as O(s))
that incurs along with each recursion
O(T) = R * O(s)
查看递归函数:
void algo(n){
if (n == 0) return; // base case just to not have stack overflow
for(i = 0; i < n; i++);// to do O(n) work
algo(n/2);
}
根据上面的定义我可以说,时间复杂度是,R是logn次,O(s)是n。因此结果应该是 n logn,其中与数学归纳法一样,证明结果为 o(n)。
请不要证明归纳法。我在问为什么给定的定义不适用于我的方法。
【问题讨论】: