什么是Big O符号?你会用吗?

编程入门 行业动态 更新时间:2024-10-26 00:22:09
本文介绍了什么是Big O符号?你会用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么是Big O符号?您使用它吗?

我想念这堂大学课:D

有人使用它并提供一些现实生活中使用它的示例吗?

另请参见:

>八岁孩子的Big-O吗? 大O,您如何计算/近似呢? >您是否在现实生活中应用了计算复杂性理论?

解决方案

大多数人在谈论Big-O时忘记了一件重要的事情,因此,我觉得有必要提一下:

您不能使用Big-O比较两种算法的速度. Big-O仅表示如果将处理的项目数量加倍,算法将变慢多少(大约),或者如果将数量减少一半,则算法变快多少.

但是,如果您有两种完全不同的算法,并且一个(A)是O(n^2),另一个(B)是O(log n),则不能说A的速度比.实际上,对于100个项目,A可能比B快十倍.它仅表示,对于200个项目,A的增长速度将降低n^2,而B的增长速度将下降log n倍.因此,如果您对两者进行基准测试,并且知道A处理100个项目需要花费多少时间,并且B对于相同的100个项目需要多少时间,并且A比B更快,则可以计算B的数量将超过速度A的数量(因为B的速度下降的速度比A的速度慢得多,所以迟早会超过A-这是肯定的). /p>

What is Big O notation? Do you use it?

I missed this university class I guess :D

Does anyone use it and give some real life examples of where they used it?

See also:

Big-O for Eight Year Olds? Big O, how do you calculate/approximate it? Did you apply computational complexity theory in real life?

解决方案

One important thing most people forget when talking about Big-O, thus I feel the need to mention that:

You cannot use Big-O to compare the speed of two algorithms. Big-O only says how much slower an algorithm will get (approximately) if you double the number of items processed, or how much faster it will get if you cut the number in half.

However, if you have two entirely different algorithms and one (A) is O(n^2) and the other one (B) is O(log n), it is not said that A is slower than B. Actually, with 100 items, A might be ten times faster than B. It only says that with 200 items, A will grow slower by the factor n^2 and B will grow slower by the factor log n. So, if you benchmark both and you know how much time A takes to process 100 items, and how much time B needs for the same 100 items, and A is faster than B, you can calculate at what amount of items B will overtake A in speed (as the speed of B decreases much slower than the one of A, it will overtake A sooner or later—this is for sure).

更多推荐

什么是Big O符号?你会用吗?

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

发布评论

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

>www.elefans.com

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