Skip to content

Instantly share code, notes, and snippets.

@sreevidyavutukuru
Created July 10, 2017 23:22
Show Gist options
  • Save sreevidyavutukuru/caed16bd47eb3e35ff2a9e94011f764f to your computer and use it in GitHub Desktop.
Save sreevidyavutukuru/caed16bd47eb3e35ff2a9e94011f764f to your computer and use it in GitHub Desktop.
import math
def index(list1, n):
startIndex = 0
endIndex = len(list1) - 1
while startIndex <= endIndex:
mid = startIndex + int(math.floor((endIndex-startIndex)/2))
if list1[mid] == n:
print n
print mid
break
elif n > list1[mid]:
startIndex = mid + 1
else:
endIndex = mid
index([1,3,4,5,6,8,9,10,11,12],10)
@sreevidyavutukuru
Copy link
Author

mid = (endIndex+startIndex)/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment