[Algorithm] 선형 탐색
ALGORITHM
- 알고리즘 정리(1)
선형 배열
def linear_search(element, some_list):
for i in range(len(some_list)):
if element == some_list[i]:
return i
return None
print(linear_search(2, [2, 3, 5, 7, 11]))
print(linear_search(0, [2, 3, 5, 7, 11]))
print(linear_search(5, [2, 3, 5, 7, 11]))
print(linear_search(3, [2, 3, 5, 7, 11]))
print(linear_search(11, [2, 3, 5, 7, 11]))
# 시간 복잡도 : O(n)
0
None
2
1
4