Lesson 1 of 3
Reason about performance without the maths headache.
Big-O describes how an algorithm's work grows as the input grows. It lets us compare approaches before we even run them.
A quick benchmark in JavaScript:
function sum(arr) {
let total = 0; // O(1)
for (const n of arr) { // O(n)
total += n;
}
return total;
}One loop over the input → linear, O(n).