Foundations
Exponentials and logarithms
Growth, decay, and the inverse that tames them
Two operations that undo each other: one multiplies over and over, the other counts how many times you multiplied, or halved.
Exponentials and logarithms are inverse twins. An exponential like says "multiply by 2, ten times" and lands on . A runs the film backwards: asks "how many times did I multiply, or, going down, how many times can I halve?" and answers . Hold onto that second reading of a log as a count of halvings: it is the entire reason binary search and balanced trees are so astonishingly fast.
The one question a logarithm answers
Multiply up, count back down
An exponential function multiplies the base by itself times. When you get growth, , each step multiplies so the curve rockets upward. When you get decay, , halving toward zero. This is the same shape behind compound interest, radioactive half-lives, and a search space that halves every step.
One base shows up so often it gets its own letter: , the natural base. It is the growth rate at which a curve's steepness always equals its current height, and it falls out of continuous compounding as when . The logarithm is the inverse function: give it a result, it hands back the exponent. Because it is an inverse, every fact about exponents flips into a fact about logs.
A logarithm counts halvings
Here is the aha you can feel with your hands. Pick a pile of items. Cut it in half, then halve what remains, and keep going until a single item is left. The number of cuts you make is exactly . Set with the slider, then step the halving and watch the tally close in on the computed logarithm.
Why +1 per doubling is a superpower
The same idea in code: a log is a loop that halves.
# how many times can we halve n before hitting 1?
def halvings(n):
count = 0
while n > 1:
n = n // 2 # cut the pile in half
count += 1
return count # == floor(log2 of the original n)
halvings(1024) # -> 10, because 2**10 == 1024The log rules, and change of base
Because logs undo exponents, the exponent laws become the log laws. These three turn multiplication into addition, the trick that made slide rules and, later, fast numeric code possible.
A quiet but huge consequence: , , and differ only by a constant factor. That is precisely why Big-O writes with no base at all: the base only changes a constant, and Big-O throws constants away.
Inverses mirror across the diagonal
Because and are inverse functions, their graphs are reflections of each other across the line . Whatever the exponential sends , the logarithm sends straight back. Drag the base and watch the two curves swing as perfect mirror images.
Check yourself
You keep halving 256 items until a single one remains. How many cuts is that?
By the power rule, the log of x raised to the k-th power rewrites as:
Why does binary search cost about log2(n) rather than n?
Think about what each comparison removes. Try to state it, then check.
Lock it in
- An exponential multiplies repeatedly; a log recovers the exponent.
- Read log2(N) as the number of times you can halve N down to 1.
- Doubling the data adds only one step: the O(log n) superpower.
- Logs of different bases differ by a constant, so Big-O drops the base.
Primary source
Where this reappears