Can you do addition/multiplication with Big O notations?

三世轮回 提交于 2019-12-18 04:26:10

问题


I'm currently taking an algorithm class, and we're covering Big O notations and such. Last time, we talked about how

O (n^2 + 3n + 5) = O(n^2)

And I was wondering, if the same rules apply to this:

O(n^2) + O(3n) + O(5) = O(n^2)

Also, do the following notations hold ?

O(n^2) + n

or

O(n^2) + Θ (3n+5)

The later n is outside of O, so I'm not sure what it should mean. And in the second notation, I'm adding O and Θ .


回答1:


At least for practical purposes, the Landau O(...) can be viewed as a function (hence the appeal of its notation). This function has properties for standard operations, for example:

O(f(x)) + O(g(x)) = O(f(x) + g(x))
O(f(x)) * O(g(x)) = O(f(x) * g(x))
O(k*f(x)) = O(f(x))

for well defined functions f(x) and g(x), and some constant k.

Thus, for your examples,

Yes: O(n^2) + O(3n) + O(5) = O(n^2)
and:
O(n^2) + n = O(n^2) + O(n) = O(n^2),
O(n^2) + Θ(3n+5) = O(n^2) + O(3n+5) = O(n^2)




回答2:


The notation:

O(n^2) + O(3n) + O(5) = O(n^2)

as well as, for example:

f(n,m) = n^2 + m^3 + O(n+m)

is abusing the equality symbol, as it violates the axiom of equality. To be more formally correct, you would need to define O(g(x)) as a set-valued function, the value of which is all functions that do not grow faster than g(x), and use set membership notation to indicate that a specific function is a member of the set.

Addition and multiplication is not defined for Landau's symbol (Big O).




回答3:


In complexity theory, the Landau symbols are used for sets of functions. Therefore O(*) does not represent a single function but an entire set. The + operator is not defined for sets, however, the following is commonly used when analyzing functions:

O(*) + g(n)

This usually represents a set of functions where g(n) is added to every function in O(*). The resulting set can be represented in big-O notation again.

O(*) + O(**)

This is similar. However, it behaves like a kind of cartesian product. Every function from O(**) is added to every function from O(*).

O(*) + Θ(*)

The same rules apply here. However, the result can usually not be expressed as Θ(**) because of the loosening by O(*). Expressing it as O(**) is still possible.




回答4:


Also the following notations hold

O(n^2) + n = O(n^2)

and

O(n^2) + Θ(3n+5) = O(n^2), Θ(n)

Hope it makes sense...



来源:https://stackoverflow.com/questions/30168800/can-you-do-addition-multiplication-with-big-o-notations

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