I've found plenty of sources claiming that the time complexity of the prime sieving algorithm Sieve of Eratosthenes is O(nlog(logn)) where n is the input. However, is this log10 or ln? I assume it's ln but according to some notational conventions, just log refers to log10 and I can't find a source that clarifies this problem.
Does anyone know?
EDIT: I know that in a case where you have only one logarithm, you can scale between different bases using constants. However, this is not true when you have several nested logarithms. I.e. log10(log10n)/ln(lnn)) does not equal log10(log10(n+1))/ln(ln(n+1))). Because of this, the logarithmic base does matter here. (I think, correct me if I'm wrong).
Answer
Big O complexity in terms of nested logarithms is base independent for the same reason it is in the case of single logarithms. For example, log10x=clog2x for the constant c=log102, as you have noted.
Likewise, using a specific example, log10log10x=dlog2log2x for some d that approaches (but does not equal) log102. This is because log10log10x=log10(clog2x)=log10c+log10log2x=log10c+clog2log2x. The factor by which the c in the second term is multiplied, log2log2x, approaches infinity, so c can be replaced with a slightly larger d, and eventually that will increase the value of the second term enough to account for the constant added to it, log10c.
For this reason, most logarithmic expressions (but not all) that typically show up in big O notation are base independent, so no base need be specified.
That being said, if no base is specified, and there is no obvious reason it should be 10 or something else, you can assume a base of e. It is on the author if that assumption is false when no other base was specified.
No comments:
Post a Comment