Math Fundamentals18 sections · 814 units
Open in Course

Algebra in Complexity Analysis

Simplifying runtime formulas

When analyzing algorithms, you write time complexity as a formula in terms of input size nn. Algebra helps you simplify these formulas.

For example, if you have nested loops where the outer runs nn times and the inner runs nn times, the total is n×n=n2n \times n = n^2 operations. You write this as O(n2)O(n^2).

If you have 3n2+5n+73n^2 + 5n + 7 operations, you drop constants and lower-order terms to get O(n2)O(n^2). Algebra tells you which term dominates as nn grows.