简体   繁体   English

段树、区间树、二叉索引树和范围树有什么区别?

[英]What are the differences between segment trees, interval trees, binary indexed trees and range trees?

What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of:段树、区间树、二叉索引树和范围树在以下方面有什么区别:

  • Key idea/definition关键思想/定义
  • Applications应用
  • Performance/order in higher dimensions/space consumption更高维度的性能/顺序/空间消耗

Please do not just give definitions.请不要只给出定义。

All these data structures are used for solving different problems:所有这些数据结构都用于解决不同的问题:

  • Segment tree stores intervals, and optimized for " which of these intervals contains a given point " queries.段树存储区间,并针对“这些区间中的哪一个包含给定点”查询进行了优化。
  • Interval tree stores intervals as well, but optimized for " which of these intervals overlap with a given interval " queries.间隔树也存储间隔,但针对“这些间隔中的哪些与给定间隔重叠”查询进行了优化。 It can also be used for point queries - similar to segment tree.它也可以用于点查询——类似于线段树。
  • Range tree stores points, and optimized for " which points fall within a given interval " queries.范围树存储点,并针对“哪些点落在给定间隔内”查询进行了优化。
  • Binary indexed tree stores items-count per index, and optimized for " how many items are there between index m and n " queries.二叉索引树存储每个索引的项目数,并针对“索引 m 和 n 之间有多少项目”查询进行了优化。

Performance / Space consumption for one dimension:一维的性能/空间消耗:

  • Segment tree - O(n logn) preprocessing time, O(k+logn) query time, O(n logn) space段树- O(n logn) 预处理时间,O(k+logn) 查询时间,O(n logn) 空间
  • Interval tree - O(n logn) preprocessing time, O(k+logn) query time, O(n) space区间树- O(n logn) 预处理时间,O(k+logn) 查询时间,O(n) 空间
  • Range tree - O(n logn) preprocessing time, O(k+logn) query time, O(n) space范围树- O(n logn) 预处理时间,O(k+logn) 查询时间,O(n) 空间
  • Binary Indexed tree - O(n logn) preprocessing time, O(logn) query time, O(n) space二叉索引树- O(n logn) 预处理时间,O(logn) 查询时间,O(n) 空间

(k is the number of reported results). (k 是报告结果的数量)。

All data structures can be dynamic, in the sense that the usage scenario includes both data changes and queries:所有数据结构都可以是动态的,因为使用场景包括数据更改和查询:

  • Segment tree - interval can be added/deleted in O(logn) time (see here )段树- 可以在 O(logn) 时间内添加/删除间隔(请参阅此处
  • Interval tree - interval can be added/deleted in O(logn) time间隔树- 可以在 O(logn) 时间内添加/删除间隔
  • Range tree - new points can be added/deleted in O(logn) time (see here )范围树- 可以在 O(logn) 时间内添加/删除新点(请参阅此处
  • Binary Indexed tree - the items-count per index can be increased in O(logn) time二叉索引树- 每个索引的项目数可以在 O(logn) 时间内增加

Higher dimensions (d>1):更高维度(d>1):

  • Segment tree - O(n(logn)^d) preprocessing time, O(k+(logn)^d) query time, O(n(logn)^(d-1)) space段树- O(n(logn)^d) 预处理时间,O(k+(logn)^d) 查询时间,O(n(logn)^(d-1)) 空间
  • Interval tree - O(n logn) preprocessing time, O(k+(logn)^d) query time, O(n logn) space区间树- O(n logn) 预处理时间,O(k+(logn)^d) 查询时间,O(n logn) 空间
  • Range tree - O(n(logn)^d) preprocessing time, O(k+(logn)^d) query time, O(n(logn)^(d-1))) space范围树- O(n(logn)^d) 预处理时间,O(k+(logn)^d) 查询时间,O(n(logn)^(d-1))) 空间
  • Binary Indexed tree - O(n(logn)^d) preprocessing time, O((logn)^d) query time, O(n(logn)^d) space二叉索引树- O(n(logn)^d) 预处理时间,O((logn)^d) 查询时间,O(n(logn)^d) 空间

Not that I can add anything to Lior's answer , but it seems like it could do with a good table.并不是说我可以在Lior 的回答中添加任何内容,但似乎可以用一张好桌子来做。

One Dimension一维

k is the number of reported results k是报告结果的数量

Operation手术 Segment部分 Interval间隔 Range范围 Indexed索引
Preprocessing预处理 n logn登录 n logn登录 n logn登录 n logn登录
Query询问 k+logn k+logn k+logn k+logn k+logn k+logn logn登录
Space空间 n logn登录 n n n n n n
Insert/Delete插入/删除 logn登录 logn登录 logn登录 logn登录

Higher Dimensions更高维度

d > 1

Operation手术 Segment部分 Interval间隔 Range范围 Indexed索引
Preprocessing预处理 n(logn)^d n(logn)^d n logn登录 n(logn)^d n(logn)^d n(logn)^d n(logn)^d
Query询问 k+(logn)^d k+(logn)^d k+(logn)^d k+(logn)^d k+(logn)^d k+(logn)^d (logn)^d (登录)^d
Space空间 n(logn)^(d-1) n(logn)^(d-1) n logn登录 n(logn)^(d-1)) n(logn)^(d-1)) n(logn)^d n(logn)^d

The bounds for preprocessing and space for segment trees and binary indexed trees can be improved:可以改进段树和二叉索引树的预处理范围和空间:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM