Stage 1 · Lesson 3 of 6
Best, worst and average case
The same algorithm can do very different amounts of work on two inputs of the same size. The is the most work it does on any input. The best case is the least, and the average case is what you expect on typical or random input.
, which checks items one by one, finds its target on the first step at best and checks everything at worst. averages O(n log n) but slows to O(n²) when it keeps choosing bad split points (). When someone gives one without saying which case, they almost always mean the worst. That is the case that decides whether your code finishes on the input you did not expect.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Algorithm Complexity and Big-O
Design Gurus · Beginner · Subscription
Short course on exactly this stage, including the amortised and space cases people miss
- CourseFreeAlgorithms, Part I
Princeton University · Intermediate
Free: the Analysis of Algorithms module measures real Java programs, then models their cost
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms