大O标记

编程入门 行业动态 更新时间:2024-10-19 07:35:34
本文介绍了大O标记-更复杂意味着更快或更慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习大O表示法,我有点困惑.我不认为我真的了解复杂性"如何影响算法,也无法确定我是否在向后看.

I'm learning about big O notation and I'm kind of confused. I don't think I really get how "complexity" effects an algorithm, and I can't tell if I'm looking at things backwards.

从最小到最复杂的顺序是:O(1),O(log n),O(n),O(n log n),O(n ^ 2)?还是我倒退了?

is the order of complexity from least to most complex: O(1), O(log n), O(n), O(n log n), O(n^2)? or do I have it backwards?

如果这是正确的顺序,那么我猜想一个复杂度为O(n ^ 2)的程序将比带有O(n log n)的程序更快地处理大量数据.但是,在测试冒泡排序(O(n ^ 2))和快速排序(O(n log n))之后,很明显O(n ^ 2)排序的处理速度比O(n log n)慢.所以我很困惑....复杂性是好是坏?如果算法更复杂,算法会更快(就完成程序而言需要花费多长时间)?或者,复杂的程序会更慢吗?

If this is the correct order, I would guess that a program with a complexity of O(n^2) would process large sets of data faster than a program with O(n log n). However after testing a bubble sort(O(n^2)) and a quick sort (O(n log n)), it's obvious that the O(n^2) sort processed WAY slower than O(n log n). So I'm confused.... is complexity good or bad? Will an algorithm be fast(in terms of how long it takes to complete the program) if it's more complex, or will a complex program will be slower?

推荐答案

O表示计算机将对具有该算法将要处理的对象的 maximum 个元素进行数量运算. .例如,您使用具有O(n ^ 2)的算法对具有3个元素的数组进行排序,这意味着计算机将对该数组最多执行 9次操作.

O notation means the number operations that a computer will do with the maximum number of elements that have the object that the algorithm will process. For example, it you sort an array with 3 elements with an algorithm that has O(n^2), it means that the computer will do a maximum of 9 operations over the array.

在这里您可以查看不同O复杂度之间的比较:

Here you can look at a comparison between different O complexities:

更多推荐

大O标记

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

发布评论

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

>www.elefans.com

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