Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

a The given code fragment consists of two statements which are independent and are performed in con... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mathematical Applications For The Management, Life And Social Sciences

Authors: Ronald J. Harshbarger, James J. Reynolds

12th Edition

978-1337625340

More Books

Students also viewed these Programming questions