Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def binary_search(searched_value, ordered_list):
- top_value = len(ordered_list)-1
- bottom_value = 0
- guess = (bottom_value+top_value)//2
- while top_value != bottom_value:
- if (searched_value < ordered_list[guess]):
- top_value = guess
- elif (searched_value > ordered_list[guess]):
- bottom_value = guess
- else:
- return True
- guess = (top_value + bottom_value) // 2
- return False
Advertisement
Add Comment
Please, Sign In to add comment