Question

2. Measure the complexity of the following algorithm: SHOW your work. (15 points) a=1 b 3: for (i = 0, i<= n, i++) d-d-1 for (j:0, j <= n, j++) c=a+b;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

2.)

In above question we have two loops

Time complexity of a loop is given as either having incrementing values or decrementing values is O(n) where n is no of times the loop executes.

In above question we have two loops that is nested loop a loop within a loop

so for every iteration inner loop completes all its iterations

as outer loop is iterating 1 time inner loop iterates n times so when outer loop iterates n times inner loop also iterates making it n*n=n2

Hence the complexity of above one is O(n2)

Add a comment
Know the answer?
Add Answer to:
2. Measure the complexity of the following algorithm: SHOW your work. (15 points) a=1 b 3:...
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