为O(n ^ 2)对为O(n​​(LOGN)^ 2)

编程入门 行业动态 更新时间:2024-10-22 12:32:07
本文介绍了为O(n ^ 2)对为O(n​​(LOGN)^ 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

时的时间复杂度为O(n ^ 2)或 O(N(LOGN)^ 2)更好?

Is time complexity O(n^2) or O (n(logn)^2) better?

我知道,当我们把它简化,它变得

I know that when we simplify it, it becomes

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

和 LOGN < N ,但对于 LOGN ^ 2 ?

and logn < n, but what about logn^2?

推荐答案

N 仅小于(登录的N) 2 作为值的 N 小于0.49 ...

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

所以一般来说(登录的N) 2 是大型的ñ更好

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

不过,由于这些的的 0 的(东西) -notations总是忽略常数因子,在你的情况下,它可能无法肯定地说哪种算法比较好..

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 小的值的差别并不大,而且可能很容易被不包括在大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 (登录的N) 2 胜手了:

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

更多推荐

为O(n ^ 2)对为O(n​​(LOGN)^ 2)

本文发布于:2023-11-29 16:36:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LOGN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!