Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...