If a function A calls n^c functions 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?
+5
A:
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)
Gumbo
2010-10-13 06:32:14
i knew I should have added as an answer!
Mitch Wheat
2010-10-13 06:32:56
And that would be O(n^c) but just with a slightly larger `c` :-)
paxdiablo
2010-10-13 06:53:40