问题
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