2.4 Growth rates
Imagine that you have a problem to solve, and you know of an algorithm whose running time is proportional to where is a measure of the input size. Unfortunately, the resulting program takes ten times too long to run. If you replace your current computer with a new one that is ten times faster, will the algorithm become acceptable? If the problem size remains the same, then perhaps the faster computer will allow you to get your work done quickly enough even with an algorithm having a high growth rate. But a funny thing happens to most people who get a faster computer. They don’t run the same problem faster. They run a bigger problem! Say that on your old computer you were content to sort 10,000 records because that could be done by the computer during your lunch break. On your new computer you might hope to sort 100,000 records in the same time. You won’t be back from lunch any sooner, so you are better off solving a larger problem. And because the new machine is ten times faster, you would like to sort ten times as many records.
If your algorithm’s growth rate is linear (i.e., if the equation that describes the running time on input size is for some constant ), then 100,000 records on the new machine will be sorted in the same time as 10,000 records on the old machine. If the algorithm’s growth rate is greater than , such as , then you will not be able to do a problem ten times the size in the same amount of time on a machine that is ten times faster.
2.4.1 Getting a faster computer
How much larger problems a faster computer solve in the same amount of time? Say that the old machine could solve a problem of size in an hour, and that the new machine is ten times faster than the old. What is the largest problem that the new machine can solve in one hour? Table 2.1 shows just that for five running-time functions.
Growth rate | Max (old) | Max (new) | Relation and | |
---|---|---|---|---|
Explanations:
- The first column lists the right-hand sides for five growth rate equations.
- The second column shows the maximum value for that can be run in 10,000 basic operations on the old machine.
- The third column shows the value for , the new maximum size for the problem that can be run in the same time on the new machine that is ten times faster. Variable is the greatest size for the problem that can run in 100,000 basic operations.
- The fourth column shows how the size of changed to become on the new machine.
- The fifth column shows the increase in problem size as the ratio of to .
This table illustrates many important points. The first two equations are both linear; only the value of the constant factor has changed. In both cases, the machine that is ten times faster gives an increase in problem size by a factor of ten. In other words, while the value of the constant does affect the absolute size of the problem that can be solved in a fixed amount of time, it does not affect the improvement in problem size (as a proportion to the original size) gained by a faster computer. This relationship holds true regardless of the algorithm’s growth rate: Constant factors never affect the relative improvement gained by a faster computer.
An algorithm with time equation does not receive nearly as great an improvement from the faster machine as an algorithm with linear growth rate. Instead of an improvement by a factor of ten, the improvement is only the square root of that: . Thus, the algorithm with higher growth rate not only solves a smaller problem in a given time in the first place, it also receives less of a speedup from a faster computer. As computers get ever faster, the disparity in problem sizes becomes ever greater.
The algorithm with growth rate improves by a greater amount than the one with quadratic growth rate, but not by as great an amount as the algorithms with linear growth rates.
Note that something special happens in the case of the algorithm whose running time grows exponentially. If you look at its plot on a graph, the curve for the algorithm whose time is proportional to goes up very quickly as grows. The increase in problem size on the machine ten times as fast is about (to be precise, it is ). The increase in problem size for an algorithm with exponential growth rate is by a constant addition, not by a multiplicative factor. Because the old value of was 13, the new problem size is 16. If next year you buy another computer ten times faster yet, then the new computer (100 times faster than the original computer) will only run a problem of size 19. If you had a second program whose growth rate is and for which the original computer could run a problem of size 1000 in an hour, than a machine ten times faster can run a problem only of size 1003 in an hour! Thus, an exponential growth rate is radically different than the other growth rates shown in the table. The significance of this difference is an important topic in computational complexity theory.
Instead of buying a faster computer, consider what happens if you replace an algorithm whose running time is proportional to with a new algorithm whose running time is proportional to . In a graph relating growth rate functions to input size, a fixed amount of time would appear as a horizontal line. If the line for the amount of time available to solve your problem is above the point at which the curves for the two growth rates in question meet, then the algorithm whose running time grows less quickly is faster. An algorithm with running time requires time steps for an input of size . An algorithm with running time requires time steps for an input of size , which is an improvement of much more than a factor of ten when compared to the algorithm with running time . Because whenever , if the typical problem size is larger than 58 for this example, then you would be much better off changing algorithms instead of buying a computer ten times faster. Furthermore, when you do buy a faster computer, an algorithm with a slower growth rate provides a greater benefit in terms of larger problem size that can run in a certain time on the new computer.
2.4.2 Comparing different growth rates
The growth rate for an algorithm is the rate at which the cost of the algorithm grows as the size of its input grows. Figure 2.1 shows a graph for six equations, each meant to describe the running time for a particular program or algorithm. A variety of growth rates that are representative of typical algorithms are shown.

The two equations labeled and are graphed by straight lines. A growth rate of (for any positive constant) is often referred to as a linear growth rate or running time. This means that as the value of grows, the running time of the algorithm grows in the same proportion. Doubling the value of roughly doubles the running time. An algorithm whose running-time equation has a highest-order term containing a factor of is said to have a quadratic growth rate. In the figure, the line labeled represents a quadratic growth rate. The line labeled represents an exponential growth rate. This name comes from the fact that appears in the exponent. The line labeled also grows exponentially.
As you can see from the figure, the difference between an algorithm whose running time has cost and another with cost becomes tremendous as grows. For , the algorithm with running time is already much slower. This is despite the fact that has a greater constant factor than . Comparing the two curves marked and shows that changing the constant factor for one of the equations only shifts the point at which the two curves cross. For , the algorithm with cost is slower than the algorithm with cost . This graph also shows that the equation grows somewhat more quickly than both and , but not nearly so quickly as the equation . For constants grows faster than either or . Finally, algorithms with cost or are prohibitively expensive for even modest values of . Note that for constants grows faster than .
We can get some further insight into relative growth rates for various algorithms from Table 2.2 below. Most of the growth rates that appear in typical algorithms are shown, along with some representative input sizes. Once again, we see that the growth rate has a tremendous effect on the resources consumed by an algorithm.
n | |||||||
---|---|---|---|---|---|---|---|
2.4.3
Growth rates exercises
2.4.3 Growth rates exercises