Worst-case traffic time estimate
Day 40 of 149
π Full deep-dive with code examples
The Traffic Estimate
Your friend asks: "How long does your commute take?"
You could say:
- "A short commute" (light traffic)
- "A long commute" (worst case: traffic)
Big O is like worst-case estimate for algorithms!
Common Big O's
| Big O | Meaning | Example |
|---|---|---|
| O(1) | Constant | Get item by index |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Loop through all |
| O(nΒ²) | Quadratic | Nested loops |
What They Mean
O(1): Same time no matter the size
- Get arr[5] with 10 items = Get arr[5] with 1 million items
O(n): Time grows with size
- 10 items β check 10
- 1000 items β check 1000
O(nΒ²): Time grows FAST
- 10 items β 100 operations
- 1000 items β 1,000,000 operations π±
Visual
| O(nΒ²)
Time | /
| O(n) |
| ___ O(1) |
+---------β
Size
In One Sentence
Big O describes how an algorithm's time grows as input size grows, focusing on worst-case scenarios.
π Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)