Question

What is the Big Oh of the list method remove() in best case and worst cases?...

What is the Big Oh of the list method remove() in best case and worst cases? The answers to these two questions, found on page 396 are O(1) and O(n). Why is the best case O(1) and worst case O(n) ?

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

Best Case is when we have one element : Just remove it

Hence its O(1)


Worst Case happens :
Supose we want to remove element which is in middle, Once we remove the element. We need to shift all the element to one position left. Shifting element to its left will take O(n) time.

Hence we can say that Remove method will take O(n) in worst case.


Thanks, PLEASE UPVOTE if helpful

Add a comment
Know the answer?
Add Answer to:
What is the Big Oh of the list method remove() in best case and worst cases?...
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