ArticleslgStudy

science

Interval tree

Interval tree is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Interval tree rather than just read about it. In short: In computer science, an interval tree is a tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point.

Interval tree — main illustration
Interval tree — illustration

Key takeaways

  • Interval tree belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Interval tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Interval tree from memory before moving on to harder problems.

Reference excerpt

In computer science, an interval tree is a tree data structure to hold intervals. Specifically, 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. The trivial solution to finding all overlapping intervals is to visit each interval and test whether it intersects the given point or interval, which requires O(n) time, where n is the number of intervals in the collection. Since a query may return all intervals, for example if the query is a large interval intersecting all intervals in the collection, this is asymptotically optimal; however, output-sensitive algorithms, where the runtime is expressed in terms of m (the number of intervals produced by the query) may also be considered. Interval trees have a query time of O(log⁡n+m) and an initial creation time of O(nlog⁡n), while limiting memory consumption to O(n). After creation, interval trees may be dynamic, allowing efficient insertion and deletion of an interval in O(log⁡n) time. If the endpoints of intervals are within a small integer range (e.g., in the range [1,…,O(n)]), faster and in fact optimal data structures exist with preprocessing time O(n) and query time O(1+m) for reporting m intervals containing a given query point (see for a very simple one).

Naïve approach In a simple case, the intervals do not overlap and they can be inserted into a simple binary search tree and queried in O(log⁡n) time. However, with arbitrarily overlapping intervals, there is no way to compare two intervals for insertion into the tree since orderings sorted by the beginning points or the ending points may be different. A naïve approach might be to build two parallel trees, one ordered by the beginning point, and one ordered by the ending point of each interval. This allows discarding half of each tree in O(log⁡n) time, but the results must be merged, requiring O(n) time. This returns queries in O(n+log⁡n)=O(n), which is no better than brute-force. Interval trees solve this problem. This article describes two alternative designs for an interval tree, dubbed the centered interval tree and the augmented tree.

Centered interval 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(nlog⁡n) time, and storage requires O(n) space.

Construction Given a set of n intervals on the number line, a data structure needs to be constructed so that all intervals overlapping another interval or point can be efficiently retrieved. First, the entire range of all the intervals is taken and divided in half at xcenter (in practice, xcenter should be picked to keep the tree relatively balanced). This gives three sets of intervals, those completely to the left of xcenter, called Sleft, those completely to the right of xcenter, called Sright, and those overlapping xcenter, called Scenter. The intervals in Sleft and Sright are recursively divided in the same manner until there are no intervals left. The intervals in Scenter that overlap the center point are stored in a separate data structure linked to the node in the interval tree. This data structure consists of two lists, one containing all the intervals sorted by their beginning points, and another containing all the intervals sorted by their ending points. The result is a binary tree with each node storing:

A center point A pointer to another node containing all intervals completely to the left of the center point A pointer to another node containing all intervals completely to the right of the center point All intervals overlapping the center point sorted by their beginning point All intervals overlapping the center point sorted by their ending point

Intersecting Interval trees allow for quickly computing all the ranges overlapping any input.

With a point The task is to find all intervals in the tree that overlap a given point x. The tree is walked with a similar recursive algorithm as would be used to traverse a traditional binary tree, but with extra logic to support searching the intervals overlapping the "center" point at each node. For each tree node, x is compared to xcenter, the midpoint used in node construction above. If x is less than xcenter, the leftmost set of intervals, Sleft, is considered. If x is greater than xcenter, the rightmost set of intervals, Sright, is considered.

As each node is processed as the tree is traversed from the root to a leaf, the ranges in its Scenter are processed. If x is less than xcenter, all intervals in Scenter must end after x, or they could not also overlap xcenter. Therefore, it is only necessary find those intervals in Scenter that begin before x. The lists of Scenter, which have already been constructed, can be consulted. Since only the interval beginnings are relevant in this scenario, the list can be sorted by beginnings. If the closest number no greater than x is found in this list, all ranges from the beginning of the list to that found point overlap x because they begin before x and end after x (because they overlap xcenter which is larger than x). Thus, the intervals in the list can be enumerated until the startpoint value exceeds x. Likewise, if x is greater than xcenter, all intervals in Scenter must begin before x, so the intervals that end after x can be found using the list sorted by interval endings. If x exactly matches xcenter, all intervals in Scenter can be added to the results without further processing and tree traversal can be stopped.

With an interval For a result interval r to intersect the query interval q one of the following must hold:

either the start or end point of r is in q; or r completely encloses q.

… excerpt ends here. Continue reading the full article.

Illustrations

Interval tree: Deleting a node with two children from a binary search tree using the in-order predecessor (rightmost node in the left subtree, labelled 6).
Deleting a node with two children from a binary search tree using the in-order predecessor (rightmost node in the left subtree, labelled 6).
Interval tree: An augmented tree with low value as the key and maximum high as the extra annotation.For example, when testing if the given interval [40 ,60) overlaps the intervals in the tree shown above, we see that it does not overlap the interval [20, 36) in the root, but since the root's low value (20) is less than the sought high value (60), we must search the right subtree. Looking ahead into the left subtree, we see that its maximum high of 41 exceeds the sought low value (40), so we must search the left subtree as well. Once we recurse into [3, 41) we can look ahead into the subtrees and see that both descendants of the [3, 41) node have maximum highs less than 40, so the left subtree search ends there and it is not necessary to recurse further.
An augmented tree with low value as the key and maximum high as the extra annotation.For example, when testing if the given interval [40 ,60) overlaps the intervals in the tree shown above, we see that it does not overlap the interval [20, 36) in the root, but since the root's low value (20) is less than the sought high value (60), we must search the right subtree. Looking ahead into the left subtree, we see that its maximum high of 41 exceeds the sought low value (40), so we must search the left subtree as well. Once we recurse into [3, 41) we can look ahead into the subtrees and see that both descendants of the [3, 41) node have maximum highs less than 40, so the left subtree search ends there and it is not necessary to recurse further.

Worked examples

Example 1 — a first encounter with Interval tree

Start with the simplest possible case. Write down what Interval tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Interval tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Interval tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Interval tree

In research
Interval tree appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Interval tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Interval tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics Search trees, so understanding it makes those chapters shorter.
In everyday life
Look for Interval tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Interval tree” →

How to study Interval tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Interval tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Interval tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Interval tree in simple terms?

In computer science, an interval tree is a tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point.

Why does Interval tree matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Interval tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Interval tree.

Tags

  • Search trees

Keep exploring