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
217
votes
3 answers

What are the differences between segment trees, interval trees, binary indexed trees and range trees?

What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of: Key idea/definition Applications Performance/order in higher dimensions/space consumption Please do not just give definitions.
Aditya
  • 5,101
  • 4
  • 27
  • 50
35
votes
5 answers

C++ - interval tree implementation

Does someone know any good interval tree implementation in C++? Obviously, something template-driven, better in boost-like style. And another question - if somebody tested, does a basic std::vector-based interval tree implementation with sorting can…
Yippie-Ki-Yay
  • 20,062
  • 23
  • 85
  • 143
21
votes
3 answers

Interval tree with added dimension of subset matching?

This is an algorithmic question about a somewhat complex problem. The foundation is this: A scheduling system based on available slots and reserved slots. Slots have certain criteria, let's call them tags. A reservation is matched to an available…
deceze
  • 471,072
  • 76
  • 664
  • 811
18
votes
1 answer

Maximum non-overlapping intervals in a interval tree

Given a list of intervals of time, I need to find the set of maximum non-overlapping intervals. For example, if we have the following intervals: [0600, 0830], [0800, 0900], [0900, 1100], [0900, 1130], [1030, 1400], [1230, 1400] Also it is given…
shobhu
  • 634
  • 2
  • 7
  • 16
17
votes
7 answers

Maximum sum of all subarrays of size k for each k=1..n

Given an array of size n, for each k from 1 to n, find the maximum sum of contiguous subarray of size k. This problem has an obvious solution with time complexity O(N2) and O(1) space. Lua code: array = {7, 1, 3, 1, 4, 5, 1, 3, 6} n =…
16
votes
1 answer

Interval tree algorithm that supports merging of intervals with no overlap

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…
Dave Griffiths
  • 1,733
  • 17
  • 19
15
votes
5 answers

R-Tree Implementation Java

I was searching the last few days for a stable implementation of the R-Tree with support of unlimited dimensions (20 or so would be enough). I only found this http://sourceforge.net/projects/jsi/ but they only support 2 dimensions. Another Option…
drame
  • 395
  • 1
  • 3
  • 14
10
votes
5 answers

Merge ranges in intervals

Given a set of intervals: {1-4, 6-7, 10-12} add a new interval: (9,11) so that the final solution is 'merged': Output: {1-4, 6-7, 9-12}. The merger can happen on both sides (low as well as high range). I saw this question was answered at multiple…
Darth.Vader
  • 3,249
  • 5
  • 38
  • 66
9
votes
4 answers

C# using others code

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download. However I can't open the whole project on my Microsoft Visual C# 2010 Express (that…
alan2here
  • 2,865
  • 4
  • 32
  • 55
9
votes
2 answers

Maximum interval overlaps using an interval tree

Here is an interesting question: Given a set of N intervals ([start, end]), use an interval tree to find the maximum number of overlapping intervals. A similar question on StackOverflow provided an O(N) solution, but if we can pre-process the…
stackoverflowuser2010
  • 29,060
  • 31
  • 142
  • 184
8
votes
3 answers

Finding C++ interval tree algorithm implementation

I'm trying to find an efficient C++ interval tree implementation (mostly likely based on red black trees) without a viral or restrictive license. Any pointers to a clean lightweight standalone implementation? For the use case I have in mind, the set…
Christophe Lambert
7
votes
4 answers

Sorted intervals query

I'm in search for a data structure which efficiently operates over closed intervals with the following properties: dynamically add or remove an interval set, and anytime change, a number ("depth") for each interval. no two depths are ever the…
Ecir Hana
  • 9,122
  • 13
  • 58
  • 105
7
votes
5 answers

IntervalTree DeleteNode Java Implementation

I need an IntervalTree or RangeTree implementation in Java, and am having trouble finding one with working deletion support. There's a built-in one at sun.jvm.hotspot.utilities.IntervalTree, but the deleteNode method in the RBTree superclass…
Sam Barnum
  • 9,932
  • 3
  • 48
  • 57
6
votes
6 answers

Round each number of list to most near number in another list

Suppose I have a certain list x with numbers, and another list y with other numbers. Elements of y should be elements of x, but due to noise in measurements, they are kind of different. I want to find, for each value of y, the value of x that is the…
Tendero
  • 963
  • 14
  • 26
6
votes
2 answers

Interval set in java

I have a list of intervals with integer values [eg. [1, 4], [10, 19] etc.]. Is there a way to put these intervals into some java collections' container [eg. Set] such that I can call a 'union' function on the container. The 'union' function should…
user1998031
  • 127
  • 2
  • 6
1
2 3 4 5