Questions tagged [interval-tree]

Interval-tree allows one to efficiently find all intervals that overlap with any given interval or point

In computer science, an interval tree is an ordered tree data structure to hold intervals.

It allows one to efficiently find all intervals that overlap with any given interval or point. It is often used for windowing queries, for instance, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene. A similar data structure is the segment tree.

Queries require O(log n + m) time, with n being the total number of intervals and m being the number of reported results. Construction requires O(n log n) time, and storage requires O(n) space.

74 questions
5
votes
2 answers

Interval tree querying

Given a set of N intervals: For each interval, which other interval has a maximal overlap? e.g. { [0,5], [2,9], [2,3], [4,9] } : [0,5]: [2,9] (Overlap of 4) [2,9]: [4,9] (Overlap of 6) [2,3]: [0,5] or [2,9] (Overlap of 2) [4,9]: [2,9] (Overlap of…
inc_shadow
  • 53
  • 5
4
votes
2 answers

Is there a way to get the number of intervals in a boost::icl::interval_map?

Is there an built-in way to get the number of intervals in a boost::icl::interval_map? I can't find it in the documentation. The method size() has a different purpose it seems.
Jan Deinhard
  • 17,925
  • 24
  • 75
  • 131
4
votes
2 answers

C implementation of an interval tree?

I could find a C++ one here, but no pure C one. Any pointers?
Dervin Thunk
  • 17,583
  • 26
  • 110
  • 202
4
votes
0 answers

Implementing interval tree in Prolog w/ rbtrees.pl

I'm looking at the augmented tree in the interval tree article, and looking at rbtrees.pl in the SWI-Prolog standard library. The article says: An extra annotation is then added to every node, recording the maximum upper value among all the…
Daniel Lyons
  • 21,545
  • 2
  • 48
  • 73
4
votes
4 answers

Intervals to non-overlapping subintervals

I'm trying to divide a list of intervals into non-overlapping subintervals. For example, if my input were [1,5],[4,9],[6,12],[11,17] I would want the output to be [1,4], [4,5], [5,6], [6,9], [9,11], [11,12], [12,17] I want the output to be a list…
4
votes
3 answers

Efficiently finding overlapping intervals from a list of intervals

This is related to finding overlapping intervals. I know how to do so given a list of intervals (interval trees). What I have is a list of list of intervals. For example, [2,6], [7,11] [1,3], [5,10], [11,13] [2,5], [6,8] The result for this…
akaHuman
  • 1,262
  • 12
  • 33
3
votes
5 answers

C# Interval tree class

I'm looking for an interval tree C# collection class. I need to be able to add intervals, idealy 2D, otherwise perhaps I could combine two standard 1D interval trees. I also need to be able to find out what intervals overlap a given interval. I…
alan2here
  • 2,865
  • 4
  • 32
  • 55
3
votes
3 answers

Merge two sorted lists of intervals

Given A and B, which are two interval lists. A has no overlap inside A and B has no overlap inside B. In A, the intervals are sorted by their starting points. In B, the intervals are sorted by their starting points. How do you merge the two interval…
3
votes
3 answers

Given two sorted lists of intervals, return the overlapping intervals between the two lists

You are given two lists of intervals, A and B. In A, the intervals are sorted by their starting points. None of the intervals within A overlap. Likewise, in B, the intervals are sorted by their starting points. None of the intervals within B…
3
votes
2 answers

Interval intersection in pandas

Update 5: This feature has been released as part of pandas 20.1 (on my birthday :] ) Update 4: PR has been merged! Update 3: The PR has moved here Update 2: It seems like this question may have contributed to re-opening the PR for IntervalIndex in…
Alex Lenail
  • 9,296
  • 9
  • 39
  • 72
3
votes
1 answer

"circular" interval tree algorithm

I'm wondering if anyone has implemented/knows of an (preferably javascript) interval-tree algorithm that will handle circular intervals. By circular, I mean intervals with a start > end. Note this also necessitates a cap to how large the intervals…
majorBummer
  • 6,357
  • 5
  • 29
  • 44
3
votes
1 answer

Algorithm - Group from the overlapping Intervals

I have set of overlapping intervals, i have to choose one element from the respective interval such that when they are grouped there are minimum gaps in the selection. By Grouping I mean consecutive elements are grouped. And if there are no…
user1447725
  • 1,273
  • 2
  • 9
  • 11
3
votes
1 answer

Augment java collection to get Interval Tree

I was going through the Introduction to Algorithms by Cormen chapter 14 (augmented data structures), in which he was talking about Interval Trees. Below is what he mentioned about the design approach behind interval tree. Step 1: Underlying data…
Trying
  • 12,882
  • 8
  • 63
  • 106
3
votes
1 answer

Efficient mapping of ranges to groups of values

I'm attempting to determine a suitable way to accomplish the following. I would like to have range -> set lookup within a particular range (say [0x0 - 0xffffffff]). Values are inserted into the range at ranges (so if we are working with T = unique…
3
votes
1 answer

IntervalTree in Guava

I am working with Guava's Range class for processing intervals. I wanted to know if it is possible to find the closest interval from a set of intervals to a given point/interval by using some of the Guava's collection containers ? I tried searching…
user1998031
  • 127
  • 2
  • 6