Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created March 20, 2021 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/78b6270add330cd30955508dadb31c15 to your computer and use it in GitHub Desktop.
Save amankharwal/78b6270add330cd30955508dadb31c15 to your computer and use it in GitHub Desktop.
def search(list, n):
l = 0
u = len(list) - 1
while 1 <= u:
mid = (l + u) // 2
if list[mid] == n:
return True
else:
if list[mid] < n:
l = mid + 1
else:
u = mid - 1
return False
list = [1, 3, 4, 7, 8, 9, 10, 45, 50, 90, 100, 150, 600, 1000]
n = 90
if search(list, n):
print("Found")
else:
print("Not Found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment