O(n ^ 2)vs O(n(logn)^ 2) [英] O(n^2) vs O (n(logn)^2)

查看:1795
本文介绍了O(n ^ 2)vs O(n(logn)^ 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是时间复杂度 O(n ^ 2) O(n(logn)^ 2)

我知道当我们简化它时,它变成

I know that when we simplify it, it becomes

O(n) vs O((logn)^2)

logn < n ,但是 logn ^ 2

推荐答案

n 仅比 log n) 2 n 小于0.49 ...

n is only less than (log n)2 for values of n less than 0.49...

所以一般日志 n) 2 对于较大的 n 更好...

So in general (log n)2 is better for large n...

但是由于这些 / em>(某事) - 总是留下常数因素,在您的情况下,可能无法确定哪种算法更好...

But since these O(something)-notations always leave out constant factors, in your case it might not be possible to say for sure which algorithm is better...

这是一个图:

(蓝线是 n ,绿线是日志 n) 2

(The blue line is n and the green line is (log n)2)

请注意, n 的小值的差异不会太大,容易被不包括在Big-O中的常数因素所抵消

Notice, how the difference for small values of n isn't so big and might easily be dwarfed by the constant factors not included in the Big-O notation.

但是对于大的 n log n) 2 获胜双手:

But for large n, (log n)2 wins hands down:

这篇关于O(n ^ 2)vs O(n(logn)^ 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆