Big O Notation
Worst-case growth rates and comparing algorithms.
What you will learn
- Read O(1), O(n), O(log n), O(n²)
- Drop constants in big-O
- Pick structure by operation cost
Big O describes how runtime or memory grows as input size n grows. We care about the dominant term, not whether you save 2Ć with a faster CPU.
Common complexities
O(1) ā hash lookup. O(log n) ā binary search. O(n) ā scan an array. O(n log n) ā good sorts. O(n²) ā nested loops over n.
Try it yourself
What is the complexity of finding duplicates with nested loops vs a hash set?
