DEV Community

Daniel
Daniel

Posted on

3

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)".

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay