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.
What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of:
Please do not just give definitions.
All these data structures are used for solving different problems:
Performance / Space consumption for one dimension:
(k is the number of reported results).
All data structures can be dynamic, in the sense that the usage scenario includes both data changes and queries:
Higher dimensions (d>1):
Not that I can add anything to Lior's answer, but it seems like it could do with a good table.
k is the number of reported results
| Operation | Segment | Interval | Range | Indexed |
|---|---|---|---|---|
| Preprocessing | n logn | n logn | n logn | n logn |
| Query | k+logn | k+logn | k+logn | logn |
| Space | n logn | n | n | n |
| Insert/Delete | logn | logn | logn | logn |
d > 1
| Operation | Segment | Interval | Range | Indexed |
|---|---|---|---|---|
| Preprocessing | n(logn)^d | n logn | n(logn)^d | n(logn)^d |
| Query | k+(logn)^d | k+(logn)^d | k+(logn)^d | (logn)^d |
| Space | n(logn)^(d-1) | n logn | n(logn)^(d-1)) | n(logn)^d |
The bounds for preprocessing and space for segment trees and binary indexed trees can be improved:
2n space and subsequently built in 2n = O(n) using dynamic programming, if you forgo adding intervals at any arbitrary point: https://cp-algorithms.com/data_structures/segment_tree.html#toc-tgt-6n, see this answer: Is it possible to build a Fenwick tree in O(n)?O(log(n)) time