I would assume that the usual definition of overlap applies - that two sets overlap if they contain at least one common element.
You haven't described what you've tried so far, so I'm going to only outline some potential approaches. As this is not a program writing site, but a site for discussion and help with specific programming problems, you won't get a complete program from me.
The naive approach:
- Generate all elements for the range
- Check for every two ranges whether they overlap by checking whether they contain common elements. See perlfaq4.
The direct approach
Note that two ranges overlap if
- The lower bound of one range is between the lower and upper bound of the other range
- The upper bound of one range is between the lower and upper bound of the other range
- For each range, check if they fulfill the modified criteria against each other range
There are other possibilities, like sorting your ranges by lower boundary and then checking for overlap - if you do it that way, you will need to add some more criteria for completely contained subranges. | [reply] |
Simple solution: take all the begin and end points of the ranges. Sort them. Loop over the resulting list. Any time you don't have the end point of range immediately following the begin point of the same range, you have overlap. How to deal with ranges sharing endpoints is left as an exercise to the reader.
In your case, the resulting after sorting is (marking begin points with a capital letter, end points with a lowercase letter)
1(A), 10(a), 11(B), 15(C), 20(b), 21(D), 25(c), 25(E), 30(d), 35(e).
So, c overlaps b, d overlaps c, e overlaps d, and whether e overlaps c is something you'll have to further specify. | [reply] [d/l] |
| [reply] |
..In the above example 'c' and 'e' overlaps with rest of the ranges...
Forgive my thickness, but I don't see how c or e overlap with a, nor how e overlaps with b. So I wonder if the problem has been expressed accurately.
Time flies like an arrow. Fruit flies like a banana.
| [reply] |
Thanks for solution provided great help. | [reply] |