【发布时间】:2015-05-21 03:25:24
【问题描述】:
Is the execution time of this unique string function reduced from the naive O(n^2) approach?
这个问题有很多有趣的讨论让我想知道如果我们对算法设置一些阈值,它会改变 Big-O 运行时间复杂度吗?例如:
void someAlgorithm(n) {
if (n < SOME_THRESHOLD) {
// do O(n^2) algorithm
}
}
是 O(n2) 还是 O(1)。
【问题讨论】:
-
您的代码 sn-p 是否存在
else条件?如果您不执行任何高于硬编码的有限值的操作,则运行时间将由一个常数限制。
标签: algorithm