比较大O表示法

编程入门 行业动态 更新时间:2024-10-23 01:38:19
本文介绍了比较大O表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在n元素数组中进行排序处理; 在X算法中:10 -8 n 2 秒, 在Y算法10 -6 n log 2 n sec, 在Z算法10 -5 秒中.

In n-element array sorting processing takes; in X algorithm: 10-8n2 sec, in Y algoritm 10-6n log2n sec, in Z algoritm 10-5 sec.

我的问题是我该如何比较它们.例如,对于y,根据x可以更快地工作,我应该选择哪个元素数量?

My question is how do i compare them. For example for y works faster according to x, Which should I choose the number of elements ?

推荐答案

比较Big-Oh表示法时,您将忽略所有常量:

When comparing Big-Oh notations, you ignore all constants:

N ^ 2具有比N * log(N)更高的增长率,后者仍比O(1)[恒定]更快.

N^2 has a higher growth rate than N*log(N) which still grows more quickly than O(1) [constant].

N的幂决定增长率.

The power of N determines the growth rate.

示例:

O(n^3 + 2n + 10) > O(200n^2 + 1000n + 5000)

忽略常量(您应该进行纯大欧姆比较),这可以简化为:

Ignoring the constants (as you should for pure big-Oh comparison) this reduces to:

O(n^3 + n) > O(n^2 + n)

进一步降低而忽略低阶术语,则得出结果:

Further reduction ignoring lower order terms yields:

O(n^3) > O(n^2)

因为N 3 > 2的幂.

Big-Oh遵循这样的层次结构:

Big-Oh follows a hierarchy that goes something like this:

O(1) < O(log[n]) < O(n) < O(n*log[n]) < O(n^x) < O(x^n) < O(n!)

(其中x大于1的任何量,甚至最小的位.)

(Where x is any amount greater than 1, even the tiniest bit.)

您可以通过一些规则来比较其他任何以n表示的表达式,这些规则我不会在此处发布,但是应该在Wikipedia中进行查找.我列出O(n*log[n])是因为它在排序算法中很常见.有关具有不同底数或不同幂的对数的详细信息,请查看参考源(我是否提到了Wikipedia?)

You can compare any other expression in terms of n via some rules which I will not post here, but should be looked up in Wikipedia. I list O(n*log[n]) because it is rather common in sorting algorithms; for details regarding logarithms with different bases or different powers, check a reference source (did I mention Wikipedia?)

试一下Wiki文章: en.wikipedia/wiki/Big_O_notation

Give the wiki article a shot: en.wikipedia/wiki/Big_O_notation

更多推荐

比较大O表示法

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

发布评论

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

>www.elefans.com

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