6) Determine for the following code fragments in the average case. Assume that all variables are of type int. (a) (b) (c) a = b + c; d = a +e; sum = 0; for (i=0; i<3; i++) for (j=0; j
6) Determine for the following code fragments in the average case. Assume that all variables are of type int. (a) (b) (c) a = b + c; d = a +e; sum = 0; for (i=0; i<3; i++) for (j=0; j
Related questions
Question
Help me please
![6) Determine for the following code fragments in the average case. Assume that all variables
are of type int.
(a)
(b)
O
(d)
(f)
a = b + c;
d = a +e;
sum = 0;
for (i=0; i<3; i++)
(i)
for (j=0; j<n; j++)
sum++;
sum=0;
for (i=0; i<n*n; i++)
sum++;
for (i=0; i<n-1; i++)
for (j=i+1; j<n; j++) {
tmp = AA[i][j];
AA[i][j] = AA[j][i];
AA[j][i] = tmp;
}
sum = 0;
for (i=1; i<n; i++)
for (j=1; j<n; j*=2)
sum++;
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<n; i++) {
for (j=0; j<n; j++)
}
(h) Assume array A contains a random permutation of the values from 0 to n - 1.
sum = 0;
for (i=0; i<n; i++)
A[i] = util.random(n);
sort(A);
for (j=0; A[j]!=i; j++)
sum++;
sum = 0;
if (EVEN(n))
for (i=0; i<n; i++)
sum++;
else
sum sum +n;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1bc0b1ee-a129-408d-9246-1132e118212d%2F9fc11f46-38bd-45cb-b4f5-4bc4574e45da%2Fm9i38ug_processed.jpeg&w=3840&q=75)
Transcribed Image Text:6) Determine for the following code fragments in the average case. Assume that all variables
are of type int.
(a)
(b)
O
(d)
(f)
a = b + c;
d = a +e;
sum = 0;
for (i=0; i<3; i++)
(i)
for (j=0; j<n; j++)
sum++;
sum=0;
for (i=0; i<n*n; i++)
sum++;
for (i=0; i<n-1; i++)
for (j=i+1; j<n; j++) {
tmp = AA[i][j];
AA[i][j] = AA[j][i];
AA[j][i] = tmp;
}
sum = 0;
for (i=1; i<n; i++)
for (j=1; j<n; j*=2)
sum++;
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<n; i++) {
for (j=0; j<n; j++)
}
(h) Assume array A contains a random permutation of the values from 0 to n - 1.
sum = 0;
for (i=0; i<n; i++)
A[i] = util.random(n);
sort(A);
for (j=0; A[j]!=i; j++)
sum++;
sum = 0;
if (EVEN(n))
for (i=0; i<n; i++)
sum++;
else
sum sum +n;
Expert Solution

Step 1: Overview
In this question we have to solve to find the Big Theta Notation for the given code fragements.
As per the guidelines, I will only perfrom first three parts, rest you may post to another question.
Let's solve and hope this helps, if you find any queries. Please utilize threaded question feature.
Step by step
Solved in 4 steps
