Algorithm 5-7: Interval retrieval

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.