Homework
I need to use a data structure + algorithm that returns the number of elements within a range consisting of 2 (x,y) values (i.e. return the number of elements that fall within a rectangular range on an xy plane) in O(logn*logn).
I am considering two possiblities, kd-tree and a range tree. A kd-tree is well suited for this because it can find elements within the range in O(logn + k) (for k elements it needs to report). But I don't need to report the elements, I simply need to compute the number of elements that are within the range.
A range tree could work in that, I could have a property in each node that holds how many are less than itself. This way, I can determine how many elements are less than a particular value in O(logn) times (by going to the two boundaries and finding the difference in the number of nodes that are less than each other). However, I don't think this will work for data sets that have both an (x,y) dimension.
Am I on the right track?