开发者

Multiplying (nesting) two big Os

开发者 https://www.devze.com 2023-01-19 23:21 出处:网络
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

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消