Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- Part Two Recursion
- Part Three Optimization Problems
- Part Four Appendix
- 22 Existential and Universal Quantifiers
- 23 Time Complexity
- 24 Logarithms and Exponentials
- 25 Asymptotic Growth
- 26 Adding-Made-Easy Approximations
- 27 Recurrence Relations
- 28 A Formal Proof of Correctness
- Part five Exercise Solutions
- Index
23 - Time Complexity
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- Part Two Recursion
- Part Three Optimization Problems
- Part Four Appendix
- 22 Existential and Universal Quantifiers
- 23 Time Complexity
- 24 Logarithms and Exponentials
- 25 Asymptotic Growth
- 26 Adding-Made-Easy Approximations
- 27 Recurrence Relations
- 28 A Formal Proof of Correctness
- Part five Exercise Solutions
- Index
Summary
It is important to classify algorithms based whether they solve a given computational problem and, if so, how quickly. Similarly, it is important to classify computational problems based whether they can be solved and, if so, how quickly.
The Time (and Space) Complexity of an Algorithm
Purpose
Estimate Duration: To estimate how long an algorithm or program will run.
Estimate Input Size: To estimate the largest input that can reasonably be given to the program.
Compare Algorithms: To compare the efficiency of different algorithms for solving the same problem.
Parts of Code: To help you focus your attention on the parts of the code that are executed the largest number of times. This is the code you need to improve to reduce the running time.
Choose Algorithm: To choose an algorithm for an application:
If the input size won't be larger than six, don't waste your time writing an extremely efficient algorithm.
If the input size is a thousand, then be sure the program runs in polynomial, not exponential, time.
If you are working on the Gnome project and the input size is a billion, then be sure the program runs in linear time.
Time Complexity Time and Space Complexities Are Functions, T(n) and S(n): The time complexity of an algorithm is not a single number, but is a function indicating how the running time depends on the size of the input. We often denote this by T(n), giving the number of operations executed on the worst case input instance of size n. An example would be T(n) = 3n2 + 7n + 23. Similarly, S(n) gives the size of the rewritable memory the algorithm requires.
- Type
- Chapter
- Information
- How to Think About Algorithms , pp. 366 - 373Publisher: Cambridge University PressPrint publication year: 2008