Question

1. Give the big-O characterization of the following loops, in terms of parameter n, and justify your answer: a) for (int i=1;

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

a)
in the worst case
i iterates from 1 to n and for each value of i, j iterates from 1 to n
so i =O(n) j= O(n)
overall = O(n^2)
b)
in the worst case
i iterates from 1 to n and in worst case j iterates from 1 to n
so i =O(n) j= O(n)
overall = O(n^2)
c)
in the worst case
i iterates from 1 to n^2 and for each value of i, j iterates from 1 to n
so i =O(n^2) j= O(n)
overall = O(n^3)
d)
in the worst case
i iterates from 1 to n^2 and in worst case j iterates from 1 to n
so i =O(n^2) j= O(n)
overall = O(n^3)
e)
in the worst case
i iterates from 1 to n and for each value of i, j iterates from 1 to n^2
so i =O(n) j= O(n^2)
overall = O(n^3)

Add a comment
Know the answer?
Add Answer to:
1. Give the big-O characterization of the following loops, in terms of parameter n, and justify...
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