Skip to content

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

asks: to what power must I raise the base to reach ? So because , and because . The exponential builds the number up; the log recovers the exponent. Formally they cancel: and .

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.

064
remaining: 64cuts so far: 0log2 N = 6

Why +1 per doubling is a superpower

Going from to adds a single extra halving: . So searching a thousand sorted items takes about 10 probes (); a million takes about 20; a billion about 30. A thousand-fold jump in data costs ten more steps. That is the flat, forgiving curve you meet in the next module.

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 == 1024
The count of halvings is floor(log2 n).

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

Drag the base b. The dashed diagonal is the mirror; the dots are a matched pair, (1, b) reflected to (b, 1).
y = bˣy = logᵦ xy = x
y = bx y = logb x

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

For scaffolded practice with the log rules and change of base, work through Khan Academy on logarithms. For the constant built up from first principles, watch 3Blue1Brown, Essence of Calculus.

Where this reappears

In the DSA module, logs explain the whole complexity class: every "halve the problem" algorithm lives there. On the LLM path, returns as information entropy, the number of bits needed to pin down one outcome.