Insert Interval Algorithm

Since a query may return all intervals, for example if the query is a large interval intersecting all intervals in the collection, this is asymptotically optimal; however, we can do better by considering output-sensitive algorithms, where the runtime is expressed in terms of M, the number of intervals produced by the query. Specifically, it lets one to efficiently find all intervals that overlap with any given interval or point.

Insert Interval source code, pseudocode and analysis