I got asked an interview question that wanted me to discern the Big-O notation of several logarithmic functions. The functions were as follows:
f(x) = log5
This is a matter of math:
So the Big O is
So (1) and (2) aren't equivalent, but (3) and (4) are (though they're different from both (1) and (2))
f(x) = log^5(n)
f(x) = log(n^5) -> 5 log(n)
O(5 log(n)) < O(log(n)^5)
f(x) = log(6*log n) -> log(6)+log(log(n))
f(x) = log(log n)
log(log n) < log(6) + log(log(n))
, although log(6) is a constant so they have same O
So you have O(log log log log log x), O(log x), O(log log x) and O(log log x), three distinct Big-O classes.
If your interviewer said 3 and 4 were different, either he was mistaken or you've misremembered the question (happens all the time).
I'll assume you mean f(n)
, not f(x)
. For 1 and 2, log^5(n)
is equivalent to O(log log log log log(n))
, while log(n^5) = 5 log(n) = O(log n)
.
For 3 and 4, I disagree. log(6*log n) = log(6) + log(log n) = O(log log n)
, which is the same as 4 - O(log log n)
.