1def binary_search(group, suspect):
2 group.sort()
3 midpoint = len(group)//2
4 while(True):
5 if(group[midpoint] == suspect):
6 return midpoint
7 if(suspect > group[midpoint]):
8 group = group[midpoint]
9 if(suspect < group[midpoint]):
10 group = group[0: midpoint]
11 midpoint = (len(group)//2)
1def binarySearchAppr (arr, start, end, x):
2# check condition
3if end >= start:
4 mid = start + (end- start)//2
5 # If element is present at the middle
6 if arr[mid] == x:
7 return mid
8 # If element is smaller than mid
9 elif arr[mid] > x:
10 return binarySearchAppr(arr, start, mid-1, x)
11 # Else the element greator than mid
12 else:
13 return binarySearchAppr(arr, mid+1, end, x)
14 else:
15 # Element is not found in the array
16 return -1
17arr = sorted(['t','u','t','o','r','i','a','l'])
18x ='r'
19result = binarySearchAppr(arr, 0, len(arr)-1, x)
20if result != -1:
21 print ("Element is present at index "+str(result))
22else:
23print ("Element is not present in array")