Can you do addition/multiplication with Big O notations?

前端 未结 4 737
执念已碎
执念已碎 2021-01-03 04: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)
相关标签:
4条回答
  • 2021-01-03 04:57

    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.

    0 讨论(0)
  • 2021-01-03 05:00

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

    0 讨论(0)
  • 2021-01-03 05:02

    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)

    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题