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
0
votes
0 answers

Grid Layout Algorithm For Positioning Rectangle Into Available Space

I'm trying to implement a very crude form of the css grid layout. It's layout algorithm is as documented. “sparse” packing (default behavior) Set the column-start line of its placement to the earliest (smallest positive index) line index that…
Sentient
  • 781
  • 2
  • 10
  • 23
0
votes
0 answers

A data structure to find a predecessor in a given range

Given a list of keys, says [2, 6, 4, 9, 3], how can I find the predecessor of an element, with index left to the element only? For example The predecessor of 6 should be 2, not 4, because 4 is on the right of 6. The predecessor of 4 should be 2,…
0
votes
2 answers

Why wouldn't boost::icl::interval_map add up the value?

Consider the following program: #include #include struct Value { explicit Value(int v) : v(v), is_empty(false) {} Value() : v(0), is_empty(true) {} Value& operator+=(const Value& other) { …
Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79
0
votes
1 answer

Find the first index x that the value a[x]>u in range [l,r]

Given an array a[] has n non-negative elements. We have 2 types of queries: A x y v: Find the first index i (x<=i<=y) that a[i]>v B u v: Update a[u]=v; I use segment tree but it's TLE in some test. This is my code. it max(it A,it B) { it C; …
aka61bt
  • 57
  • 4
0
votes
1 answer

Calculate the maximum number of overlapping intervals

Calculate the maximum number of overlapping intervals with some conditions about operations: Insert an interval: O(logN) Remove an interval: O(logN) Calculate(the maximum number of overlapping intervals): O(1) I think this problem can be solved…
0
votes
0 answers

Is there an efficient algorithm for the following interval problem?

I have a list of sorted intervals and another list, which describes the index of every interval. Here's an example: intervals = [(0, 2), (2, 3), (4, 6)] // (0, 2) includes 0, but doesn't include 2 values = [2, 3, 7] Now, I want to know, how often…
0
votes
0 answers

Julia IntervalTrees.jl Create IntervalMap that maps to Array

I wanna create something like this, just as explained on here. using IntervalTrees # Create an interval tree mapping (Int, Int) intervals to Strings. xs = IntervalMap{Int, ASCIIString}() # Insert values xs[(1,100)] = "Low" xs[(101,1000)] =…
riasc
  • 281
  • 2
  • 3
  • 15
0
votes
1 answer

Interval Tree: Uncaught TypeError: Cannot read property 'mid' of null

I am trying to visualize the count of datasets that falls into particular range(Start Date and End Date). Following example from this I was able to do that. My code is here. The visualization at the bottom allow the user to filter the year range.…
user3050590
  • 1,656
  • 4
  • 21
  • 40
0
votes
0 answers

Using Interval tree to find overlapping regions

I have two files File 1 chr1:4847593-4847993 TGCCGGAGGGGTTTCGATGGAACTCGTAGCA File 2 Pbsn|X|75083240|75098962| TTTACTACTTAGTAACACAGTAAGCTAAACAACCAGTGCCATGGTAGGCTTGAGTCAGCT CTTTCAGGTTCATGTCCATCAAAGATCTACATCTCTCCCCTGGTAGCTTAAGAGAAGCCA …
sbradbio
  • 169
  • 1
  • 13
0
votes
2 answers

Lazy propagation for Segmented Tree

There is something unclear to me in the lazy propagation algorithm for segmented trees. According to the code below, upon completely overlap of the query interval, the update value is just added to the parent node and the children are marked for…
mkmostafa
  • 3,071
  • 2
  • 18
  • 47
0
votes
1 answer

Extend a class without changing a base algorithm implementation?

I'm writing an interval tree in C#. What I'd like to do is just extend an existing binary search tree to store intervals and not have to rewrite the core functionality (add, get, delete). Inside the BST, I have a Node class: protected class Node…
rookie
  • 2,783
  • 5
  • 29
  • 43
0
votes
1 answer

HackerEarth Challenge-- Deepu and Array

[ The Challenge is Over ] Problem: An Array of positive elements. Deepu Wants to reduce the elements of the array. He calls a function Hit(X) which reduces the all the elements in the array which are greater than X by 1. he will call this array many…
Ritesh
  • 497
  • 4
  • 15
0
votes
2 answers

PANDAS: fast check whether integers fall into a set of intervals

I have a pandas dataframe INT with two integer columns, START and END, representing intervals [START, END]. I need to check if an integer POS falls in one of these intervals, that is, if there exists a row where START <= POS <= END. I need to do…
Giovo
  • 43
  • 5
0
votes
1 answer

Range query in Solr

I have millions of documents with the following fields: name (string), start version (int), end version (int). I need to query efficiently all records which answers the query: Select all documents where version >= "start version" and version<="end…
Avner Levy
  • 6,601
  • 9
  • 53
  • 92
0
votes
1 answer

Simple code in python causing unexpected behaviour

I am trying to implement a segment tree class in python. Segment trees allow queries on ranges in logarithmic time (more about segment trees). In my implementation I hold the necessary information to be able to answer the sum of the elements in a…