Algorithm 5-7: interval search

Source: Internet
Author: User

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.


  • Related Article

    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.