0 · Math toolkit: logs, exponents, sums
Logs, exponents, floors and the sums you will meet in every analysis.
In one sentence
Algorithm analysis keeps asking two questions: "how many times can I halve this?" (that's a logarithm) and "what do all these loop steps add up to?" (that's a sum). This page gives you the handful of rules that answer both.
Everyday analogy
- Logarithm = the "how many folds" number. Fold a 64-page newspaper in half, again and again, until one page is left. You fold it 6 times, so . A log counts how many halvings (or doublings) it takes.
- Sum = the till receipt. Each loop iteration adds an item to the bill. The closed-form formula is the total printed at the bottom, so you don't have to add the items one by one.
Key rules
| Rule | Formula | Plain words |
|---|---|---|
| Definition | "What power of gives ?" | |
| Product | multiply inside → add outside | |
| Quotient | divide inside → subtract outside | |
| Power | exponent jumps out to the front | |
| Undo | a power and a log cancel | |
| Change base | all logs differ only by a constant | |
| Swap trick | handy in recurrences | |
| Exponents | , | |
| Arithmetic sum | ||
| Squares | ||
| Geometric () | ||
| Powers of 2 | "the next power, minus one" | |
| Shrinking geometric () | a constant | |
| Harmonic | ||
| Constant |
Notation in this course: , . In Big-O the base doesn't matter (change-base rule).
Logs as halving: the staircase
| Step | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Size | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
6 halvings reach 1, so . Double and you add just one step. That's why grows so slowly.
| 8 | 1 024 | 1 048 576 (≈ a million) | ≈ a billion | |
|---|---|---|---|---|
| 3 | 10 | 20 | 30 |
Gauss's pairing trick for (here )
1 2 3 4
8 7 6 5 ← same numbers written backwards
---------------
9 9 9 9 ← every pair sums to n+14 pairs × 9 = 36 = . In general, pairs of give .
Powers of 2: each term beats everything before it
1 + 2 + 4 + 8 = 15 next term = 16 = 15 + 1
■ ■■ ■■■■ ■■■■■■■■So . The largest term dominates: the total is less than twice the last term.
Common mistakes
- . Only products split.
- . The first is "log squared"; the second equals .
- is not . It's about .
- Off-by-one in sums: has terms.
Mastery check
Solve without hints, then explain in your own words
(a) Find a closed form for and check it with .
(b) How many times can you halve 4096 before reaching 1?
(c) Simplify .
(a) . With : and ✓
(b) , so 12.
(c) .
Status
Tick all six steps to unlock “Mastered”.
Which study mode worked for you?
See it move
- Desmos: plot , and together to see which grows faster.
References
- Lecture06 Algorithm Analysis: Mathematical Background: Slides 13–21 (logarithms), 22–26 (series).
- CLRS 4e §3.3 (standard functions: logs, exponentials) and Appendix A (summations, A.1–A.2).