arraytime complexity

Common Array Operations Time Complexity

4 min read
Feb 3, 2025

The following table summarizes the time complexity of common operations on arrays. Understanding these complexities can help you write more efficient code. The aim is to be language agnostic, but some operations may have different complexities in different languages.

Access by index

O(1)

Arrays provide constant-time access to any element using its index

Insert at end

O(1)*

* Amortized O(1) - occasional resizing may be needed depending on implementation

Remove last element

O(1)

Removing from the end is constant time as no shifting is required

Adding at start (unshift)

O(n)

Must shift all existing elements to the right: linear time.

Removing first element (shift)

O(n)

Must shift all remaining elements to the left

Looking for an easy summary? Checkout this cheatsheet.

Big O Academy