我试图找到此代码的T(n):
def sequentialSearch(alist, item):
pos = 0
found = False
while pos < len(alist) and not found:
if alist[pos] == item:
found = True
else:
pos = pos+1
return found
我认为T(n)=(2 + sigma(n))和BigO = n,但我的问题(井2)是if if语句除了n之外还添加任何其他东西。另外,传递的变量是否会在这种情况下添加任何内容?我是否正确地想到了这一点?谢谢!