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.

78 questions
1
vote
1 answer

Find points in intervals with a extra condition

I have a file with coordinates (interval) and another one with locations (points). I want to find all points that overlap with the intervals Example Locations # Locations chr1 99 chr1 100 chr1 101 chr1 102 ... chr2 120 chr2 121 chr2 122 chr2 123 #…
1
vote
0 answers

Augment a Red Black tree

I'm trying to make an interval tree from some boilerplate red-black-tree code. To make an augmented red-black-tree that supports intervals (as described in Wikipedia) you need to augment it to store that max value of any range of any child. I…
Schneems
  • 14,918
  • 9
  • 57
  • 84
1
vote
2 answers

Finding Overlap among multiple intervals

Let's say I have a list of intervals (or ranges) (Eg. 10-15, 5-7, 9-12..). The problem is to find the subset of ranges that overlaps. Of course I can use Interval tree for this. The actual problem that I have is there are multiple ranges. Best…
amit
  • 10,612
  • 11
  • 61
  • 60
1
vote
3 answers

Given set of intervals sorted according to Start time. Count all the intervals which has Time "T" in them in O(logn)

Suppose the list of intervals may be [[1,3],[2,4],[6,12]] and the Query time T = 3. The number of intervals which have 3 in the above list are 2 (i.e) [[1,3],[2,4]]. Is it possible to do this in O(logn) time?
Ajantha
  • 33
  • 4
1
vote
1 answer

Why does an interval tree need to store maximum right end of subtree?

I'm studying the implementation of interval tree, and I'm wondering if I can use a red black tree without the maximum value being stored and using the following pseudo-code? i=input_interval x=tree.root while x!=None AND check_overlap(i,x)==False:…
kastle
  • 43
  • 4
1
vote
1 answer

Hashing methodology for collection of strings and integer ranges

I have a data, for example per the following: I need to match the content with the input provided for the Content & Range fields to return the matching rows. As you can see the Content field is a collection of strings & the Range field is a range…
Sanal
  • 55
  • 1
  • 7
1
vote
0 answers

Combining “positive” and “negative” intervals to minimise total length

I have two sets of intervals: one containing “positive” intervals between, say, 0 and 100; and the other containing “negative” intervals between -100 and 0. The intervals in each set are not necessarily unique (maybe “collection” is a better word in…
Confounded
  • 446
  • 6
  • 19
1
vote
1 answer

Interval Tree - function to main disfunctionality

I have a question on Interval Trees to solve and I know basicaly the algorithm, but I have a problem in my code when my functions returns a value to it's main. The very question I am having is finding the maximum value between certain indexes, and…
Mihnea Gafton
  • 61
  • 1
  • 8
1
vote
1 answer

Too slow queries in interval tree

I have a list of intervals and I need to return the ones that overlap with an interval passed in a query. What is special is that in a typical query around a third or even half of the intervals will overlap with the one given in the query. Also, the…
1
vote
2 answers

Can someone please explain the solution to "Almost sorted intervals" to me?

Here is the problem, and here is a solution. First part is simple enough. It's the second part that I don't get, no matter how hard I try. You basically have two sets of intervals and need to find all intersections where one interval is not…
thule
  • 4,034
  • 21
  • 31
1
vote
1 answer

Creating a voxel system and got stuck, finding myself in the need of information on how to implement it

So, I should probably explain how I want to implement it first. My idea is fairly simple, I want to create each chunk and determine the location of each vertex by utilizing a floating point grid local to each chunk, I then want to place the voxels…
user2717116
1
vote
2 answers

Finding the closest intervals in an interval tree that do not contain the query

I have implemented an Interval Tree in Java as outlined in the CLRS algorithm book (it uses red-black tree as the underlying structure). In the book (and as far as I've seen online), it discusses how to find the node whose interval contains the…
Aaron
  • 1,693
  • 4
  • 26
  • 40
1
vote
2 answers

Set::IntervalTree acting weirdly when I add nodes through a loop in perl

I am trying to use the Set::IntervalTree module and I think it is giving me the same node pointers if I insert the elements in a loop. If I insert them outside a loop sequentially one after the another the nodes are inserted fine and the find /…
ajkl
  • 1,016
  • 1
  • 7
  • 27
1
vote
3 answers

Algorithm to validate a list of intervals

Given a list of start / end datetime values I need to validate three things: for each interval, the start time is before the end time no overlap exists between list elements, each start / end span must represent a discrete interval in the overall…
Steve Wagner
  • 254
  • 1
  • 3
  • 12
1
vote
1 answer

Interval Tree traversal

Here is the function I wrote for traversing an interval tree. I notice it fails to visit some nodes though. Assuming the code is pretty clear, I want to know where it fails. public boolean searchTree(Node node,int x) { …
user1271793