Skip to content

Commit

Permalink
Add 🎶
Browse files Browse the repository at this point in the history
  • Loading branch information
harishvc committed Sep 4, 2016
1 parent 27d2a12 commit 67b476b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bst-check-if-value-exists.py
@@ -1,3 +1,4 @@

#Given a sorted list find if a value exists

'''
Expand All @@ -10,6 +11,10 @@
#Time complexity: O(logn)
def findTarget(a,start,end,target):
while start <= end:
#mid = start + (end-start)//2 since
#end-start//2 gives the mid VALUE
#adding start to the mid VALUE gives the index from start!
#example: if start=3 and end=4, mid = 3 + (4-3)//2 ~ 3rd index starting from 0
mid = start + (end-start)//2
if a[mid] == target:
return True
Expand Down

0 comments on commit 67b476b

Please sign in to comment.