The interval search problem is to specify a series of intervals and a tested interval to find the intervals that intersection the tested interval.
To solve this problem, you need to write a class. The interface of this class is as follows:
public interface IntervalST
, Value> { void put(Key lo, Key hi, Value value); Value get(Key lo, Key hi) void delete(Key lo, Key hi) Iterable
intersect(Key lo, Key hi);}
Each node has two values. The first value is the start and end of the interval, and the second value is the maximum end of the interval between the node and the subnode. To simplify the problem, the binary tree uses the start point of the interval as the keyword.
Insert operation
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + CrLlyOvH + records + b7dxtXNqLb + records/NDCy/nT0Li4vdq147XE1 + 6089PSx/records + records/records + Cjx1bCBjbGFzcz0 = "list-paddingleft-2">
If there is an intersection between the current node and the searched interval, the current node is returned.
If the left subnode is empty, go to the right
If the entire range is on the left of the current node, go to the left
Go to the right in other cases
Complexity
The complexity of all operations is logN.