Question

Compute the time complexity for each of the following two program fragments with respect to N....

Compute the time complexity for each of the following two program fragments with respect to N. Show your steps in reaching your answer.

1)             for(i=1; i < N; i = i*2) {

      for(j=0;j

            // Operations with constant time…

      } }

2)              for(i = 0; i < sqrt(N); i++){

      for(j=1; j < i+8; j++){

           for(k=0;k

                  // Operations with constant time…

           } } }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

it will be nlogn.

for the first loop it is multiplication by i and second loop in j is dependent on i and will run for n times as well so it will be nlogn.

2)

it should be roughly n2 as the second first and second loop are dependent and will run together for roughly n times and the k for will run for n more times so n2

Add a comment
Know the answer?
Add Answer to:
Compute the time complexity for each of the following two program fragments with respect to N....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT