search for interval overlap in list of intervals?

For completeness’ sake, I’d like to add that there is a well-known data structure for just this sort of problem, known (surprise, surprise) as an interval tree. It’s basically an augmented balanced tree (red-black, AVL, your pick) that stores intervals sorted by their left (low) endpoint. The augmentation is that each node stores the largest right (high) endpoint in its subtree. This tree allows you to find all overlapping intervals in O(log n) time.

It’s described in CLRS 14.3.

Leave a Comment