Answer to Question #243551 in Algorithms for kofi

Question #243551

Q1. Determine the growth function and order of the following code fragment:

for (int count=0; count < n; count++)

{

for (int count2=0; count2 < n; count2=count2*2)

{

System.out.println(count, count2);

}

}


 

Q2. What is the order of the following growth functions?

a. 10n2 + 100n + 1000

b. 10n3 – 7

c. 2n + 100n3

d. n2 log n

 

 

Q3. Arrange the growth functions of Q4 in ascending order of efficiency for n=10 and again for n = 1,000,000.


1
Expert's answer
2021-09-28T13:18:56-0400

1.

The outer loop runs n times.

The inner loop runs 1 time if n=1..2, 2 times if n=3..4, 3 times if n is upto 8, 4 times if n is upto 16, 5 times if n is upto 32.

So, the growth function:

"f(n)=nlog_2n"


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS