[go: nahoru, domu]

Jump to content

Interval tree: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Breuwi (talk | contribs)
Adding another reference
Breuwi (talk | contribs)
Enhance intro
Line 1: Line 1:
In [[computer science]], the '''interval tree''' is an [[ordered tree data structure|ordered tree]] [[data structure]] to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval. An important special case is finding all intervals that contain a particular point.
In [[computer science]], the '''interval tree''' is an [[ordered tree data structure|ordered tree]] [[data structure]] to hold intervals. Specifically, it allows one to efficiently find all intervals or that overlap with any given interval or point. It is often used for windowing queries, for example, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene.


An interval tree is a simple ordered tree, for example a [[binary search tree]] or [[self-balancing binary search tree]], where the tree is ordered by the 'low' values of the intervals, and an extra annotation is added to every node recording the maximum high value of both its subtrees. It is simple to maintain this attribute in only O(''h'') steps during each addition or removal of a node, where ''h'' is the height of the node added or removed in the tree, by updating all ancestors of the node from the bottom up.
An interval tree is a simple ordered tree, for example a [[binary search tree]] or [[self-balancing binary search tree]], where the tree is ordered by the 'low' values of the intervals, and an extra annotation is added to every node recording the maximum high value of both its subtrees. It is simple to maintain this attribute in only O(''h'') steps during each addition or removal of a node, where ''h'' is the height of the node added or removed in the tree, by updating all ancestors of the node from the bottom up.

Revision as of 04:31, 23 September 2006

In computer science, the interval tree is an ordered tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals or that overlap with any given interval or point. It is often used for windowing queries, for example, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene.

An interval tree is a simple ordered tree, for example a binary search tree or self-balancing binary search tree, where the tree is ordered by the 'low' values of the intervals, and an extra annotation is added to every node recording the maximum high value of both its subtrees. It is simple to maintain this attribute in only O(h) steps during each addition or removal of a node, where h is the height of the node added or removed in the tree, by updating all ancestors of the node from the bottom up.

Now, it's known that two intervals A and B overlap only when both A.low ≤ B.high and A.high ≥ B.low. When searching the trees for nodes overlapping with a given interval, you can immediately skip:

  • all nodes to the right of nodes whose low value is past the end of the given interval.
  • all nodes that have their maximum 'high' value below the start of the given interval.

This is easily extended to higher dimensions, by cycling through the dimensions at each level of the tree. For example, for two dimensions, the odd levels of the tree might contain ranges for the x coordinate, while the even levels contain ranges for the y coordinate.

References