Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

In computer science, does 'log n' automatically imply base 2?

$
0
0
In computer science, does 'log n' automatically imply base 2?

I'm asking this silly question because I found myself trying to recall the formula for the height of a complete binary tree, to help answer the question in C++ forum about QuickSort overflowing its stack. Since it's been many years since college, all I could recall was that tree operations typically cost O(log n), and this was based on the average depth/height of a tree. So just doing a quick search without actually reading the rest of text, I found the formula the the height of a complete binary tree was log(n + 1) where n is the number of nodes.

Hitting numbers in a calculator was giving me odd results though. For example, a binary tree with height of 3, will have 23-1 == 7 nodes. But log(7+1) == log(8) ~= 0.903. Not even close to 3. Trying ln(8) ~= 2.07, close but not yet there. It was only after I tried log2(8) did I get the correct answer.

If somebody offers a choice between algorithms that are O(log n) vs O(ln n) vs O(log5 n), should I assume it is log2 n, or stop and ask whether it is log10 n?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>