The problem I have to solve is the 4D version of the 1D problem of stabbing queries: find which intervals a number belongs to. I am looking for a multi-dimensional implementation of segment trees. Ideally, it will be in Java and it will use fractional cascading.
Multi-dimensional implementations exist for kd-trees (k-NN searches) and range trees (given a bounding box, find all points in it) but for segment trees I've only found 1D implementations.
I'd be happy to consider other data structures with similar space/time complexity to address the same problem.
To expand on my comment, the binary-space-partitioning algorithm I have in mind is this.
- Choose a coordinate x and a threshold t (random coordinate, median coordinate, etc.).
- Allocate a new node and assign all of the intervals that intersect the half-plane x=t to it.
- Recursively construct child nodes for (a) the intervals contained entirely within the lower half-space x<t and (b) the intervals contained entirely within the upper half-space x>t.
The stabbing query starts at the root, checks all of the intervals assigned to the current node, descends to the appropriate child, and repeats. It may be worthwhile to switch to brute force for small subtrees.
If too many intervals are getting stabbed by the half-plane x=t, you could try recursing on the (a) the intervals that intersect the lower half-space and (b) the intervals that intersect the upper half-space. This duplicates intervals, so the space requirement is no longer linear, and you probably have to switch over to brute force on collections of intervals for which subdivision proves unproductive.
来源:https://stackoverflow.com/questions/15827012/multi-dimensional-segment-trees