Courses / Mathematics I
Programming Elements

Computational Complexity

Mathematics I 341 words Free to read

How Algorithms Scale

Two algorithms can solve the same problem, yet one finishes instantly on data that would take the other centuries. Computational complexity measures how an algorithm's resource use — usually time (number of basic steps) — grows as the input size nn grows. It predicts scalability, the property that matters most as data gets large.

We describe growth with big-O notation, which captures the dominant term and ignores constants and lower-order terms — because for large nn only the fastest-growing part matters. Common complexity classes, from best to worst:

The gulf between classes is enormous. For n=1,000,000n = 1{,}000{,}000, a linear algorithm does a million steps while a quadratic one does a trillion — the difference between a second and weeks. This is why choosing the right algorithm usually matters far more than the speed of the machine or micro-optimising the code.

Big-O describes asymptotic behaviour — the trend as nn \to \infty — deliberately dropping constants. So O(n)O(n) and O(100n)O(100n) are the same class, because for large enough nn the algorithm that scales better wins regardless of constant factors. This focus on scaling, not exact step counts, is what makes complexity a clean and powerful predictor.

Common pitfall: confusing an algorithm's complexity class (how it scales) with its raw speed on small inputs. Big-O is about asymptotic growth as nn \to \infty, so it drops constants — O(n)O(n) beats O(n2)O(n^2) for large nn even if the quadratic one is faster on tiny inputs. A lower complexity class is not automatically faster on every input; it is guaranteed to win once nn is large enough, which is what scalability means.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

13practice questions
2interactive scenes
Start Mathematics I free

Programming Elements