Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Border value not included
If you're adding one to len(array)//2 then the program loosing border values of splitted half.
In your example the algorithm wouldn't find '4'.
  • Loading branch information
gaisin authored May 12, 2019
commit ac8c54bf912c4f99ded9fb2d39065b51ade8ef49
4 changes: 2 additions & 2 deletions binary_search/Python3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def binary_search(a,value):
mid=a[len(a)//2]
if value==mid: return True
if value<mid: return binary_search(a[:len(a)//2],value)
if value>mid: return binary_search(a[len(a)//2+1:],value)
if value>mid: return binary_search(a[len(a)//2:],value)


a=[1,2,3,4,5,6,7,8,9]
print(binary_search(a,5))
print(binary_search(a,5))