Multi-dimensional segment trees

笑着哭i 提交于 2019-12-06 14:02:33

问题


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.


回答1:


To expand on my comment, the binary-space-partitioning algorithm I have in mind is this.

  1. Choose a coordinate x and a threshold t (random coordinate, median coordinate, etc.).
  2. Allocate a new node and assign all of the intervals that intersect the half-plane x=t to it.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!