Math Fundamentals18 sections · 814 units
Open in Course

Exponents in Big-O

Algorithm complexity

Exponents show up in Big-O when algorithms branch or nest. O(n2)O(n^2) means two nested loops over nn items. O(n3)O(n^3) means three nested loops. These are polynomial and usually acceptable for small nn.

O(2n)O(2^n) is exponential. It means the work doubles with every extra input element. At n=20n = 20, that's about 10610^6 operations. At n=30n = 30, about 10910^9. At n=40n = 40, you're waiting hours.

The growth rate hierarchy you should remember: O(logn)<O(n)<O(nlogn)<O(n2)<O(n3)<O(2n)<O(n!)O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!). Polynomial beats exponential for large nn, which is why converting an O(2n)O(2^n) brute force into an O(n2)O(n^2) dynamic programming solution is such a big win.