时间复杂度
1-1
The Fibonacci number sequence {FN} is defined as: F0=0, F1=1, FN=FN−1+FN−2, N=2, 3, … The time complexity of the function which calculates FN recursively is Θ(N!).
- T
- F
1-2
(logn)2 is O(n).
- T
- F
1-4
NlogN2 and NlogN3 have the same speed of growth.
- T
- F
1-5
N2logN和NlogN2具有相同的增长速度。
- T
- F
1-6
2N和NN具有相同的增长速度。
- T
- F
2-5
求整数n(n>=0)的阶乘的算法如下,其时间复杂度为( )。
long fact(long n)
{
if (n<=1) return 1;
return n*fact(n-1);
}
- O(n)
2-7
For the following function (where n>0)
int func ( int n )
{ int i = 1, sum = 0;
while ( sum < n ) { sum += i; i *= 2; }
return i;
}
the most accurate time complexity bound is:
- O(logn)
2-8
For the following function (where n>0)
int func ( int n )
{ int i = 1, sum = 0;
while ( n > sum ) { i *= 2; sum += i; }
return i;
}
the most accurate time complexity bound is:
- O(logn)
2-9
Suppose A is an array of length N with some random numbers. What is the time complexity of the following program in the worst case?
void function( int A[], int N ) {
int i, j = 0, cnt = 0;
for (i = 0; i < N; ++i) {
for (; j < N && A[j] <= A[i]; ++j);
cnt += j - i;
}
}
- ?
算法概论
1-3
An algorithm may or may not require input, but each algorithm is expected to produce at least one result as the output.
- T
- F