【发布时间】:2013-03-09 05:25:50
【问题描述】:
就大 O 表示法而言,以下函数的增长率是多少?
f (n) = Comb(1000,n) for n = 0,1,2,…
int Comb(int m, int n)
{
int pracResult = 1;
int i;
if (m > n/2) m = n-m;
for (i=1; i<= m; i++)
{
pracResult *= n-m+i;
pracResult /= i;
practicalCounter++;
}
return pracResult;
}
递归:
int combRecursive (int m, int n)
{
recursiveCounter++;
if (n == m) return 1;
if (m == 1) return n;
return combRecursive(n-1, m) + combRecursive(n-1, m-1);
}
我猜n^2???不过我可能错了……我一直在努力弄清楚事情的效率如何……
先谢谢你了。
【问题讨论】:
-
我收回我的话。如果你写的内容是正确的,那么你的函数在 O(1) 中运行。
-
需要更多关于 Comb() 的信息
-
我很抱歉。我会尽快更新问题。
-
我已经更新了代码。
-
@JLott:您是否 100% 确定您以正确的顺序使用变量 m 和 n?您将 n 作为第二个参数传递,但第一个参数名为 n。
标签: time-complexity big-o