The interval search problem gives a range of ranges, while testing the interval of time, looking for and testing intervals across intervals.
To solve the problem, you need to write a class specifically for the interface of this class, such as the following:
Public interface Intervalst<key extends Comparable<key>, value> { void put (Key lo, key Hi, value value);
value get (Key lo, key hi) void Delete (key lo, key hi) iterable<value> intersect (Key lo, key hi);}
There are two values in each of these nodes. The first value is the start and end point of the interval, and the second value is the largest interval end of the node and the child node. In order to simplify the problem, the two-fork tree is taken as keyword by the interval starting point.
Insert operation
When inserting the interval, it is inserted according to the rules of the ordinary binary tree. The maximum right interval for all parent nodes needs to be updated after the insert is complete.
Find operations
The find operation requires a running step:
Assuming that the current node is intersected with the searched interval, the current node is returned
Suppose the left child node is empty and the right side is deep
Assuming that the entire interval is on the left side of the current node, the left side is deep
The rest of the situation right side deep
Complexity of
All operations of the complex degree logn.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Algorithm 5-7: Interval retrieval