DEV Community

Discussion on: Comprehensive Big O Notation Guide in Plain English, using Javascript

Collapse
 
danoseun profile image
'Seun Somefun

Oh so what makes shift() and unshift() O(n) is because of the change in the index they cause for elements in the array and not because they affect a single element at a known index?

Thread Thread
 
humblecoder00 profile image
Şahin Arslan

Yes, main reason is mutation place: beginning of an array. Adding or removing an element from start changes index order of all other elements coming after it.

Thread Thread
 
danoseun profile image
'Seun Somefun

Thanks Sahin

Thread Thread
 
celestelayne profile image
Celeste

this is a super important point :-) thanks!

Some comments have been hidden by the post's author - find out more