Knowledge Base
Big O Cheat Sheet
- O(1): constant time, e.g. average HashMap access.
- O(log n): binary search, database index lookup.
- O(n): full scan, sequential loop.
- O(n log n): common sorting algorithms.
- O(n²): nested loops on large data can spike CPU quickly.
- Relate complexity to real cost: I/O, network, locks, and memory.
Array access -> O(1)
HashMap get/put -> O(1) average
Binary search -> O(log n)
Full table scan -> O(n)
Merge sort -> O(n log n)
Nested loop compare -> O(n^2)