2

I just started learning data structure and while going through array insertion I wondered why is time complexity of array insertion O(n) and not O(n+1) ?

In best case, when insertion is at the last place,the time complexity is O(1). I suppose we are considering 1 to insert the element as no elements are moved here. In worst case, Given that we have to move n elements and then insert the new element, Shouldn't the time time complexity be O(n+1) ? n for moving the elements and 1 for insertion.

Help is very much appreciated.Thanks.

0

1 Answer 1

10

Any function that is O(n) is also O(n+1), and vice versa. Lower-order terms are essentially ignored, so the +1 doesn't contribute anything meaningful.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.