📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Data Structures and Algorithms Big O Notation

Big O Notation

5 min read Quiz at the end
Big O measures how algorithm time/space scales with input — drop constants and lower-order terms.

Big O Notation

Big O describes how time or space grows relative to input size n — the foundation for comparing algorithms.

NotationNameExample
O(1)ConstantArray index access
O(log n)LogarithmicBinary search
O(n)LinearLinear search
O(n log n)LinearithmicMerge sort
O(n²)QuadraticBubble sort
O(2^n)ExponentialRecursive subsets
O(n!)FactorialPermutations
# n=1000 comparisons:
# O(1)      = 1
# O(log n)  = 10
# O(n)      = 1,000
# O(n log n)= 10,000
# O(n^2)    = 1,000,000
# O(2^n)    = astronomical

# Rules
# Drop constants:  O(2n) -> O(n)
# Drop lower terms: O(n^2 + n) -> O(n^2)
# Best/Avg/Worst case all matter
Topic Quiz · 1 questions

Test your understanding before moving on

1. What is the time complexity of binary search?
💡 Binary search halves the search space each step — it takes at most log2(n) comparisons.