Let a
be an interval [a.start, a.end]
, where a.start
and a.end
are real numbers such that 0 <= a.start < a.end <= 1
.
Two such intervals a
and b
intersect if a.start < b.start < a.end
OR b.start <= a.start < b.end
Let As
be a sorted list of non-intersecting intervals a_0, a_1, ..., a_n
such that a_i
doesn't intersect a_j
and a_i.start < a_j.start
for i < j
Given the interval b
, determine the first interval and last interval in As
that b
intersects (or find no intersections). i.e.: If possible, find i
and j
such that b intersects with a_i
and a_j
but not a_{i-1}
or a_{j+1}
I've solved this with a modified binary search (O(n) in the worst case), so my intuition is that this is a lg(n) problem, but I don't know if I have the best algorithm.