ON Linear Time
1 min readRapid overview
ON Linear Time
TL;DR
O(n) linear time means cost grows in direct proportion to input size ā double the data, double the work. It's the complexity of a single pass: map, filter, reduce, or one for loop over a collection. Linear is usually the practical target when you can't do better than touching every element once, and it's what you aim for when refactoring away an accidental O(n²).
How it works
const sum = (items: number[]) => items.reduce((acc, item) => acc + item, 0);
Notes
- Single passes through arrays are O(n).
- Filtering and mapping are O(n).