Skip to content

Big O

Medium — good to knowGeneral Dev

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.