Algorithm complexity when faced with substraction in value

和自甴很熟 提交于 2019-12-23 20:15:55

问题


I have the following formula that I have to simplify in order to get the time complexity of my algorithm : (n^2-n)/3. Are there any rules that apply that can allow me to simplify this expression even further to a more "common" Θ(n^2) or something like that (I'm assuming that's what the result will be, might be wrong).

I simply don't know how to deal with the substraction here. Usually, if two values add each other, you only consider the one that is the highest to analyse the complexity of the algorithm. What do I do in this case ?


回答1:


Since Θ is a tight bound, there is no better simplification for it, if some function f(n) is both in Θ(h(n)) AND in Θ(g(n)) it means that Θ(h(n)) = Θ(g(n)), so for any other function you will find, the information gain over Θ(n^2) in your example is none.

When dealing with substraction of n^k - n^m, where k>m, you can simply "throw" n^m away, when analyzing big Θ notation.

This is true because:

n^k - n^m <= n^k  
-> and thus it is in O(n^k)

On the other hand:
For every m,k there is some value N such that for all n>N: 0.5n^k >= n^m, and thus:

n^k - n^m >= n^k - 0.5n^k = 0.5n^k    for n > N
-> it is also in Omega(n^k)

Since we found both upper and lower bound, we can conclude n^k-n^m, when k>m, is in Θ(n^k).
(Similar proof can be done for general f(n),g(n) which are in different Θ-complexity classes).



来源:https://stackoverflow.com/questions/29706119/algorithm-complexity-when-faced-with-substraction-in-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!