我正在学习大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标记
发布评论