Skip to content

Instantly share code, notes, and snippets.

@ianchanning
Last active September 8, 2019 07:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchanning/4bfed060439978377457 to your computer and use it in GitHub Desktop.
Save ianchanning/4bfed060439978377457 to your computer and use it in GitHub Desktop.
What are the differences between segment trees, interval trees, binary indexed trees and range trees?

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

Stack Overflow: http://stackoverflow.com/questions/17466218/what-are-the-differences-between-segment-trees-interval-trees-binary-indexed-t/34699478

One Dimension

k is the number of reported results

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
|              | 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 |

Higher Dimensions

d > 1

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
|              | 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 |
@kagan94
Copy link

kagan94 commented Oct 2, 2016

What do the reported results (k) mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment