19 might take much more time than others. All else being equal, we

advertisement
19
multiplications
50–
simple powery
algorithm
40
30
20–
10-
0
10
Figure 2.7
20
30
40
50
n
Time efficiency of the simple and smart power algorithms.
might take much more time than others. All else being equal, we prefer the algorithm
whose time requirement grows most slowly with n.
If we have a formula for an algorithm's time requirement, we can focus on its growth
rate as follows:
• Take the fastest-growing term in the formula, and discard all slower-growing terms.
• Discard any constant factor in the fastest-growing term.
The resulting formula is called the algorithm's time complexity. We define space
complexity similarly.
Download