Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Big O(logn) log base e?

For binary search tree type of data structures, I see the Big O notation is typically noted as O(logn). With a lowercase 'l' in log, does this imply log base e (n) as described by the natural logarithm? Sorry for the simple question but I've always had trouble distinguishing between the different implied logarithms.

like image 461
BuckFilledPlatypus Avatar asked Oct 15 '09 00:10

BuckFilledPlatypus


People also ask

Can you have log base e?

The number e frequently occurs in mathematics (especially calculus) and is an irrational constant (like π). Its value is e = 2.718 281 828 ... Apart from logarithms to base 10 which we saw in the last section, we can also have logarithms to base e. These are called natural logarithms.

Is log loge or log10?

The common log can be represented as log10 (x). The natural log can be represented as loge (x). The interrogative statement for the common logarithm is written as “At which number should we raise 10 to get y?”

Why we take E as a base in log?

e is used because many computations are easy if you use base e. Think in the derivative of e^x vs a^x. However a^x = e^(c x) for some c. The exponential functions are useful for modeling many systems that occur in our natural world, as well as for modeling economics.


2 Answers

Big O notation is not affected by logarithmic base, because all logarithms in different bases are related by a constant factor, O(ln n) is equivalent to O(log n).

enter image description here

like image 122
Cade Roux Avatar answered Sep 20 '22 00:09

Cade Roux


Once expressed in big-O() notation, both are correct. However, during the derivation of the O() polynomial, in the case of binary search, only log2 is correct. I assume this distinction was the intuitive inspiration for your question to begin with.

Also, as a matter of my opinion, writing O(log2 N) is better for your example, because it better communicates the derivation of the algorithm's run-time.

In big-O() notation, constant factors are removed. Converting from one logarithm base to another involves multiplying by a constant factor.

So O(log N) is equivalent to O(log2 N) due to a constant factor.

However, if you can easily typeset log2 N in your answer, doing so is more pedagogical. In the case of binary tree searching, you are correct that log2 N is introduced during the derivation of the big-O() runtime.

Before expressing the result as big-O() notation, the difference is very important. When deriving the polynomial to be communicated via big-O notation, it would be incorrect for this example to use a logarithm other than log2 N, prior to applying the O()-notation. As soon as the polynomial is used to communicate a worst-case runtime via big-O() notation, it doesn't matter what logarithm is used.

like image 29
10 revs Avatar answered Sep 23 '22 00:09

10 revs