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

前端 未结 2 1440
情书的邮戳
情书的邮戳 2020-11-28 17:23

What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of:

  • Key idea/definition
  • Applications
2条回答
  •  天涯浪人
    2020-11-28 17:27

    Not that I can add anything to Lior's answer, but it seems like it could do with a good table.

    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 |
    

    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 |
    

    These tables are created in Github Formatted Markdown - see this Gist if you want the tables formatted nicely.

提交回复
热议问题