Multiplying (nesting) two big Os
If a function A calls n^c funct开发者_运维百科ions B that runs in O(n^2) time, what is the time complexity of function A? Is it just polynomial (n^c) as well as c has just gotten bigger?
If a function A calls another function B, the total complexity is the product of the complexities of A and B. So in this case the total complexity is O(nc · n2) = O(nc + 2).
The general rules for products:
ƒ1 ∈ O(g1) and ƒ2 ∈ O(g2) ⟹ ƒ1·ƒ2 ∈ O(g1·g1)
ƒ·O(g) ∈ O(ƒ·g)
精彩评论