Big O
ELI5 — The Vibe Check
Big O notation is how we describe how fast (or slow) an algorithm gets as the input grows. O(1) means instant no matter the size. O(n) means it takes twice as long if you double the input. O(n²) means it takes four times longer for double the input. It is the vocabulary for talking about performance at scale.
Real Talk
Big O notation describes the upper bound of an algorithm's time or space complexity as a function of input size (n), ignoring constants and lower-order terms. It characterizes worst-case behavior. Common complexities from fastest to slowest: O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic, O(2ⁿ) exponential. Used to compare algorithm efficiency independently of hardware.
Show Me The Code
// O(1) — constant: doesn't matter how big the array is
const first = arr[0];
// O(n) — linear: one loop through n items
for (const item of arr) { /* ... */ }
// O(n²) — quadratic: nested loops (danger zone)
for (const a of arr) {
for (const b of arr) { /* ... */ }
}
// O(log n) — logarithmic: binary search, halves each step
// O(n log n) — merge sort, quicksort (best general-purpose sort)
When You'll Hear This
"What's the Big O of that lookup? O(n) is too slow for this." / "Use a hash map — O(1) instead of O(n) search."
Related Terms
Algorithm
An algorithm is just a step-by-step recipe for solving a problem. Sort a list? There is an algorithm. Find the shortest path? Algorithm. Make a sandwich?
Array
An array is a list of things in order, like a numbered row of boxes. Box 0 holds the first item, box 1 holds the second, and so on.
Hash Map
A hash map is a super-fast lookup table. You store a value under a key (like a label), and you can find it instantly without searching through everything.
Space Complexity
Space complexity is how much extra memory your algorithm uses as the input grows.
Time Complexity
Time complexity is how the time your algorithm takes grows as the input gets bigger. Does it take twice as long when you double the data? Ten times longer?