Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Introduction to Algorithms Time Complexity Constant and Logarithmic Time

finding a logarithm

Is there a mistake in the video on finding a logarithm explanation, or am I wrong? Pasan is saying at 4:29 "So if I say log to the base 2 of 8 = 3, I'm basically saying the opposite of an exponent. Instead of saying how many times do I have to multiply this value, I'm asking, how many times do I have to divide 8 by 2 to get the value 3 (he is saying 1 for some reason though)?"

I agree with everything except the very last sentence. I don't think it will be correct to say that we can calculate a logarithm by finding how many times we have to divide its argument (in our case 8) by its base (in our case 2) to get the answer. The correct answer is 3, but we won't be able to achieve it with division by 2: I. 8 : 2 = 4 II. 4 : 2 = 2

Please correct me if I am wrong on that. (P.S. Sorry, I don't know how to write subscripts here in the forum)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Veronika Post! He is correct. He's saying that you have to determine how many times 8 will be divided by 2 to get to the value of one, not two.

Here's a quote from 4:40 in the video:

I'm asking, how many times do I have to divide 8 by 2 to get the value 1?

8 / 2 = 4  // 1 division
4 / 2 = 2  // 2 divisions
2 / 2 = 1  // 3 divisions

When determining the logarithm we are dividing backwards to a value of one. Note that I'm using ^ to denote "to the power of":

  • 2^0 = 1
  • 2^1 = 2
  • 2^2 = 4
  • 2^3 = 8

Hope this helps! :sparkles:

Hi Jennifer Nordell, thank you for your reply! I see now that Pasan said "get the value 1" in the video, not by mistake, as I thought before, but on purpose. I tried googling this way of "unwinding" logarithms, but couldn't find anything unfortunately. Does it work for all cases, or only for cases with positive exponents? I see that it works for our example, but it doesn't seem that it would work for:

  • fractional exponent: 25^1/2 = 5 => log_25 (5) = 1/2
  • negative exponent: 2^-3 = 1/8 => log_2 (1/8) = -3

Maybe you can forward me to some external resource that explains this method?, sorry I just feel confused.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Veronika Post Honestly, your best bet would probably be to go to Khan Academy and do the lessons there on exponents and logarithms. This "unwinding" technique works for positive whole exponents. Fractional exponents indicate a "root". An exponent of 1/2 is the same thing as the square root. An exponent of 1/3 is the cubed root. A negative exponent is 1 over the base. So in your last example with the -3, it is one divided by two to the third power.

I would probably start with practicing exponents. Once you get that, move on to logarithms. A solid foundation in working with exponents will make the logarithm seem more obvious. :smiley:

Hope this helps! :sparkles:

Hi Jennifer Nordell,

that is exactly what I did right after I watched TeamTreehouse video about logarithms. I went to Khan Academy and brushed up on my exponent and logarithm skills. And I understand what you were talking about, the method of dividing logarithm argument (sometimes called answer, number or result) by logarithm base till we get 1 does work, but only for positive exponents, meaning if we have log_a (x) = y, this will work for only for a > 0, meaning that we cannot generalize and use it as a method to calculate any logarithm. I do know that number with a fractional exponent can be represented as a root of a number, and that a number with a negative exponent can be represented as its reciprocal. And it seems to me that in both cases trying to calculate logarithm by dividing logarithm argument by logarithm base till we get 1 won't work.

I might be wrong on that, I am going to ask my university math center about that and will let you know.