Conceptintro
Order of growth
Also called growth rate.
The Θ-class of a running-time function, found from its dominant term, which tells how the cost scales as the input size grows.
The order of growth of a running time is its -class: the set of functions that grow at the same rate as when becomes large. You usually find it by keeping the fastest-growing term of and dropping its constant factor. When one order is of the other, the algorithm with the smaller order is faster for all large , whatever the constants are.
In plain words
Take a program that does three times n squared, plus ten times n, plus seven steps on an input of size n. For an input of 10 items, the squared part is 300 steps and the linear part is 100 steps. For 1000 items, the squared part is three million steps and the linear part is only ten thousand. The small parts matter less and less as the input grows. In the end, only the square decides how the time grows. If you make the input ten times larger, the time becomes about a hundred times larger.
This is the order of growth. It says how the cost scales. It does not say the exact time. A machine that is twice as fast changes the constant. It does not change the order of growth. For large inputs, the order of growth decides which algorithm is faster.
The idea
Leading term. Write as a sum of a fixed number of terms. The leading term is the one that grows fastest. If is a polynomial with , then when . So . The proof is by the limit: for large we have , and this gives the constants of the definition of in asymptotic notation.
Drop constants and lower terms. The order of growth of is . The constant depends on the machine, the language and how you count a step. The terms and are smaller than for large . Two functions and have the same order of growth when . This is an equivalence relation on functions that are eventually positive, and the order of growth of is its equivalence class . We name the class by its simplest member, for example . See also asymptotic equivalence and tilde notation, where you keep the constant of the leading term.
The base of a logarithm does not matter. For bases we have , a constant multiple. So needs no base. See logarithms. The base of an exponential does matter: and have different orders of growth, because .
The usual ladder. From slow to fast growth, each function is of the next one:
The names are constant, logarithmic, square root, linear, linearithmic, quadratic, cubic, exponential and factorial time. Any polynomial of fixed degree is below any exponential with . The page common growth rates lists them with examples, and comparing growth by limits shows how to compare two functions with a limit.
Why the order wins over the constant. Let algorithm A take steps and algorithm B take steps. B has the smaller constant, but B takes more steps than A for each (at they are equal: ). For any constants , the function is below for all . So a linear algorithm beats a quadratic one from some size on, however large and however small is. The size where this happens can be large. Below that size, the algorithm with the higher order can be faster, so the order of growth is a statement about large inputs only.
Examples
The table gives the value of each function for some . Here , and the values are rounded.
| 10 | 3.3 | 33 | 100 | 1024 | |
| 100 | 6.6 | 664 | |||
| 1000 | 10.0 | 9966 | more than | ||
| 13.3 | more than | ||||
| 19.9 | more than |
The row for shows the gap. At steps in each second, steps take about years. Also, going from to , the column grows by a factor of about , and the column by a factor of .
The next table shows the largest that a computer can solve in a fixed number of steps, if the algorithm takes exactly steps. The value is rounded down.
| Steps available | with | ||||
|---|---|---|---|---|---|
| 39 620 077 | 31 622 | 1000 | 29 | ||
| 352 213 444 | 100 000 | 2154 | 33 |
A machine ten times faster gives a ten times larger input for a linear algorithm, but about times for a quadratic one, and only 4 more items for an exponential one (29 to 33).
Non-examples:
- and have the same order of growth, but and do not.
- and do not have the same order of growth, although the exponents differ by a constant factor.
- Not every pair of functions is in an order. The functions and are incomparable: neither is of the other, because for infinitely many and for infinitely many . The running times of real algorithms are usually comparable, but the ladder is not a total order on all functions.
- A function that oscillates between two orders has no single simple order. A program that takes steps on odd and steps on even is and , but it is of neither.
Pitfalls
- is not the order. "Insertion sort is " is true, but is not its order of growth. The order of growth is a -class, so it needs a matching upper and lower bound.
- The order depends on the case. Insertion sort has worst-case order and best-case order . Say which case you mean, see worst-case analysis.
- A sum with a growing number of terms. The leading-term rule needs a fixed number of terms. In no single term dominates, and keeping only the largest term gives the wrong order. Evaluate the sum first: it is , see arithmetic series.
- Equal order does not mean equal speed. Two sorts, for example merge sort and heapsort, can differ by a factor of two or more on a real machine.
Where it is used
The order of growth is the main summary of an algorithm. A page on this site gives the order for the worst, average or best case, and it names the model. Experiments use a sharper form: if the time is (see tilde notation), then doubling multiplies the time by a ratio that tends to , and this is the doubling hypothesis. A bound alone does not give this, because the ratio of a function only stays between two constants. Problem classes such as polynomial time are defined by upper bounds on the order of growth, such as for a constant . The order of growth is not enough to choose between two algorithms of the same order, or for small inputs. Then the constants and the real machine matter.
References
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 2YCV99 Edit this page History Report an error Markdown JSON