Reputation: 3598
I have intervals of the form (a1, b1), (a2, b2), ...., (an, bn)
.
I would like to support the following operations
Intervals tree is the straightforward solution if we want to find intervals which overlap with the point. What about the case when we want to find non intersecting intervals?
Upvotes: 2
Views: 115
Reputation: 2346
Have all nodes in two trees simultaneously. Tree A holds them by key ai
and tree B holds them by key bi
.
Insertion and deletion is obviously O(log n)
.
For requirement 3, print the nodes in B from the smallest to the biggest and stop when bi
is still smaller then the point. Same, but backwards, in A.
Example:
Given (1,10), (5,18), (13,20)
, and a point 12
.
The interval(s) in A where ai
is bigger than 12
is (13,20)
, and in B the interval(s) that are smaller are (1,10)
.
Upvotes: 3