Given a binary search tree (bst) of integer values and a range [low, high], return count of nodes where all the nodes under that node (or subtree rooted with that node) lie in the given range.
Answers
Answered by
0
Answer:Answer:this is a program in python(since we learn python)
def bin_search(a,s):
q='Element is not found in the given list'
l=len(a)-1
f=0
while f != l:
m=(f+l)//2
if a[m]>s:
f=m
elif a[m]<s:
l=m
else:
q= str('Element is found at',m+1,'position')
return q
a=[<the list>]
a.sort
s=int(input('Enter elemnt to be searched'))
print(bin_search(a,s))
#note:
# The given list should be of numbers(not strings)
Explanation:
the worst case is n/2 since the no of comparinions is half that of the no of items in list
Similar questions
History,
6 months ago
Computer Science,
11 months ago
Chemistry,
11 months ago
Math,
1 year ago
Math,
1 year ago