考虑下面的C程序
int f1(int n)
{
if(n == 0 || n == 1)
return n;
else
return (2*f1(n-1) + 3*f1(n-2));
}
int f2(int n)
{
int i;
int X[N], Y[N], Z[N] ;
X[0] = Y[0] = Z[0] = 0;
X[1] = 1; Y[1] = 2; Z[1] = 3;
for(i = 2; i <= n; i++)
{
X[i] = Y[i-1] + Z[i-2];
Y[i] = 2*X[i];
Z[i] = 3*X[i];
}
return X[n] ;
}
f1(n)和f2(n)的运行时间为
(一种) (n)和 (n)
(B) (2 ^ n)和 (n)
(C) (n)和 (2 ^ n)
(D) (2 ^ n)和 (2 ^ n)
(A) A
(B) B
(C) C
(D) D答案: (B)
说明:请参阅https://www.geeksforgeeks.org/c-language-set-5/的问题3
这个问题的测验