I am currently learning about big O notation in my algorithms class and I stumbled upon this particular problem that perplexed me. Can we represent O(n lg(n)) as c * n* lg n if we know the formal definition holds? Meaning, if f(n) <= c n lg n, and the definition holds true for some constants, then O(n lg n) can be represented as c* n* lg n? And if my assumption is true, then we could do:
= lg(O(n lg n))
= lg(c* n* lg n)
= lg(c) + lg(n) +lg(lg(n))
If lg(n) is the highest order term in this case, then would this simplify to be O(lg(n))? Since all the lower order terms would eventually be overlapped by the highest order term?
Your question is a little hard to follow. I think you are asking:
Suppose we have a function
f
that grows asymptotically at or less than a rate ofO(n lg n)
. Does the functionlg ∘ f
grow asymptotically at or less than a rate ofO(lg n)
?
Yes, it does.
UPDATE: Commenter Paul Hankin points out a counterexample. Perhaps this is correct?
Suppose we have a function
f
that grows asymptotically at exactly a rate ofO(n lg n)
. Does the functionlg ∘ f
grow asymptotically at a rate ofO(lg n)
?
I think the answer to that is yes.
You're trying to show that lg(O(n lg n)) = O(lg n)
. This is somewhat non-standard notation, but it means that for all f
in O(n lg n)
, there's a g
in O(lg n)
such that log(f) = g
. This is explained on wikipedia here: https://en.wikipedia.org/wiki/Big_O_notation#Multiple_usages
The statement isn't quite true as written. For example, f = 2^(-n)
is in O(n lg n)
, but lg(f) = -n
which isn't in O(lg n)
. But if we limit ourselves to f
's which are greater than 1
, then it's true.
If f = O(n lg n)
, then there's a c
such that for all sufficiently large n
, f(n) < cn lg n
. Then lg(f(n)) < lg(c) + lg(n) + lg(lg(n)) = O(lg n)
. Since lg(f(n)) > 0
, we have have that lg(f(n)) = O(lg n)
. This is essentially your proof from the question with a little additional care taken about definitions and making sure that lg(f(n))
isn't large and negative.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.