DAA Study Hub

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 log⁡264=6\log_2 64 = 6. 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

RuleFormulaPlain words
Definitionlog⁡bx=y  ⟺  by=x\log_b x = y \iff b^y = x"What power of bb gives xx?"
Productlog⁡b(xy)=log⁡bx+log⁡by\log_b(xy) = \log_b x + \log_b ymultiply inside → add outside
Quotientlog⁡b(x/y)=log⁡bx−log⁡by\log_b(x/y) = \log_b x - \log_b ydivide inside → subtract outside
Powerlog⁡b(xa)=alog⁡bx\log_b(x^a) = a\log_b xexponent jumps out to the front
Undoblog⁡bx=xb^{\log_b x} = xa power and a log cancel
Change baselog⁡cx=log⁡bxlog⁡bc\log_c x = \dfrac{\log_b x}{\log_b c}all logs differ only by a constant
Swap trickalog⁡bc=clog⁡baa^{\log_b c} = c^{\log_b a}handy in recurrences
Exponents2a⋅2b=2a+b2^a\cdot 2^b = 2^{a+b}, (2a)b=2ab(2^a)^b = 2^{ab}
Arithmetic sum∑i=1ni=n(n+1)2\sum_{i=1}^{n} i = \dfrac{n(n+1)}{2}Θ(n2)\Theta(n^2)
Squares∑i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^{n} i^2 = \dfrac{n(n+1)(2n+1)}{6}Θ(n3)\Theta(n^3)
Geometric (r≠1r\ne1)∑i=0kri=rk+1−1r−1\sum_{i=0}^{k} r^i = \dfrac{r^{k+1}-1}{r-1}
Powers of 2∑i=0k2i=2k+1−1\sum_{i=0}^{k} 2^i = 2^{k+1}-1"the next power, minus one"
Shrinking geometric (0<r<10<r<1)∑i=0∞ri=11−r\sum_{i=0}^{\infty} r^i = \dfrac{1}{1-r}a constant
Harmonic∑i=1n1i≈ln⁡n\sum_{i=1}^{n} \dfrac1i \approx \ln nΘ(log⁡n)\Theta(\log n)
Constant∑i=1nc=cn\sum_{i=1}^{n} c = cn

Notation in this course: lg⁡n=log⁡2n\lg n = \log_2 n, ln⁡n=log⁡en\ln n = \log_e n. In Big-O the base doesn't matter (change-base rule).


Logs as halving: the staircase

Step0123456
Size6432168421

6 halvings reach 1, so log⁡264=6\log_2 64 = 6. Double nn and you add just one step. That's why log⁡n\log n grows so slowly.

nn81 0241 048 576 (≈ a million)≈ a billion
log⁡2n\log_2 n3102030

Gauss's pairing trick for 1+2+⋯+n1+2+\dots+n (here n=8n = 8)

 1   2   3   4
 8   7   6   5      ← same numbers written backwards
---------------
 9   9   9   9      ← every pair sums to n+1

4 pairs × 9 = 36 = 8⋅92\frac{8\cdot 9}{2}. In general, n/2n/2 pairs of (n+1)(n+1) give n(n+1)2\frac{n(n+1)}{2}.

Powers of 2: each term beats everything before it

1 + 2 + 4 + 8 = 15        next term = 16 = 15 + 1
■ ■■ ■■■■ ■■■■■■■■

So 1+2+⋯+2k=2k+1−11 + 2 + \dots + 2^k = 2^{k+1}-1. The largest term dominates: the total is less than twice the last term.


Common mistakes

  • log⁡(a+b)≠log⁡a+log⁡b\log(a + b) \ne \log a + \log b. Only products split.
  • (log⁡n)2≠log⁡(n2)(\log n)^2 \ne \log(n^2). The first is "log squared"; the second equals 2log⁡n2\log n.
  • ∑i=1ni\sum_{i=1}^{n} i is not nn. It's about n2/2n^2/2.
  • Off-by-one in sums: ∑i=0k2i\sum_{i=0}^{k} 2^i has k+1k+1 terms.

Mastery check

Solve without hints, then explain in your own words

(a) Find a closed form for ∑i=1n(3i−1)\sum_{i=1}^{n}(3i - 1) and check it with n=4n = 4.

(b) How many times can you halve 4096 before reaching 1?

(c) Simplify log⁡2(16 n5)\log_2(16\,n^5).

Your mastery check
Not started
Solve the problem above with no hints, close the page and explain it out loud. Tick each step honestly.
Mastery checklist

Status

Tick all six steps to unlock “Mastered”.

Which study mode worked for you?

Saved in this browser onlySee all my progress →

See it move

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).

On this page