【发布时间】:2014-01-14 21:13:49
【问题描述】:
如果我们有这样的问题,我们该如何解决:
以下方法的最坏情况时间复杂度是多少 (其中 n 是 array.length):
boolean search(int[] array, int value) {
for (int j = 0; j < array.length; i++)
if (array[j] == value)
return true;
return false;
}
- O(1)
- O(log2 n)
- O(n)
- O(n^2)
- O(n+值)
【问题讨论】:
-
与
i++其复杂性是无限的:D 但与j++它将是O(n)
标签: algorithm data-structures big-o time-complexity