Complexity Analysis
Understand algorithmic time and space complexity using Big O notation, with intuitive summaries and examples.
What is Big O?
Big O describes how runtime or memory grows as input size n increases. It captures the dominant term, ignoring constants and lower-order terms.
Time vs Space
Time complexity measures steps executed; space complexity measures additional memory used beyond the input itself.
Best / Average / Worst
We often focus on worst-case for guarantees, average-case for typical behavior, and best-case for ideal scenarios.
Interactive growth visualizer
O(1) — Constant
Runtime does not grow with input size. Single step operations.
O(log n) — Logarithmic
Problems reduced by a constant factor each step (divide-and-conquer search).
O(n) — Linear
Work grows directly with input size. Single pass over data.
O(n log n) — Quasi-linear
Divide-and-conquer over all elements. Optimal comparison sorting boundary.
O(n²) — Quadratic
Nested loops over data. Pairwise comparisons across elements.
O(2^n), O(n!) — Exponential/Factorial
Brute-force exploration of combinations or permutations.