The intersection of two intervals [s1, s2] and [t1, t2] is empty if and only if :
t2 < s1 or s2 < t1
So, for two intervals, in order to check whether these two intersect or not, you only need to perform the above test.
Also, as soon as you find out that s2 <t1, then it makes no sense to go further in the list that cited t1, since large intervals never intersect, which means that you must move on.
Naive Psuedo algorithm:
given [s1, s2] for each list [t1, t2, ... t(n)] in search_lists for each interval [t(x), t(x+1)] from [t1, t2, ... t(n] (x goes from 0 to n-1) if t(x+1) < s1 continue if s2 < t(x) break saveInterval()
This can be improved quite a bit to really use the fact that [t1, t2, .., t (n)] is sorted.
first of all, note that [s1, s2] will intersect with [t(x), t(x+1)] iff t(x+1) >= s1 and s2 >= t(x)
but
if t(x) >= s1 then for every h>0 `t(x+h) >= s1`
also
if s2 >= t(x) then for every h>0 `s2 >= t(xh)`
therefore, if we find the smallest i, so that t (i + 1)> = s1, then all intervals from [t(i), t(i+1)] occur on the first intersection condition; those. ( [t(i+1), t(i+2)] , [t(i+2), t(i+3)] ...)
and if we find the largest j, so that s2> = t (j-1), then all the intervals from [t(j-1), t(j)] back will correspond to the second condition. those. ( [t(j-2), t(j-1)] , [t(j-3), t(j-2)] ...)
All intervals between i and j satisfy both criteria and only them.
So, the final algorithm:
given [s1, s2] for each list [t1, t2, ... t(n)] in search_lists find the smallest i such that t(i+1)>=s1 find the biggest j such that s2>= t(j-1) if j>i then all the intervals between `{t(i)... t(j)}` intersect with [s1, s2] otherwise there is no intersection.
Since {t1, t2, t3...t(n)} sorted, we can use binary search to efficiently find indices i and j
EDIT2:
Intersection of [s1, s2] and [t1, t2]: [max(s1, t1), min(s2,t2)]
dimensions: L1 = s2-s1 L2 = t2-t1 L3 = min(s2,t2) - max(s1,t1)
The rating you are looking for: L3/ min(L2, L1) rating from 0 to 1.
(min(s2,t2) - max(s1,t1)) / ( min(s2-s1, t2-t1) )
The calculation cost is 3 tests, 3 minus operations and one floating point operation. But I assume that the intervals are valid and the intersection exists, otherwise additional tests are needed. ( s2>s2 , t2>t1 and min(s2,t2) > max(s1,t1) . The final test is the same iff condition for the intersection from the discussion above.