Question: Determine for the following code fragments in the average case. Assume that all variables are of type int . (a) a = b +

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); }

Step by Step Solution

3.34 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The given code fragment consists of two statements which are independent and are performed in con... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!