Complexity Analysis
Predict how running time and memory grow with input size, including amortized cost, and check those predictions with measurements.
4 objectives 6 steps about 125 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Derive Big-O time and space bounds for code with sequential, nested and multi-input loops, dropping constants and lower-order terms correctly.
- Distinguish best, worst, average and amortized cost, and explain why appending to a dynamic array is amortized O(1).
- Use input-size limits to decide which complexity class a solution must reach (for example, n = 10^5 rules out O(n^2)).
- Benchmark two implementations across growing inputs with timeit and explain whether the measurements match the asymptotic prediction.
Lesson plan
6 steps, about 125 min · 5 of 5 lessons available so far
- Counting Steps Instead of Seconds Concept · 20 min
- Reading Loops: From Code to a Bound Worked example · 25 min
- Worst Case, Average Case and Amortized Cost Concept · 20 min
- Budgeting Operations from Input Limits Worked example · 15 min
- Lab: Timing Growth Curves with timeit Lab · 30 min
- Check: Predict, Then Measure Knowledge check · 8 questions
Practise it
Given six short Python functions, write the time and space bound of each, then benchmark two of them at n = 10^3 to 10^6 with timeit and tabulate whether the growth ratios match your prediction. Use a fixed runtime budget and stop infeasible input sizes early; retain raw timings and separate a growth hypothesis from a correctness argument.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
- Build your own Hash TableIntro · 3–6 h
References
Hard prerequisites
Unlocks
On these roadmaps
Progress and evidence for this skill are shared across all of them.