简体   繁体   English

功能增长大

[英]big O in Growth of Functions

Suppose we have two algorithms, A and B , for solving some problem (say multiplying two n × n matrices, or sorting an array n of integers). 假设我们有两种算法AB用于解决某些问题(例如,将两个n×n矩阵相乘,或对整数n进行排序)。 Let n denote the input size of the problem, and let T A (n) and T B (n) denote the number of steps taken by algorithms A and B , respectively, on inputs of size n . n表示问题的输入大小,令T A (n)T B (n)表示算法AB在大小为n的输入上分别采取的步骤 It is known that T A (n) = O(n 3 ) and T B (n) = O(n 5 ) . 已知T A (n)= O(n 3T B (n)= O(n 5 Is it true that for sufficiently large n , algorithm A performs less steps than algorithm B ? 如果n足够大,算法A执行的步骤少于算法B的步骤吗? Why or why not? 为什么或者为什么不?

First, I suppose you meant that the bounds are O(n 3 ) and O(n 5 ) (ie, powers of 3 and 5, respectively). 首先,我想你的意思是边界是O(n 3O(n 5 (即分别为3和5的幂)。

Since O is an upper bound , you can't really say anything about the comparisons. 因为O是一个上限 ,所以您不能真正说出比较。 For example: 例如:

  • n 2 = O(n 3 ) , and n 1.5 = O(n 5 ) , but, even for large n , the former function is larger than the latter. n 2 = O(n 3n 1.5 = O(n 5 ,但是,即使对于较大的n ,前者的功能也要大于后者。

  • Conversely, n 1.5 = O(n 3 ) , and n 2 = O(n 5 ) , and here, for large n , the former function is indeed larger than the latter. 相反, n 1.5 = O(n 3n 2 = O(n 5 ,在这里,对于较大的n ,前一个函数的确大于后者。

If the question would be about Θ , not O , the answer would be different - in that case, you could state that, for large enough n , the former performs less steps than the latter. 如果问题是关于θ而不是O ,那么答案将有所不同-在那种情况下,您可以说,对于足够大的n ,前者执行的步骤少于后者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM