Data Structures19 sections · 729 units
Open in Course

Point Query

Finding intervals at point

To find all intervals containing point pp:

function queryPoint(node, p)
    if node is null then
        return empty list

    result := []

    if p < node.mid then
        // Check center intervals sorted by low
        for interval in node.centerByLow
            if interval.low <= p then
                result.add(interval)
            else
                break
        result.addAll(queryPoint(node.left, p))

    else if p > node.mid then
        // Check center intervals sorted by high
        for interval in node.centerByHigh
            if interval.high >= p then
                result.add(interval)
            else
                break
        result.addAll(queryPoint(node.right, p))

    else // p == node.mid
        result.addAll(node.center)

    return result

Time: O(logn+k)O(\log n + k) where kk is the number of results.