[Algorithm] Interval coincidence inference

Source: Internet
Author: User

Topic description Narration:

Given a source interval [x, y] and n unordered target range [X1,y1],[x2,y2],... [Xn,y,] infers that the given source range [x, Y] is not within the target range.

For example: Given the source interval [1 6] and the target range [1 2][2 4][4 9] can feel the interval [1 6] in the target range, due to the source interval of the set of [1 9].

Imagine a collection of such a target range now. It is frequently necessary to query whether an interval is in the set. So how to reduce the complex of single query

The degree of impurity. Pretreatment. The preprocessing of the interval can satisfy this demand.

Directly on the method:

First step: Merge the bands first (that is, set the interval merge into a disjoint interval)

The second step: in this process after the interval to find such a source interval, about the search, of course, two can have a very good effect, then the interval can be sorted.


So: 1 Sorts the interval by its starting point.

2 Merge intersection interval

32 points to find the source range.


The code is as follows:





[Algorithm] Interval coincidence inference

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.