Handbooks / Data Structures & Algorithms / Chapter 1
Big-O and Recursion
7 pages · ~5 min✓ Reviewed
Start here. Next up: Arrays and Hashing.
Asymptotic Notation and Growth Rates
1. The Three Bounds
- Big-O:
f(n)=O(g(n))iff ≤ c·g(n)for alln ≥ n0 - An upper bound, usually quoted for the worst case
- Omega is the lower bound:
f ≥ c·g(n) - Theta is the tight bound: true only when O and Omega both hold
| Symbol | Bound | Means |
|---|---|---|
| O | upper | at most g |
| Omega | lower | at least g |
| Theta | tight | O and Omega |
2. Simplify and Order
- Drop constants and lower-order terms:
3n²+5n+9is Theta(n²) - Different input variables stay separate:
O(a+b), notO(n)
Growth order, slowest to fastest
- 11
- 2log n
- 3n
- 4n log n
- 5n²
- 6n³
- 72ⁿ
- 8n!