如果你有这样的算法,复杂度是多少:
int get(const std::vector<unsigned int>& v, int N)
{
int a = 0;
for(int i = 0; i < N; ++i)
for(int j = 0; j < v.size(); ++j)
for(int k = 0; k < v[j]; ++k)
a += k * v[j];
return a;
}
除了缺少实用性之外,如果一个因素变化如此之大,您还会考虑什么复杂性?我的意思是,当 V = v.size()
时,它肯定是 O(N * V * ?)
,但是接下来呢?
最佳答案
复杂度为
O(N * V * std::numeric_limits<unsigned int>::max()) = O(N * V)
因为std::numeric_limits<unsigned int>::max()
是一个常数。
关于c++ - 当范围变化时,复杂性是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32977015/