Big O for Array Methods

dashingdaniel

Daniel

Posted on April 12, 2020

Big O for Array Methods

Push and Pop

Adding or removing data to the array using these two operations is always constant.

So this has a BigO of 1 "O()".

Shift and Unshift

Shifting and Unshifting always will take its own time. As the array has to reindex itself after doing this. So the complexity increases with the no of items

So this has a BigO of N "O(N)".

Concat

Its a simple operation of merging two arrays into one but as we know that indexing takes its own time. So this is also the same as shift.

So this has a BigO of N "O(N)".

Slice

Slice returns the copy of an array from starting index to the ending index as the number of elements grows this'll also grow based on the size of the array

So this has a BigO of N "O(N)".

Splice

With splice we can insert, remove or modify the elements in an array using index. But at the end we are left with indexing. So even this operation grows with the number of elements

So this has a BigO of N "O(N)".

💖 💪 🙅 🚩
dashingdaniel
Daniel

Posted on April 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related