We have the Java method rangeQuery_count(BSTNode,int,int)
. Given the root of a BST (keys int) and an interval [a,b], this method returns number of keys of the BST belong to the interval.
static int rangeQuery_count(BSTNode v, int a, int b) { //a<=b
if(v==null) return 0;
if(v.key < a) return rangeQuery_count(v.right, a, b);
else if(v.key > b) return rangeQuery_count(v.left, a, b);
else return 1 + rangeQuery_count(v.right, a, b) + rangeQuery_count(v.left, a, b);
}
I have to determine an asymptotic estimate of the cost of the algorithm in function of the number of nodes n of the BST. I'm just starting to study these topics and I would like to understand how to calculate the cost of a program.