Re: dynamic structure for storing/querying intervals
- From: Mark P <usenet@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 19 Apr 2006 22:47:40 GMT
Googmeister wrote:
Mark P wrote:I'm looking for advice on an efficient data structure that can store
intervals on a line (or, in possibly degenerate cases, just points).
I'd like to be able to query the structure by providing a range (again,
possibly degenerating to a point) and retrieve all intervals which
overlap the query range. Additionally, and this is where some of the
conventional structures I've found fall short, I'd like the structure to
support dynamic insertions and deletions. That is, inserts and deletes
may be mixed in with the queries.
Currently I'm using a structure of my own invention which is a balanced
search tree of all interval endpoints, which additionally keeps track of
which intervals start at or contain each such point, updating this data
as intervals are added or removed. The drawback to this approach is
that when many intervals overlap the performance degrades significantly.
I think you want an interval search tree. It's a balanced BST of
intervals,
sorted by left endpoint. Each node also contains the maximum endpoint
in its subtree. This suffices to do insert, overlap, and delete
efficiently.
http://en.wikipedia.org/wiki/Interval_tree
Ah, thanks. Funny, I had looked at the Interval Tree in CLR some time ago and had somehow been left with the impression that it didn't support dynamic operations. But you are indeed correct that it does all of the things I've asked for.
Thanks,
Mark
.
- References:
- dynamic structure for storing/querying intervals
- From: Mark P
- Re: dynamic structure for storing/querying intervals
- From: Googmeister
- dynamic structure for storing/querying intervals
- Prev by Date: Re: Tips for improving skills at interpreting other people's code?
- Next by Date: Re: Karnaugh map rules?
- Previous by thread: Re: dynamic structure for storing/querying intervals
- Next by thread: Karnaugh map rules?
- Index(es):
Relevant Pages
|
Loading