這裏是我的僞代碼:線性搜索跳轉米的地方
LinearSearch(List, key, m):
while (m < List.length):
if (m==key): // key is found
return m
else if (m < key): // key is larger than index
m = m + m
else: // key is smaller than index
m = m - 1
return NIL
但我不認爲這是正確的,因爲它似乎不是正確的,如果關鍵是List.length之間 - m和List.length。
請問誰能告訴我有什麼問題?
我也想該算法的時間複雜度,在三種情況:
worstcase when successful search
worst case when unsuccessful search
average case
謝謝
您認爲複雜性是什麼?你最好的猜測是什麼,爲什麼? – Maynza