哪个更好:O(n log n)或O(n ^ 2)

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

好的,我有这个项目要做,但我只是不理解。问题是,我有2种算法。 O(n ^ 2)和 O(n * log 2 n)。

无论如何,我在项目信息中发现,如果 n< 100 ,则 O(n ^ 2)效率更高,但是如果 n> = 100 ,则 O(n * log 2 n)效率更高。我想用数字和单词或画一张照片来举例说明。但是,问题是,我不明白这一点,也不知道如何证明这一点。

这里有人可以帮助我了解其工作原理吗? p>

提前加油!

编辑:谢谢大家的答复。

解决方案

只需问 wolframalpha 。

在这种情况下,它表示

n log(n) lim --------- = 0 n ^ 2

或者您也可以自己计算限制:

n log(n)log(n)(Hôpital)1 / n 1 lim --------- = lim -------- = lim ------- = lim --- = 0 n ^ 2 n 1 n

这意味着 n ^ 2 增长更快,因此当 n 足够高。 / p>

Okay so I have this project I have to do, but I just don't understand it. The thing is, I have 2 algorithms. O(n^2) and O(n*log2n).

Anyway, I find out in the project info that if n<100, then O(n^2) is more efficient, but if n>=100, then O(n*log2n) is more efficient. I'm suppose to demonstrate with an example using numbers and words or drawing a photo. But the thing is, I don't understand this and I don't know how to demonstrate this.

Anyone here that can help me understand how this works?

Cheers in advance!

EDIT: Thanks all for the replies.

解决方案

Just ask wolframalpha if you have doubts.

In this case, it says

n log(n) lim --------- = 0 n^2

Or you can also calculate the limit yourself:

n log(n) log(n) (Hôpital) 1/n 1 lim --------- = lim -------- = lim ------- = lim --- = 0 n^2 n 1 n

That means n^2 grows faster, so n log(n) is smaller (better), when n is high enough.

更多推荐

哪个更好:O(n log n)或O(n ^ 2)

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

发布评论

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

>www.elefans.com

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