Skip to content
Lydia Hallie theavocoder
Big O contents
Big O Notation / O(1)

Constant

Constant time means the number of steps does not depend on the size of the input. Reading an array element by index is the classic example: the engine can jump straight to the position.

const first = items[0];
const last = items[items.length - 1];

Both lines do the same amount of work whether the array holds ten values or ten million. That does not mean the work is free. It means the cost stays flat as the input grows.

Hash table lookups are often described as constant time on average. Collisions and resizing can change the real cost, which is why the word average matters.

References and further reading