Professional Documents
Culture Documents
Kd-Trees Continued: Generalized, Incremental NN, Range Searching, Kd-Tree Variants
Kd-Trees Continued: Generalized, Incremental NN, Range Searching, Kd-Tree Variants
- kd-trees pick a key value to be the cutting value, based on the order
of insertion
- Don’t need to use key values => like PR Quadtrees => PR kd-trees
y p1 p1
z c1 c2 c3 c4
Octtree
kd-tree
y b e
Empty
regions X
x c f g
X
d h X Empty
h subtrees
g
b e a
c
a s=LL d e
d f
f h s=L
Idea: keep a priority queue that contains all elements visited so far
(points, bounding boxes)
HeapInsert(H, root, 0)
while not Empty(H):
e := ExtractMin(H)
if IsLeaf(e):
output e as next nearest
else
foreach c in Children(e): dt(q,c) may be the distance
t = Type(c)
to the bounding box
HeapInsert(H, c, dt(q,c))
represented by c, e.g.
Incremental, Generalized NN Example
Some spatial data structure: L,R = left, right
A,B = above, below
c T
S
q LT RT
T
a BQ AQ BS AS
Q
b
b a c
a BQ AQ BS AS
Q
b
b a c
f h f d e
i
g m
i
b
k j
j d
a k
count = 0
if T.data in Query: count++
return count
(For clarity, omitting the cutting
dimension, and the BB(T)
parameters that would be passed
into the function)
Range Query PseudoCode
set = empty_set()
if T.data in Query: set.union({T.data})
set.union(RangeQuery(Q, T.left))
set.union(RangeQuery(Q, T.right))
return set
Expected # of Nodes to Visit
2
Consider a node a with 4
c
cutting dimension = x
b
1
Vertical line can intersect a
exactly one of a’s children 3
(say c)
a Q
AllNodesUnder(a) a
kd-tree Summary:
• Use O(n) storage [1 node for each point]