Determine for the following code fragments in the average case. Assume that all variables are of
Fantastic news! We've Found the answer you've been seeking!
Question:
Determine ϴ for the following code fragments in the average case. Assume that all variables are of type int.
(a) a = b + c;
d = a + e;
(b) sum = 0;
for (i=0; i<3; i++)
for (j=0; j
sum++;
(c) sum=0;
for (i=0; i
sum++;
(d) for (i=0; i < n-1; i++)
for (j=i+1; j < n; j++) {
tmp = A[i][j];
A[i][j] = A[j][i];
A[j][i] = tmp;
}
(e) sum = 0;
for (i=1; i<=n; i++)
for (j=1; j<=n; j*=2)
sum++;
(f) sum = 0;
for (i=1; i<=n; i*=2)
for (j=1; j<=n; j++)
sum++;
(g) Assume that array A contains n values, Random takes constant time, and sort takes n log n steps.
for (i=0; i
for (j=0; j
A[i] = Random(n);
sort(A, n); }
Related Book For
Mathematical Applications for the Management, Life and Social Sciences
ISBN: 9781337625340
12th edition
Authors: Ronald J. Harshbarger, James J. Reynolds
Posted Date: