From ac8c54bf912c4f99ded9fb2d39065b51ade8ef49 Mon Sep 17 00:00:00 2001 From: Rouslan Gaisin Date: Mon, 13 May 2019 01:24:39 +0300 Subject: [PATCH] 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'. --- binary_search/Python3/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binary_search/Python3/main.py b/binary_search/Python3/main.py index 1891685..75b4726 100644 --- a/binary_search/Python3/main.py +++ b/binary_search/Python3/main.py @@ -5,8 +5,8 @@ def binary_search(a,value): mid=a[len(a)//2] if value==mid: return True if valuemid: 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)) \ No newline at end of file +print(binary_search(a,5))