简体   繁体   English

上限算法分析

[英]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 找出ck ,使cn^4 >= n^4 + 100 n ^2 + 50

If we discard, lower terms 100 n^2 and 50 . 如果我们舍弃,则降低项100 n^250 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 = tn^4 = t^2c=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 如果我开始把值t123456789 ,和10t^2 =100

At 10 , i still have 10 ,我还有

100,00 <= 100, 00 +50

At t=11 , and t^2 = 121 , i have below t=11t^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 . 找到ck使下面的内容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.

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