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
24 - Logarithms and Exponentials
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
Logarithms log2(n) and exponentials 2n arise often when analyzing algorithms.
Uses: These are some of the places that you will see them.
Divide a Logarithmic Number of Times: Many algorithms repeatedly cut the input instance in half. A classic example is binary search (Section 1.4): You take something of size n and you cut it in half, then you cut one of these halves in half, and one of these in half, and so on. Even for a very large initial object, it does not take very long until you get a piece of size below 1. The number of divisions required is about log2(n). Here the base 2 is because you are cutting them in half. If you were to cut them into thirds, then the number of times to cut would be about log3(n).
A Logarithmic Number of Digits: Logarithms are also useful because writing down a given integer value n requires 「log10(n + 1)」 decimal digits. For example, suppose that n = 1,000,000 = 106. You would have to divide this number by 10 six times to get to 1. Hence, by definition, log10(n) = 6. This, however, is the number of zeros, not the number of digits. We forgot the leading digit 1.
- Type
- Chapter
- Information
- How to Think About Algorithms , pp. 374 - 376Publisher: Cambridge University PressPrint publication year: 2008