- 1
How to do binary search in python?
I want a full complete program to understand my bug. I have tried multiple times but it has not worked. So can you show a full program for it?
7 Answers
+ 3
l = 0, r = last index
while l <= r:
mid = l + (r - l) / 2
if v[mid] < target
l = mid + 1
else if v[mid] > target
r = mid - 1
else return mid
return -1
+ 3
Before asking for a "complete full program", you should do a try by yourself. Please put it in the playground and link it here. Thanks!
+ 2
Hmm no there are several tutorials ,probably code also our there ,why don't you first understand how binary search works and then try to implement ,if still you are facing an errors link the code so someone can help you ,also do not ask for codes here :-)
+ 2
Asim Yadav, yes you did, but you have not presented any of your codes here. If we can see what you have done so far, it is much easier to to support you. How should we know about the bug you mentioned?
0
Lothar didn't I say in my description that "I have tried multiple times".
0
Thnx Bobby Fischer
0
Lothar ok I will attach the image of my code