简体   繁体   中英

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. 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.

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

c g(n) >= f(n) for n>=k.

For some constant value of c and k, the above equation will hold true. We do not consider lower values of n. This means g(n) for low values of n is not important. For large values of n , g(n) will be the maximum rate of growth of f(n) .

Here, f(n)= n^4 + 100 n^2 + 50

When n is very large, g(n) = n^4

Find c and k , so that cn^4 >= n^4 + 100 n ^2 + 50

If we discard, lower terms 100 n^2 and 50 . we can say c should be 2 .

2 n^4 >= n^4 .

To find value of k , try substituting n^2 = t , n^4 = t^2 and 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

At 10 , i still have

100,00 <= 100, 00 +50

At t=11 , and t^2 = 121 , i have below

14,641 >= 12150.

So my k will be 11 .

Similarly for the other equation, f(n) = 3n +8

g(n) will be n . Find c and k so that below is 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 .

At k=8 , we have 32>=32 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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