Two algorithms for the same problem — exhaustive enumeration and bisection search for a square root, back in Exhaustive Enumeration and Approximate Solutions and Bisection Search and the Perils of Floats — can differ by a factor of fifty million in the number of steps they take on the same input. This note gives that observation a name — asymptotic complexity — and a vocabulary for talking about it: Big O notation, and the handful of complexity classes (constant, logarithmic, linear, log-linear, polynomial, exponential) that essentially every algorithm this vault will ever show falls into. This is deliberately a reading skill, not a proof-writing one:
docs/programme-profiles/library/introduction-to-python.md's Branch A/B split defers the rigorous derivation of running-time bounds to learn/library/programming/ds-a/'s dedicated complexity topic, and this note's job is only to make you fluent enough to read "" in a library's documentation and understand roughly what it promises.Learning objectives. By the end of this note you should be able to:
- explain why raw wall-clock timing is a poor way to compare two algorithms, and what "counting basic steps as a function of input size" fixes about that;
- distinguish best-case, worst-case, and average-case running time, and explain why worst-case is the default focus in most contexts;
- apply the two simplification rules (keep the fastest-growing term, drop multiplicative constants) to go from an exact step count to a Big O expression;
- read off, at a glance, the practical difference in scalability between , , , , and exponential growth, using the vault's own two square-root algorithms as the anchoring example.
In this lesson
- Why not just time the program?
- Best case, worst case, average case
- From an exact step count to Big O
- The complexity classes, read informally
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.