[英]algorithm analysis for upper bound
>Problem: n^4 + 100n^2 + 50.
>Solution given: n^4 + 100n^2 + 50 <= 2n^4 for all n>=1
> n^4 + 100n^2 + 50 = O(n^4) with c=2 and n0 = 100
But when n is 1, the above function will be "4+100+50 <= 2" which is not true. 但是,当n为1时,上述函数将为“ 4 + 100 + 50 <= 2”,这是不正确的。 How can i derive the correct upper bound for this problem or let me know if the given solution is wrong.
我如何得出此问题的正确上限,或者让我知道给定的解决方案是否错误。
The problem is from Data structures and algorithms made easy in java. 问题出在Java中简化的数据结构和算法。
A correct way to state the solution would be 陈述解决方案的正确方法是
n^4 + 100n^2 + 50 <= c*n^4 for all n>=n0 with c=2 and n0 = 100
=> n^4 + 100n^2 + 50 = O(n^4)
We need to find, smallest rate of growth, g(n)
such that 我们需要找到最小的增长率
g(n)
使得
c g(n) >= f(n) for n>=k.
For some constant value of c and k, the above equation will hold true. 对于c和k的某个恒定值,上述等式成立。 We do not consider lower values of n.
我们不考虑n的较低值。 This means
g(n)
for low values of n
is not important. 这意味着低
n
值的g(n)
不重要。 For large values of n
, g(n)
will be the maximum rate of growth of f(n)
. 对于较大的
n
值, g(n)
将是f(n)
的最大增长率。
Here, f(n)= n^4 + 100 n^2 + 50
在这里,
f(n)= n^4 + 100 n^2 + 50
When n
is very large, g(n) = n^4
当
n
非常大时, g(n) = n^4
Find c
and k
, so that cn^4 >= n^4 + 100 n ^2 + 50
找出
c
和k
,使cn^4 >= n^4 + 100 n ^2 + 50
If we discard, lower terms 100 n^2
and 50
. 如果我们舍弃,则降低项
100 n^2
和50
。 we can say c
should be 2
. 我们可以说
c
应该是2
。
2 n^4 >= n^4 .
To find value of k
, try substituting n^2 = t
, n^4 = t^2
and c=2
, 要找到
k
值,请尝试替换n^2 = t
, n^4 = t^2
和c=2
,
2t^2 >= t^2 + 100t + 50
t^2 >= 100t +50
If i start putting values of t
from 1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
, and 10
and t^2 =100
如果我开始把值
t
从1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
,和10
和t^2 =100
At 10
, i still have 在
10
,我还有
100,00 <= 100, 00 +50
At t=11
, and t^2 = 121
, i have below 在
t=11
且t^2 = 121
下
14,641 >= 12150.
So my k
will be 11
. 所以我的
k
将是11
。
Similarly for the other equation, f(n) = 3n +8
对于其他方程式类似,
f(n) = 3n +8
g(n)
will be n
. g(n)
将为n
。 Find c
and k
so that below is true
. 找到
c
和k
使下面的内容true
。
c.g(n) >= f(n)
4n>=3n+
8, discard constant 8
to find c
, and insert constant 8
back in equation to find k
. 4n>=3n+
8,舍弃常数8
以找到c
,并将常数8
插入等式中以找到k
。
At k=8
, we have 32>=32
. 在
k=8
,我们有32>=32
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.