Cheat sheet
The numbers worth memorizing, on one page. Every row links to the full lesson.
Growth rates
Rule of thumb: about 10⁸ simple operations per second.
| Complexity | Name | Typical example | Feasible n (1 s) |
|---|---|---|---|
| O(1) | Constant | Array index, hash lookup | Any n |
| O(log n) | Logarithmic | Binary search, balanced BST | Any n |
| O(n) | Linear | Single scan | n ≤ 10⁸ |
| O(n log n) | Linearithmic | Merge sort, heap operations × n | n ≤ 10⁶–10⁷ |
| O(n²) | Quadratic | Nested loops, simple DP | n ≤ 10⁴ |
| O(n³) | Cubic | Floyd-Warshall, matrix multiply | n ≤ 500 |
| O(2ⁿ) | Exponential | All subsets, bitmask DP | n ≤ 20–25 |
| O(n!) | Factorial | All permutations | n ≤ 10–11 |
Estimation rules of thumb
For back-of-the-envelope capacity planning.
| Quantity | Rule |
|---|---|
| Seconds per day | 86,400 ≈ 10⁵ |
| Requests/day → QPS | divide by ~10⁵ |
| 1M requests/day | ≈ 12 QPS |
| Peak QPS | ≈ 2–3 × average |
| Storage per year | daily writes × object size × 365 |
| Cache size (80/20) | ≈ 20% of daily read volume |
Sorting algorithms
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | No |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | No |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
| Counting & Bucket Sort | O(n + k) | O(n + k) | O(n + k) | O(n + k) | Yes |
| Radix Sort | O(d·(n + b)) | O(d·(n + b)) | O(d·(n + b)) | O(n + b) | Yes |
Data structure operations
| Structure | Access | Search | Insert | Delete | Space |
|---|---|---|---|---|---|
| Arrays & Dynamic Arrays | O(1) | O(n) | O(n) | O(n) | O(n) |
| Dynamic array (append) | O(1) | O(n) | O(1) amortized | O(n) | O(n) |
| Linked Lists | O(n) | O(n) | O(1) at node | O(1) at node | O(n) |
| Stacks | O(n) | O(n) | O(1) | O(1) | O(n) |
| Queues & Deques | O(n) | O(n) | O(1) | O(1) | O(n) |
| Hash Tables | n/a | O(1) avg · O(n) worst | O(1) avg | O(1) avg | O(n) |
| Binary Search Trees | O(log n) avg | O(log n) avg · O(n) worst | O(log n) avg | O(log n) avg | O(n) |
| AVL / Red-black tree | O(log n) | O(log n) | O(log n) | O(log n) | O(n) |
| Heaps & Priority Queues | O(1) peek | O(n) | O(log n) | O(log n) root | O(n) |
| Tries (Prefix Trees) | n/a | O(L) | O(L) | O(L) | O(Σ·N·L) |
| Skip Lists | O(log n) avg | O(log n) avg | O(log n) avg | O(log n) avg | O(n) |
| Union-Find (Disjoint Set) | n/a | O(α(n)) find | O(α(n)) union | n/a | O(n) |
| Segment Trees | n/a | O(log n) query | O(log n) update | n/a | O(n) |
| Fenwick Trees (BIT) | n/a | O(log n) prefix | O(log n) update | n/a | O(n) |
Graph algorithms
| Algorithm | Time | Space | Use it for |
|---|---|---|---|
| Breadth-First Search | O(V + E) | O(V) | Shortest paths, unweighted |
| Depth-First Search | O(V + E) | O(V) | Cycles, components, ordering |
| Topological Sort | O(V + E) | O(V) | Dependency ordering in a DAG |
| Dijkstra's Algorithm | O((V + E) log V) | O(V) | Shortest paths, weights ≥ 0 |
| Bellman-Ford & Floyd-Warshall | O(V·E) · O(V³) | O(V) · O(V²) | Negative weights · all pairs |
| Minimum Spanning Trees | O(E log E) | O(V) | Cheapest connected subgraph |
| Union-Find (Disjoint Set) | O(α(n)) per op | O(V) | Dynamic connectivity |
| A* Pathfinding | O(E log V) | O(V) | Heuristic shortest path |
| SCCs, Bridges & Articulation Points | O(V + E) | O(V) | SCCs, bridges, articulation points |
Latency numbers every engineer should know
L1 cache reference
0.5 ns
Branch mispredict
5 ns
L2 cache reference
7 ns
Mutex lock/unlock
25 ns
Main memory reference
100 ns
Compress 1 KB (Snappy)
3 µs
Send 1 KB over 1 Gbps
10 µs
SSD random read
150 µs
Read 1 MB sequentially from RAM
250 µs
Round trip in a datacenter
500 µs
Read 1 MB sequentially from SSD
1 ms
Disk seek
10 ms
Read 1 MB sequentially from disk
20 ms
Packet CA → Netherlands → CA
150 ms
Bars use a log scale: each step is roughly 10× slower than the last.
Powers of two
| Power | Approx. value | Bytes |
|---|---|---|
| 2¹⁰ | 1 thousand | 1 KB |
| 2²⁰ | 1 million | 1 MB |
| 2³⁰ | 1 billion | 1 GB |
| 2⁴⁰ | 1 trillion | 1 TB |
| 2⁵⁰ | 1 quadrillion | 1 PB |
Availability nines
| Availability | Name | Down / year | Down / month | Down / day |
|---|---|---|---|---|
| 99% | Two nines | 3.65 days | 7.31 hours | 14.4 min |
| 99.9% | Three nines | 8.77 hours | 43.8 min | 1.44 min |
| 99.95% | Three and a half | 4.38 hours | 21.9 min | 43.2 s |
| 99.99% | Four nines | 52.6 min | 4.38 min | 8.64 s |
| 99.999% | Five nines | 5.26 min | 26.3 s | 864 ms |