Stage 1 · Lesson 6 of 6
Reading constraints to guess the target complexity
The limits in a problem statement, called , tell you how fast your solution must be. A typical , the system that runs and checks your code, manages roughly 10^8 simple steps per second. So work backwards from the input size n.
Up to about 20 allows O(2^n). Up to a few thousand allows O(n²). Up to 10^5 or 10^6 needs O(n log n) or O(n).
Up to 10^9 or more needs O(log n) or a formula. Reading constraints before you design tells you which ideas are worth trying, and which (trying everything) will run out of time. It turns this stage from theory into a tool you use on every problem.
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