Learn Big O notation and analyze how algorithm runtime scales with input size.
Time complexity measures how the runtime of an algorithm grows as the input size n grows. We use Big O notation to express this growth rate, ignoring constants and lower-order terms. Understanding time complexity lets you predict whether your solution will be fast enough for large inputs.
This topic teaches how to measure time complexity
N/A
Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.
constant time regardless of input.
map.get(key), arr[i]
input halved each step.
while (n > 1) { n = Math.floor(n/2); }
single pass through input.
for (const x of arr) { ... }
sorting or divide-and-conquer.
arr.sort(), merge sort
nested loops over same input.
for i: for j: compare arr[i] and arr[j]
exponential, all subsets.
function fib(n) { return fib(n-1)+fib(n-2); }
O(3n) = O(n)
Keep only the dominant term
Big O always describes worst-case unless stated otherwise