1

I have seen some SegmentTree implementation uses [l, r) to represent an interval, while some others use [l, r].

So my question: why we would want to use [left, right)? Seems it adds some complexity in the code to understand if there are no obvious advantages?

Thanks for answers in advance!

Huang C.
  • 398
  • 6
  • 17
  • A larger interval can be partitioned into finitely many intervals of the for `[a,b)` but can't be partitioned into finitely many intervals of the form `[a,b]`. Whether this is worth the added complexity is a judgment call. – John Coleman Aug 08 '16 at 12:13
  • @JohnColeman could you elaborate on why [a, b] can't be partitioned into finitely many intervals? Shouldn't the smallest interval just be [a, a]? – Huang C. Aug 08 '16 at 12:16
  • Endpoints force overlapping. [0,1) can be partitioned into [0,0.5) and [0.5, 1) but [0,1] can't be partitioned into [0, 0.5] and [0.5, 1]. Note that intervals of the form [a,b) are typically used for bins for histograms, essentially for this reason – John Coleman Aug 08 '16 at 12:52
  • Oh! That is a good point! Thank you very much! – Huang C. Aug 09 '16 at 06:36

0 Answers0