Reputation: 17
Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T.Can someone explain how to calculate the absolute value of the time taken to compute the sum..?
Upvotes: 0
Views: 713
Reputation: 20520
I'll leave you to work out the full details, but here's a start. The algorithm will go:
L
. You can do that in log time.H
.I've assumed that "lie between" means "strictly between", but you might want weak inequalities in steps 1 and 3.
Upvotes: 2