How to Find the Big O of a Function
At a glance
- 1. Set the limit
Specify the variable and the direction of growth, such as n tending to infinity.
- 2. Find dominant terms
For sums, compare terms and identify which grows fastest in the stated limit.
- 3. Prove an upper bound
Show the function's absolute value is at most a constant times your proposed bound.
- 4. Check tightness
Use a matching lower bound if you want to claim Theta rather than only Big O.
Big O describes an eventual upper bound on a function’s growth. To find it, you need to know which variable is changing and what limit you care about—most often, an integer input tending to infinity. Once that is clear, compare the function with a simpler growth rate and verify that the comparison holds up to a constant factor.
The definition of Big O
For functions considered as tends to infinity, is if there are constants and such that
for every , assuming is nonnegative and eventually positive. For sequences, replace with an integer and require the inequality for all .
The constants and may depend on the functions, but not on the input once it is at least . The definition allows you to ignore behavior over a finite starting interval. It also uses an absolute value, so it applies when can be negative.
For example, is because, for every ,
Here, and work. The definition does not require the smallest possible constant.
A practical method
- State the limit. Are you studying , , or a different limit? Big O depends on this choice. In algorithm analysis, the usual question is growth as input size tends to infinity.
- Break the function into terms. For a sum, compare the rates at which its terms grow. A faster-growing term can eventually bound slower-growing terms up to constants.
- Propose a bound. Choose a simple standard rate, such as , , or .
- Verify the inequality. Find constants that make the defining inequality true beyond some threshold. A growth-rate comparison is a useful guide, but the inequality is the definition.
Common growth rates, ordered from slower to faster as , include
where and . This is a pattern, not a complete ranking for every possible function. For example, logarithm bases do not affect Big O: changing the base multiplies a logarithm by a constant.
Worked example
Find the Big O of
As tends to infinity, the quadratic term grows faster than and the constant term. To verify that is a valid bound, use for all sufficiently large (for the natural logarithm, it already holds for ). Also, for . Therefore,
for integers with the natural logarithm. This proves . In fact, the terms are nonnegative and , so the function also has a quadratic lower bound. Thus , which says its growth is bounded both above and below by constant multiples of .
Common mistakes
- Dropping the limit. A statement such as “ is ” is incomplete unless the variable and limiting direction are understood. A function can have different behavior near zero and near infinity.
- Treating Big O as an exact answer. If , then is , but it is also . The second bound is true but looser. Use when you want to state a tight growth rate.
- Keeping every term as a separate answer. For a polynomial, the highest-degree nonzero term determines its Big O as . For other sums, compare the terms rather than automatically choosing the last one written.
- Ignoring signs. The definition bounds . With terms that cancel, do not infer the growth rate from the largest-looking individual term without checking the whole function. For instance, , not as a tight bound, although it is still technically .
- Confusing constants with variables. Fixed coefficients do not change the growth class: and are both . A quantity that depends on is not a fixed constant and cannot be absorbed that way.
Big O near a finite point
The same definition can describe behavior near a point. For instance, is as because whenever . In this setting, write the limit explicitly and use the corresponding neighborhood, rather than applying rules for .
References
- Introduction to Algorithms, Fourth Edition — Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein
- Concrete Mathematics: A Foundation for Computer Science, Second Edition — Ronald L. Graham, Donald E. Knuth, and Oren Patashnik
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.