Interval tree algorithm that supports merging of intervals with no overlap

Posted by Dave Griffiths on Stack Overflow See other posts from Stack Overflow or by Dave Griffiths
Published on 2010-04-07T15:33:29Z Indexed on 2010/04/09 11:33 UTC
Read the original article Hit count: 614

I'm looking for an interval tree algorithm similar to the red-black interval tree in CLR but that supports merging of intervals by default so that there are never any overlapping intervals.

In other words if you had a tree containing two intervals [2,3] and [5,6] and you added the interval [4,4], the result would be a tree containing just one interval [2,6].

Thanks

Update: the use case I'm considering is calculating transitive closure. Interval sets are used to store the successor sets because they have been found to be quite compact. But if you represent interval sets just as a linked list I have found that in some situations they can become quite large and hence so does the time required to find the insertion point. Hence my interest in interval trees. Also there may be quite a lot of merging one tree with another (i.e. a set OR operation) - if both trees are large then it may be better to create a new tree using inorder walks of both trees rather than repeated insertions of each interval.

© Stack Overflow or respective owner

Related posts about interval

Related posts about interval-tree