Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

math - What is the Big O of "n + log?log?(n^2)"?

Hello everyone my question is that what is the big O of n + loglog(n^2) and why?

I think it should be O(n) but my teacher just told me that my answer is wrong... can someone explain to me why?

question from:https://stackoverflow.com/questions/65911089/what-is-the-big-o-of-n-loglogn2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your answer O(n) is correct. Google logarithm rules (easy to forget if you don't use it often) and find in particular the power law and the multiplication law. By applying the power law first and then the multiplication law we can reduce your equation like this:

enter image description here

I have used Wolfram Alpha to quickly plot the reduced version:

enter image description here

If you 'zoom out' a little bit as presented on the second graph you can see that the function behaves as a logarithm (up to X = 2 roughly) and linear for X > 2. This is why in big O notation we say that the linear term n is dominant over the logarithm in this case as it is of the highest power and dictates the algorithm scaling behavior.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...