repl.it
@manoj2rox/

Binary search

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def Binary_search(arr,x):
  first = 0
  last = len(arr)-1
  found = False
  while(first<=last and not found):
    mid = (first+last)//2
    if(arr[mid]==x):
      return(mid)
    else:
      if(arr[mid]<x):
        first = mid + 1
      else:
        mid = mid - 1
  return(found)
?