Multi-dimensional segment trees

…衆ロ難τιáo~ 提交于 2019-12-04 20:18:17

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.

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