Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Time complexity 时间复杂性:我们如何找到O(n^3)?_Time Complexity - Fatal编程技术网

Time complexity 时间复杂性:我们如何找到O(n^3)?

Time complexity 时间复杂性:我们如何找到O(n^3)?,time-complexity,Time Complexity,我知道f(n)=3*n^3+4*n+2有O(n^3)的复杂性,但我想知道如何使用大O的定义来计算它: If f(n) has complexity O(g(n)), that means there exists a constant c > 0, n0 >=1 where f(n) < c*g(n) 如果f(n)的复杂度为O(g(n)),这意味着存在一个常数c>0,n0>=1,其中f(n)=1,n^3>=n>=1,所以 f(n) = 3*n^3 + 4*n + 2

我知道
f(n)=3*n^3+4*n+2
有O(n^3)的复杂性,但我想知道如何使用大O的定义来计算它:

If f(n) has complexity O(g(n)), that means there exists a constant c > 0, n0 >=1 where f(n) < c*g(n)
如果f(n)的复杂度为O(g(n)),这意味着存在一个常数c>0,n0>=1,其中f(n)

但是你如何确定什么是
c
和什么是
g(n)

你可以使用任何肮脏的黑客手段,你想发现一个c和n0是有效的,然后证明它们(归纳法通常很有效,但有时并不必要)

这里,只需注意,对于n>=1,n^3>=n>=1,所以

f(n) = 3*n^3 + 4*n + 2
    <= 3*n^3 + 4*n^3 + 2*n^3
     = 9n^3
f(n)=3*n^3+4*n+2