
空间树结构
|
273
空间树结构
最近邻算法小结
最好情况和平均情况:
O
(log
n
)
最坏情况:
O
(
n
)
nearest (T, x)
n = find parent node in T where x would have been inserted
min = distance from x to n.point
❶
better = nearest (T.root, min, x)
❷
if better found then return better
return n.point
end
nearest (node, min, x)
d = distance from x to node.point
if d < min then
result = node.point
❸
min = d
dp = perpendicular distance from x to node
if dp < min then
❹
pt = nearest (node.above, min, x)
if distance from pt to x < min then
result = pt
min = distance from pt to x
pt = nearest (node.below, min, x)
if distance from pt to x < min then
result = pt