Geometric Applications of BST
Last updated
// Running time is proportional to log(n)
public int size(key low, key high) {
if(contains(high)){
return rank(high) - rank(low) + 1;
} else {
return rank(high) - rank(low);
}
}..............
TreeNode x = root;
while(x!=null){
if(x.interval.insersects(lo,hi)){
return x.interval;
}else if(x.left == null) {
x = x.right;
}else if(x.left.max < lo){
x = x.right;
}else {
x = x.left;
}
}
return null;
..............