Describe the order of growth of each of the following code sections, using 0 not
ID: 2247323 • Letter: D
Question
Describe the order of growth of each of the following code sections, using 0 notation:
a. count = 0;
for (i = 1; i <= N; i++)
count++;
b. count = 0;
for (i = 1; i <= N; i++)
for (j = 1; j <= N; j++)
count++;
c. value = N;
count = 0;
while (value > 1)
{
value = value / 2;
count++;
}
d. count = 0;
value = N;
value = N * (N -1);
count = count + value;
e. count = 0;
for (i = 1; i <= N; i++)
count++;
for (i = N; i >= 0; i--)
count ++;
f. count = 0;
for (i = 1; i <= N; i++)
for (j = 1; j <= 5; j++)
count++;
Explanation / Answer
Hi...
a. count = 0;
for (i = 1; i <= N; i++)
count++;
b. count = 0;
for (i = 1; i <= N; i++)
for (j = 1; j <= N; j++)
count++;
c. value = N;
count = 0;
while (value > 1)
{
value = value / 2;
count++;
}
d. count = 1;
value = N;
value = N * (N -1);
count = count + value;
e. count = 1;
for (i = 1; i <= N; i++)
count++;
for (i = N; i >= 0; i--)
count ++;
f. count = 1;
for (i = 1; i <= N; i++)
for (j = 1; j <= 5; j++)
count++;
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.