구현 13분def binary_search(element, some_list, start_index=0, end_index=None):
if end_index == None:
end_index = len(some_list) - 1
middle_index = (start_index + end_index) // 2
if some_list[middle_index] == element:
return middle_index
elif end_index < start_index: 📌
return None
elif element < some_list[middle_index]:
end_index = middle_index -1
return binary_search(element, some_list, start_index, end_index)
elif some_list[middle_index] < element:
start_index = middle_index +1
return binary_search(element, some_list, start_index, end_index)
print(binary_search(2, [2, 3, 5, 7, 11]))
print(binary_search(0, [2, 3, 5, 7, 11]))
print(binary_search(5, [2, 3, 5, 7, 11]))
print(binary_search(3, [2, 3, 5, 7, 11]))
print(binary_search(11, [2, 3, 5, 7, 11]))