When articles/question state that the Big O running time of the algorithm is O(LogN) .
For example Quicksort has a Big O running time of O (LogN) where the it is Log base 10 but Height of binary tree is O(LogN+1) where it is Log base 2
Question
1)I am confused over whether is it Log base 10 or Log base 2 as different articles use different bases for their Logarithm .
2) Does it make a difference if its Log base 2 or Log base 10??
3)Can we assume it mean Log base 10 when we see O(LogN)???
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) .
Yes you can assume that provided you know the base conversion rule. Well, that's only true if the base of the log is a constant. log_2 n is similar to log_10 n but not to log_n n . :) @dg99:- I have updated my answer.
I think it does not matter what is the base of the log as the relative complexity is the same irrespective of the base used.
So you can think of it as O(log2X) = O(log10X)
Also to mention that logarithms are related by some constant.
So
So most of the time we generally disregard constants in complexity analysis, and hence we say that the base doesn't matter.
Also you may find that the base is considered to be 2 most of the time like in Merge Sort. The tree has a height of log₂ n
, since the node has two branches.
1)I am confused over whether is it Log base 10 or Log base 2 as different articles use different bases for their Logarithm .
So as explained above this change of base doesn't matter.
2) Does it make a difference if its Log base 2 or Log base 10??
No it does not matter.
3)Can we assume it mean Log base 10 when we see O(LogN)???
Yes you can assume that provided you know the base conversion rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With