How to prove the time complexity of query in interval tree

33 views Asked by At

Original question is* Given an interval tree T and an interval i, describe how to list all intervals in T that overlap i in O(min(n,klgn)) time, where k is the number of intervals in the output list.*

It is clear that we can use k query & delete to have a O(klogn) algorithm.But this can be O(nlogn) if k is O(N). Otherwise we can use a trimmed traversal which is at most O(N) as provided in CLRS 14.3 as follow

INTERVALS-SEARCH(T, x, i)
    let list be an empty array
    if i overlaps x.int
        list.APPEND(x)
    if x.left != T.nil and x.left.max > i.low
        list = list.APPEND(INTERVALS-SEARCH(T, x.left, i))
    if x.right != T.nil and x.int.low ≤ i.high and x.right.max ≥ i.low
        list = list.APPEND(INTERVALS-SEARCH(T, x.right, i))
    return list

but how to prove this is at most O(klogn)?

I am trying to prove the traversal traverse both subtrees for O(k) time but failed.

I am expecting for a strict proof of the time complexity

0

There are 0 answers