해당 값을 찾을때까지 검색 반경을 반씩 잘라서 검색 범위를 줄여 검색하는 알고리즘
오름차순으로 정렬되어 있어야한다.
num_list = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]
def binary_search(arr, target):
start = 0
end = len(arr) -1
while(start <= end):
pointer = (start + end) //2
if pointer = target:
return pointer
elif target < pointer:
end = pointer
elif target > pointer:
start = pointer
return 'there is no such target in list'
result = binary_search(num_list, 9)