【发布时间】:2020-09-23 20:05:43
【问题描述】:
如果我有一个 for 循环来搜索某些东西,并且它被一个 while 循环包围,那么它是否是 O(N^2) 尽管从未运行过两次 while 循环? 例如,在集合中搜索 6
int location;
while (found == false AND quit == false)
foreach data x in collection
if x == 6
location = 6
found = true // exit prematurely
end if
end for
quit = true // exit here after for loop
end while
这个算法的复杂度是多少?
【问题讨论】:
标签: loops big-o complexity-theory