Question

Explain why building a list in sorted order is an O(n2) operation. You don’t have to...

Explain why building a list in sorted order is an O(n2) operation. You don’t have to derive it with mathematical formality, but at least explain why, mathematically, it’s O(n2).

0 0
Add a comment Improve this question Transcribed image text
Answer #1
for building a list of n items in sorted order.

procedure:
-----------
Adding 1st item in sorted order takes 1 operation.
Adding 2nd item in sorted order takes 2 operations(to add before the first item or after the first item)
...
Adding i+1th item in sorted order after (already sorted i items), it takes i operations.
...

so, total number of operations = 1+2+3+...+n = n(n+1)/2 = (n^2+n)/2
we can ignore constant terms and lower order terms.
so, time complexity is O(n^2)
Add a comment
Know the answer?
Add Answer to:
Explain why building a list in sorted order is an O(n2) operation. You don’t have to...
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