Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harishvc committed Apr 27, 2016
1 parent 8ab3c32 commit 5e13723
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions binary-search-tree-search-sorted-rotated-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ def BST(t2,target,start,end):
return False
elif (t2[mid] == target):
return True
#sorted
#check if sorted: value at start < value at middle
elif( t2[start] <= t2[mid]):
if (target >= t2[start] and target <= t2[mid]):
return BST(t2,target,start,mid-1)
else:
return BST(t2,target,mid+1,end)
#unsorted
#unsorted: target on the right
elif (target >= target[mid] and target <= target[end]):
return BST(t2,target,mid+1,end)
#unsorted: target on the left, target > start and target > middle
else:
return BST(t2,target,start,mid-1)

Expand All @@ -39,4 +40,5 @@ def BST(t2,target,start,end):
target = [4,50]
for x in target:
result = BST(t2,x,0,len(t2)-1)
print("target=",x, " Found=", result)
print("target=",x, " Found=", result)

0 comments on commit 5e13723

Please sign in to comment.