Then
a, b, c and d respectively are:
| A. | 3, 1, 2 and 0 |
| B. | 1/3, 1/2, 1/6 and 2 |
| C. | 1/3, 1/2, 1/6 and 1 |
| D. | 1/3, 1/2, 1/6 and 0 |
(1) scanf ("%d", &n);
(2) x = 2;
(3) for (i = 1; i <= n; i++)
(4) x = x*x;
A choice of loop invariant for this fragment is:
If we reach the test for i <= n in the for loop of line
(4) above with the value of the loop counter i set to k, then the
value of x at that point will be 22k-1.
For values of i > n, this statement is:
| A. | false |
| B. | true |
| C. | not applicable |
| D. | undefined |
| A. | 22n |
| B. | 22n-1 |
| C. | 22n+1 |
| D. | None of the above |
| A. | 5000 |
| B. | 50,000 |
| C. | 500,000 |
| D. | 5,000,000 |
| A. | log(n), sqrt(n), n*log(n), n2 |
| B. | sqrt(n), log(n), n2, n*log(n) |
| C. | log(n), n*log(n), sqrt(n), n2 |
| D. | log(n), n*log(n), n2, sqrt(n) |
| A. | T1(n) + T2(n) = O(f(n)) | B. | T1(n)/T2(n) = 1 | C. | T1(n) is O(T2(n)) |
| D. | All of the above |
| A. | 1 and 8 |
| B. | 2 and 6 |
| C. | 2 and 7 |
| D. | 3 and 5 |
scanf("%d", &n);
for (i = 0; i < n; i++)
for (j = 0; i < n; j++)
A[i][j] = 0;
for (i = 0; i < n; i++)
A[i][i] = 1;
It's tightest bound running time is:
| A. | O(n) |
| B. | O(n2) |
| C. | O(n3) |
| D. | O(2n) |
| A. | O(g(n) - f(n)) |
| B. | O(g(n) * f(n)) |
| C. | O(g(n)) |
| D. | All of the above |
for (i = 0; i <= b; i++) {
loop body;
}
How many times is the body of the loop executed?
| A. | b-a |
| B. | b-a+1 |
| C. | b-a-1 |
| D. | b-a+2 |
scanf("%d", &x);
low = 0;
high = n-1;
while (low <= high) {
mid = (low+high)/2;
if (x < A[mid])
high = nid-1;
else if (x > A[mid])
low = mid+1;
else
return mid;
}
Its running time is:
| A. | O(n) |
| B. | O(log n) |
| C. | O(n*log n) |
| D. | O(n2) |
| T(1) = a | (1) |
| T(n) = T(n-1) + b | (2) |
by repeated substitution where (2) is assumed to be the first substitution into T(n), we will find that after i substitutions into T(n), T(n) =
| A. | T(n-i) + ib |
| B. | T(n-i-1) + (i-1)b |
| C. | T(n-i+1) + (i+1)b |
| D. | None of the above |
| T(1) = a |
| T(n) = 2T(n-1) + b |
for some positive constants a and b, then T(n) is
| A. | O(n) |
| B. | O(n*log n) |
| C. | O(n2log n) |
| D. | None of the above |
| A. | xn + nyxn-1 |
| B. | xn + yn |
| C. | xn + ny |
| D. | xn + nyn-1 |
| A. | 180 |
| B. | 36 |
| C. | 66 |
| D. | None of the above |