data-structures - 一维空间索引的数据结构

标签 data-structures

我有大量对象,每个对象代表一个数字范围(例如 [1,3]、[2,8]、[3,3])。我希望能够快速查询与给定范围重叠的所有范围。这是标准 2D 或 3D 空间索引(例如 R 树)的一维等效项。

例如:

Data = [0,1], [1,3], [2,8], [3,3], [5,9]
Query = [2,4]
Output = [1,3], [2,8], [3,3]

我想向结构中添加项目或从中删除项目,通常运行时间为 O(log N),并且搜索结构通常也为 O(log N)。

是否有一个很好的适合易于理解的标准数据结构?

最佳答案

interval tree我想到的是:(来自维基百科的描述,图片来自here)

A tree with each node storing:

  • A center point
  • A pointer to another node containing all intervals completely to the left of the center point
  • A pointer to another node containing all intervals completely to the right of the center point
  • All intervals overlapping the center point sorted by their beginning point
  • All intervals overlapping the center point sorted by their ending point

它允许O(log n + m) 间隔相交查询,其中m 是相交间隔的数量。

您必须查看这两个网站以获取有关构建和查询的更多详细信息。

关于data-structures - 一维空间索引的数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23527175/

相关文章:

c++ - 优化或新算法来解决这个问题?

c - 一个 C 程序,用于添加两个长度不等的单向链表,所有节点中都包含单个数字

java - 插入排序——交换节点

algorithm - 适合用道岔表示铁路的数据结构是什么?

python - 从图中删除边

c - FIFO 队列头指针不正确

xml - 什么是 XML 的良好替代数据格式?

c - 链表头部动态分配——C

algorithm - 在 M 天内阅读一本有 N 章的书的最佳方式

算法 - 如何有效地确保每个数组中的元素是不同的?