Table of Contents

Logarithms come up a lot in algorithms. Review how they work and learn the situations where they're…

What logarithm even means

Here's what a logarithm is asking:

"What power must we raise this base to, in order to get this answer?"

So if we say:


The 10 is called the base (makes sense – ite's on the bottom). Think of the 100 as the "answer." It's what we're taking the log of. So this expression would be pronounced "log base 10 of 100."

And all it means is, "What power do we need to raise this base (10) to, to get this answer (100)?"

10x = 100

What x gets us our result of 100? The answer is 2:

102 = 100

So we can say:

log10100 = 2

The "answer" part could be surrounded by parentheses, or not. So we can say log10(100) or log10100. Either one's fine.

What logarithms are used force

The main thing we use logarithms for is solving for x when x is in an exponent.

So if we wanted to solve this:

10x = 100

We need to bring the x down from the exponent somehow. And logarithms give us a trick for doing that.

We take the log10 of both sides (we can do this – the two sides of the equation are still equal):

log1010x = log10100

Now the left-hand side is asking, "what power must we raise 10 to in order to get 10x?" The answer, of course, is x . So we can simplify that whole left side to just "x":

x = log10100

We've pulled the x down from the exponent!

Now we just have to evaluate the right side. What power do we have to raise 10 to in order to get 100? The answer is still 2.

x = 2

That's how we use logarithms to pull a variable down from an exponent.

Logarithm rules

These are helpful if you're trying to do some algebra stuff with logs.

Simplification: logb(bx) = x … Useful for bring a variable down from an exponent.

Multiplication: logb(x * y) = logb(x) + logb(y)

Division: logb(x / y) = logb(x) - logb(y)

Powers: logb(xy) = y * logb(x)

Change of base: logb(x) = logc(x) / logc(b) … Useful for changing the base of a logarithm from b to c.

Where logs come up in algorithms and interviews

Date: 2020-01-30 Thu 11:18

Author: Jack Liu

Created: 2020-02-08 Sat 21:26