Is the execution time of this unique string function reduced from the naive O(n^2) approach?是O(n^2)还是O(1)?
这个问题有很多有趣的讨论,使我怀疑,如果我们把一些门槛上的算法,它会改变大O的运行时间复杂性?例如:
void someAlgorithm(n) {
if (n < SOME_THRESHOLD) {
// do O(n^2) algorithm
}
}
它会为O(n 2 )或会是O(1)。
您的代码段中是否存在'else'条件?如果你没有执行超过硬编码有限值的任何内容,那么运行时间将受常数限制。 –