Time Complexity
ELI5 — The Vibe Check
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? The same? Understanding time complexity helps you avoid writing code that works fine on 10 items but melts down on 10 million.
Real Talk
Time complexity is a measure of how the runtime of an algorithm scales with input size (n), expressed in Big O notation. It counts the number of operations rather than actual wall-clock time, making it hardware-independent. Analysis covers best case (Ω), average case (Θ), and worst case (O). Critical for choosing the right algorithm at scale.
Show Me The Code
// Time complexity examples:
// O(1) — HashMap lookup:
const user = userMap.get(id); // same speed for 10 or 10M users
// O(n) — Finding max in unsorted array:
const max = arr.reduce((a, b) => Math.max(a, b));
// O(n log n) — Array sort:
arr.sort((a, b) => a - b); // JavaScript's built-in sort
// O(n²) — Bubble sort (avoid for large n):
for (let i = 0; i < n; i++)
for (let j = 0; j < n; j++) { /* compare */ }
When You'll Hear This
"The time complexity is O(n²) — it'll be too slow past 10,000 records." / "Profile it to confirm the time complexity matches theory."
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?
Big O
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.
Space Complexity
Space complexity is how much extra memory your algorithm uses as the input grows.