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 is to visit each interval and test whether it intersects the given point or interval, which requires O ( n ) {\displaystyle O(n)} time, where n {\displaystyle 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 {\displaystyle m} (the number of intervals produced by the query) may also be considered. Interval trees have a query time of O ( log ⁡ n + m ) {\displaystyle O(\log n+m)} and an initial creation time of O ( n log ⁡ n ) {\displaystyle O(n\log n)} , while limiting memory consumption to O ( n ) {\displaystyle O(n)} . After creation, interval trees may be dynamic, allowing efficient insertion and deletion of an interval in O ( log ⁡ n ) {\displaystyle O(\log n)} time. If the endpoints of intervals are within a small integer range (e.g., in the range [ 1 , … , O ( n ) ] {\displaystyle [1,\ldots ,O(n)]} ), faster and in fact optimal data structures exist with preprocessing time O ( n ) {\displaystyle O(n)} and query time O ( 1 + m ) {\displaystyle O(1+m)} for reporting m {\displaystyle 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 ) {\displaystyle 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 ) {\displaystyle O(\log n)} time, but the results must be merged, requiring O ( n ) {\displaystyle O(n)} time. This returns queries in O ( n + log ⁡ n ) = O ( n ) {\displaystyle 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 ) {\displaystyle O(\log n+m)} time, with n {\displaystyle n} being the total number of intervals and m {\displaystyle m} being the number of reported results. Construction requires O ( n log ⁡ n ) {\displaystyle O(n\log n)} time, and storage requires O ( n ) {\displaystyle O(n)} space.

… 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.  The left subtree's maximum high of 41 exceeds the sought low value (40), so we must search the left subtree as well.  However, 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 search them.
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. The left subtree's maximum high of 41 exceeds the sought low value (40), so we must search the left subtree as well. However, 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 search them.

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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

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