I have written this code for binary search in python.
import math
import copy
def binarySearch(array, target):
c=-1
flag=False
org_array=copy.deepcopy(array)
# Write your code here.
l=array[0:math.floor(len(array)/2)]
r=array[math.floor(len(array)/2):len(array)]
for i in r:
if(i==target):
flag=True
c=org_array.index(i)
return c
if(flag==False):
array=l
binarySearch(array, target)
binarySearch([0,1,21,33,45,45,61,71,72,73,74], 21)
Though it is working fine and returning index for elements in 'r'(second half of list), but it is not returning anything for search element in first half of list-->(l).May i know, where i am going wrong.