Reputation: 13
I was wondering if there exist a data structure that can support the following operations(ideally in log(n)
time where n is the number of points):
Upvotes: 1
Views: 70
Reputation: 65437
Assuming that the weights are never negative, we can define a distance function on R2 × R+ (points × weights) as d((p, w), (p′, w′)) = d(p, p′) + |w − w′|. Weird metric, but it plugs right into the cover tree nearest neighbors algorithm. Then we query a point p by first embedding it as (p, v) where v = 0.
To add a constant c to all of the weights, we adjust the “vantage point” v by v ← v − c. A new point p added to the structure with weight w embeds as (p, w − v).
Upvotes: 1