# 순차검색 알고리즘
def seqsearch(S, x):
location = 0
# while 반복문 실행횟수 확인용
loop_count = 0
while location < len(S) and S[location] != x:
loop_count += 1
location += 1
if location < len(S):
return (location, loop_count)
else:
return (-1, loop_count)
seq = list(range(30))
val = 5
print(seqsearch(seq, val))
(5, 5)
seq = list(range(30))
val = 10
print(seqsearch(seq, val))
(10, 10)
seq = list(range(30))
val = 20
print(seqsearch(seq, val))
(20, 20)
seq = list(range(30))
val = 29
print(seqsearch(seq, val))
(29, 29)
seq = list(range(30))
val = 30
print(seqsearch(seq, val))
(-1, 30)
seq = list(range(30))
val = 100
print(seqsearch(seq, val))
(-1, 30)
while
반복문의 실행횟수가 선형적으로 달라짐.