🧮Best, Worst and Average Case
Also known as Worst Case, Best Case, Average Case, Worst-Case Complexity
How fast code runs on the best input, the worst one and a normal one.
Think of it like
It is like looking for your shoes. Some days they are by the door, some days they are lost.
Example
A linear search over 1,000 names finds the first name in 1 step. It needs 1,000 steps for the last one or a missing one.
Why it matters
A sort that is quick on most data can still freeze on a bad input. The worst case tells you how bad it can get.
Definition
Common mistake
Key takeaways
- 1Best case. The luckiest possible input.
- 2Worst case. The slowest it can ever be.
- 3Average case. What to expect most days.