<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
(	O
short	O
for	O
k-dimensional	O
tree	B-Application
)	O
is	O
a	O
space-partitioning	B-Algorithm
data	B-General_Concept
structure	I-General_Concept
for	O
organizing	O
points	O
in	O
a	O
k-dimensional	O
space	O
.	O
</s>
<s>
k-d	B-Data_Structure
trees	I-Data_Structure
are	O
a	O
useful	O
data	B-General_Concept
structure	I-General_Concept
for	O
several	O
applications	O
,	O
such	O
as	O
searches	O
involving	O
a	O
multidimensional	O
search	O
key	O
(	O
e.g.	O
</s>
<s>
range	B-Data_Structure
searches	I-Data_Structure
and	O
nearest	B-Algorithm
neighbor	I-Algorithm
searches	I-Algorithm
)	O
and	O
creating	O
point	B-Algorithm
clouds	I-Algorithm
.	O
</s>
<s>
k-d	B-Data_Structure
trees	I-Data_Structure
are	O
a	O
special	O
case	O
of	O
binary	O
space	B-Algorithm
partitioning	I-Algorithm
trees	O
.	O
</s>
<s>
The	O
k-d	B-Data_Structure
tree	I-Data_Structure
is	O
a	O
binary	O
tree	B-Application
in	O
which	O
every	O
node	O
is	O
a	O
k-dimensional	O
point	O
.	O
</s>
<s>
Points	O
to	O
the	O
left	O
of	O
this	O
hyperplane	O
are	O
represented	O
by	O
the	O
left	O
subtree	B-Application
of	O
that	O
node	O
and	O
points	O
to	O
the	O
right	O
of	O
the	O
hyperplane	O
are	O
represented	O
by	O
the	O
right	O
subtree	B-Application
.	O
</s>
<s>
The	O
hyperplane	O
direction	O
is	O
chosen	O
in	O
the	O
following	O
way	O
:	O
every	O
node	O
in	O
the	O
tree	B-Application
is	O
associated	O
with	O
one	O
of	O
the	O
k	O
dimensions	O
,	O
with	O
the	O
hyperplane	O
perpendicular	O
to	O
that	O
dimension	O
's	O
axis	O
.	O
</s>
<s>
So	O
,	O
for	O
example	O
,	O
if	O
for	O
a	O
particular	O
split	O
the	O
"	O
x	O
"	O
axis	O
is	O
chosen	O
,	O
all	O
points	O
in	O
the	O
subtree	B-Application
with	O
a	O
smaller	O
"	O
x	O
"	O
value	O
than	O
the	O
node	O
will	O
appear	O
in	O
the	O
left	O
subtree	B-Application
and	O
all	O
points	O
with	O
a	O
larger	O
"	O
x	O
"	O
value	O
will	O
be	O
in	O
the	O
right	O
subtree	B-Application
.	O
</s>
<s>
Since	O
there	O
are	O
many	O
possible	O
ways	O
to	O
choose	O
axis-aligned	O
splitting	O
planes	O
,	O
there	O
are	O
many	O
different	O
ways	O
to	O
construct	O
k-d	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
The	O
canonical	O
method	O
of	O
k-d	B-Data_Structure
tree	I-Data_Structure
construction	O
has	O
the	O
following	O
constraints	O
:	O
</s>
<s>
As	O
one	O
moves	O
down	O
the	O
tree	B-Application
,	O
one	O
cycles	O
through	O
the	O
axes	O
used	O
to	O
select	B-Algorithm
the	O
splitting	O
planes	O
.	O
</s>
<s>
(	O
For	O
example	O
,	O
in	O
a	O
3-dimensional	O
tree	B-Application
,	O
the	O
root	O
would	O
have	O
an	O
x-aligned	O
plane	O
,	O
the	O
root	O
's	O
children	O
would	O
both	O
have	O
y-aligned	O
planes	O
,	O
the	O
root	O
's	O
grandchildren	O
would	O
all	O
have	O
z-aligned	O
planes	O
,	O
the	O
root	O
's	O
great-grandchildren	O
would	O
all	O
have	O
x-aligned	O
planes	O
,	O
the	O
root	O
's	O
great-great-grandchildren	O
would	O
all	O
have	O
y-aligned	O
planes	O
,	O
and	O
so	O
on	O
.	O
)	O
</s>
<s>
Points	O
are	O
inserted	O
by	O
selecting	O
the	O
median	O
of	O
the	O
points	O
being	O
put	O
into	O
the	O
subtree	B-Application
,	O
with	O
respect	O
to	O
their	O
coordinates	O
in	O
the	O
axis	O
being	O
used	O
to	O
create	O
the	O
splitting	O
plane	O
.	O
</s>
<s>
This	O
method	O
leads	O
to	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
,	O
in	O
which	O
each	O
leaf	O
node	O
is	O
approximately	O
the	O
same	O
distance	O
from	O
the	O
root	O
.	O
</s>
<s>
However	O
,	O
balanced	B-Data_Structure
trees	I-Data_Structure
are	O
not	O
necessarily	O
optimal	O
for	O
all	O
applications	O
.	O
</s>
<s>
Note	O
that	O
it	O
is	O
not	O
required	O
to	O
select	B-Algorithm
the	O
median	O
point	O
.	O
</s>
<s>
In	O
the	O
case	O
where	O
median	O
points	O
are	O
not	O
selected	O
,	O
there	O
is	O
no	O
guarantee	O
that	O
the	O
tree	B-Application
will	O
be	O
balanced	B-Data_Structure
.	O
</s>
<s>
To	O
avoid	O
coding	O
a	O
complex	O
median-finding	B-Algorithm
algorithm	O
or	O
using	O
an	O
sort	O
such	O
as	O
heapsort	B-Application
or	O
mergesort	B-Algorithm
to	O
sort	O
all	O
n	O
points	O
,	O
a	O
popular	O
practice	O
is	O
to	O
sort	O
a	O
fixed	O
number	O
of	O
randomly	O
selected	O
points	O
,	O
and	O
use	O
the	O
median	O
of	O
those	O
points	O
to	O
serve	O
as	O
the	O
splitting	O
plane	O
.	O
</s>
<s>
In	O
practice	O
,	O
this	O
technique	O
often	O
results	O
in	O
nicely	O
balanced	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
Given	O
a	O
list	O
of	O
n	O
points	O
,	O
the	O
following	O
algorithm	O
uses	O
a	O
median-finding	B-Algorithm
sort	O
to	O
construct	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
containing	O
those	O
points	O
.	O
</s>
<s>
select	B-Algorithm
median	O
by	O
axis	O
from	O
pointList	O
;	O
</s>
<s>
</s>
<s>
</s>
<s>
This	O
algorithm	O
creates	O
the	O
invariant	B-Application
that	O
for	O
any	O
node	O
,	O
all	O
the	O
nodes	O
in	O
the	O
left	O
subtree	B-Application
are	O
on	O
one	O
side	O
of	O
a	O
splitting	O
plane	O
,	O
and	O
all	O
the	O
nodes	O
in	O
the	O
right	O
subtree	B-Application
are	O
on	O
the	O
other	O
side	O
.	O
</s>
<s>
Alternative	O
algorithms	O
for	O
building	O
a	O
balanced	B-Data_Structure
presort	O
the	O
data	O
prior	O
to	O
building	O
the	O
tree	B-Application
.	O
</s>
<s>
Then	O
,	O
they	O
maintain	O
the	O
order	O
of	O
the	O
presort	O
during	O
tree	B-Application
construction	O
and	O
hence	O
eliminate	O
the	O
costly	O
step	O
of	O
finding	O
the	O
median	O
at	O
each	O
level	O
of	O
subdivision	O
.	O
</s>
<s>
Two	O
such	O
algorithms	O
build	O
a	O
balanced	B-Data_Structure
to	O
sort	O
triangles	O
in	O
order	O
to	O
improve	O
the	O
execution	O
time	O
of	O
ray	B-Algorithm
tracing	I-Algorithm
for	O
three-dimensional	O
computer	O
graphics	O
.	O
</s>
<s>
These	O
algorithms	O
presort	O
n	O
triangles	O
prior	O
to	O
building	O
the	O
,	O
then	O
build	O
the	O
tree	B-Application
in	O
time	O
in	O
the	O
best	O
case	O
.	O
</s>
<s>
An	O
algorithm	O
that	O
builds	O
a	O
balanced	B-Data_Structure
to	O
sort	O
points	O
has	O
a	O
worst-case	O
complexity	O
of	O
.	O
</s>
<s>
This	O
algorithm	O
presorts	O
n	O
points	O
in	O
each	O
of	O
k	O
dimensions	O
using	O
an	O
sort	O
such	O
as	O
Heapsort	B-Application
or	O
Mergesort	B-Algorithm
prior	O
to	O
building	O
the	O
tree	B-Application
.	O
</s>
<s>
It	O
then	O
maintains	O
the	O
order	O
of	O
these	O
k	O
presorts	O
during	O
tree	B-Application
construction	O
and	O
thereby	O
avoids	O
finding	O
the	O
median	O
at	O
each	O
level	O
of	O
subdivision	O
.	O
</s>
<s>
One	O
adds	O
a	O
new	O
point	O
to	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
in	O
the	O
same	O
way	O
as	O
one	O
adds	O
an	O
element	O
to	O
any	O
other	O
search	B-Language
tree	I-Language
.	O
</s>
<s>
First	O
,	O
traverse	O
the	O
tree	B-Application
,	O
starting	O
from	O
the	O
root	O
and	O
moving	O
to	O
either	O
the	O
left	O
or	O
the	O
right	O
child	O
depending	O
on	O
whether	O
the	O
point	O
to	O
be	O
inserted	O
is	O
on	O
the	O
"	O
left	O
"	O
or	O
"	O
right	O
"	O
side	O
of	O
the	O
splitting	O
plane	O
.	O
</s>
<s>
Adding	O
points	O
in	O
this	O
manner	O
can	O
cause	O
the	O
tree	B-Application
to	O
become	O
unbalanced	O
,	O
leading	O
to	O
decreased	O
tree	B-Application
performance	O
.	O
</s>
<s>
The	O
rate	O
of	O
tree	B-Application
performance	O
degradation	O
is	O
dependent	O
upon	O
the	O
spatial	O
distribution	O
of	O
tree	B-Application
points	O
being	O
added	O
,	O
and	O
the	O
number	O
of	O
points	O
added	O
in	O
relation	O
to	O
the	O
tree	B-Application
size	O
.	O
</s>
<s>
If	O
a	O
tree	B-Application
becomes	O
too	O
unbalanced	O
,	O
it	O
may	O
need	O
to	O
be	O
re-balanced	O
to	O
restore	O
the	O
performance	O
of	O
queries	O
that	O
rely	O
on	O
the	O
tree	B-Application
balancing	O
,	O
such	O
as	O
nearest	O
neighbour	O
searching	O
.	O
</s>
<s>
To	O
remove	O
a	O
point	O
from	O
an	O
existing	O
k-d	B-Data_Structure
tree	I-Data_Structure
,	O
without	O
breaking	O
the	O
invariant	B-Application
,	O
the	O
easiest	O
way	O
is	O
to	O
form	O
the	O
set	O
of	O
all	O
nodes	O
and	O
leaves	O
from	O
the	O
children	O
of	O
the	O
target	O
node	O
,	O
and	O
recreate	O
that	O
part	O
of	O
the	O
tree	B-Application
.	O
</s>
<s>
For	O
the	O
general	O
case	O
,	O
find	O
a	O
replacement	O
point	O
,	O
say	O
,	O
from	O
the	O
subtree	B-Application
rooted	O
at	O
.	O
</s>
<s>
For	O
finding	O
a	O
replacement	O
point	O
,	O
if	O
discriminates	O
on	O
(	O
say	O
)	O
and	O
has	O
a	O
right	O
child	O
,	O
find	O
the	O
point	O
with	O
the	O
minimum	O
value	O
from	O
the	O
subtree	B-Application
rooted	O
at	O
the	O
right	O
child	O
.	O
</s>
<s>
Otherwise	O
,	O
find	O
the	O
point	O
with	O
the	O
maximum	O
value	O
from	O
the	O
subtree	B-Application
rooted	O
at	O
the	O
left	O
child	O
.	O
</s>
<s>
Balancing	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
requires	O
care	O
because	O
k-d	B-Data_Structure
trees	I-Data_Structure
are	O
sorted	O
in	O
multiple	O
dimensions	O
so	O
the	O
tree-rotation	B-Data_Structure
technique	O
cannot	O
be	O
used	O
to	O
balance	O
them	O
as	O
this	O
may	O
break	O
the	O
invariant	B-Application
.	O
</s>
<s>
Several	O
variants	O
of	O
balanced	B-Data_Structure
k-d	B-Data_Structure
trees	I-Data_Structure
exist	O
.	O
</s>
<s>
They	O
include	O
divided	O
k-d	B-Data_Structure
tree	I-Data_Structure
,	O
pseudo	O
k-d	B-Data_Structure
tree	I-Data_Structure
,	O
K-D-B-tree	B-Data_Structure
,	O
hB-tree	O
and	O
Bkd-tree	O
.	O
</s>
<s>
Many	O
of	O
these	O
variants	O
are	O
adaptive	B-Data_Structure
k-d	I-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
The	O
nearest	B-Algorithm
neighbour	I-Algorithm
search	I-Algorithm
(	O
NN	O
)	O
algorithm	O
aims	O
to	O
find	O
the	O
point	O
in	O
the	O
tree	B-Application
that	O
is	O
nearest	O
to	O
a	O
given	O
input	O
point	O
.	O
</s>
<s>
This	O
search	O
can	O
be	O
done	O
efficiently	O
by	O
using	O
the	O
tree	B-Application
properties	O
to	O
quickly	O
eliminate	O
large	O
portions	O
of	O
the	O
search	O
space	O
.	O
</s>
<s>
Searching	O
for	O
a	O
nearest	O
neighbour	O
in	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
proceeds	O
as	O
follows	O
:	O
</s>
<s>
Starting	O
with	O
the	O
root	B-Application
node	I-Application
,	O
the	O
algorithm	O
moves	O
down	O
the	O
tree	B-Application
recursively	O
,	O
in	O
the	O
same	O
way	O
that	O
it	O
would	O
if	O
the	O
search	O
point	O
were	O
being	O
inserted	O
(	O
i.e.	O
</s>
<s>
The	O
algorithm	O
unwinds	O
the	O
recursion	O
of	O
the	O
tree	B-Application
,	O
performing	O
the	O
following	O
steps	O
at	O
each	O
node	O
:	O
</s>
<s>
If	O
the	O
hypersphere	O
crosses	O
the	O
plane	O
,	O
there	O
could	O
be	O
nearer	O
points	O
on	O
the	O
other	O
side	O
of	O
the	O
plane	O
,	O
so	O
the	O
algorithm	O
must	O
move	O
down	O
the	O
other	O
branch	O
of	O
the	O
tree	B-Application
from	O
the	O
current	O
node	O
looking	O
for	O
closer	O
points	O
,	O
following	O
the	O
same	O
recursive	O
process	O
as	O
the	O
entire	O
search	O
.	O
</s>
<s>
If	O
the	O
hypersphere	O
does	O
n't	O
intersect	O
the	O
splitting	O
plane	O
,	O
then	O
the	O
algorithm	O
continues	O
walking	O
up	O
the	O
tree	B-Application
,	O
and	O
the	O
entire	O
branch	O
on	O
the	O
other	O
side	O
of	O
that	O
node	O
is	O
eliminated	O
.	O
</s>
<s>
When	O
the	O
algorithm	O
finishes	O
this	O
process	O
for	O
the	O
root	B-Application
node	I-Application
,	O
then	O
the	O
search	O
is	O
complete	O
.	O
</s>
<s>
For	O
example	O
,	O
approximate	O
nearest	O
neighbour	O
searching	O
can	O
be	O
achieved	O
by	O
simply	O
setting	O
an	O
upper	O
bound	O
on	O
the	O
number	O
points	O
to	O
examine	O
in	O
the	O
tree	B-Application
,	O
or	O
by	O
interrupting	O
the	O
search	O
process	O
based	O
upon	O
a	O
real	O
time	O
clock	O
(	O
which	O
may	O
be	O
more	O
appropriate	O
in	O
hardware	O
implementations	O
)	O
.	O
</s>
<s>
Nearest	O
neighbour	O
for	O
points	O
that	O
are	O
in	O
the	O
tree	B-Application
already	O
can	O
be	O
achieved	O
by	O
not	O
updating	O
the	O
refinement	O
for	O
nodes	O
that	O
give	O
zero	O
distance	O
as	O
the	O
result	O
,	O
this	O
has	O
the	O
downside	O
of	O
discarding	O
points	O
that	O
are	O
not	O
unique	O
,	O
but	O
are	O
co-located	O
with	O
the	O
original	O
search	O
point	O
.	O
</s>
<s>
One	O
of	O
its	O
implementations	O
is	O
best-bin-first	B-Algorithm
search	I-Algorithm
.	O
</s>
<s>
A	O
range	B-Data_Structure
search	I-Data_Structure
searches	O
for	O
ranges	O
of	O
parameters	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
a	O
tree	B-Application
is	O
storing	O
values	O
corresponding	O
to	O
income	O
and	O
age	O
,	O
then	O
a	O
range	B-Data_Structure
search	I-Data_Structure
might	O
be	O
something	O
like	O
looking	O
for	O
all	O
members	O
of	O
the	O
tree	B-Application
which	O
have	O
an	O
age	O
between	O
20	O
and	O
50	O
years	O
and	O
an	O
income	O
between	O
50,000	O
and	O
80,000	O
.	O
</s>
<s>
Since	O
k-d	B-Data_Structure
trees	I-Data_Structure
divide	O
the	O
range	O
of	O
a	O
domain	O
in	O
half	O
at	O
each	O
level	O
of	O
the	O
tree	B-Application
,	O
they	O
are	O
useful	O
for	O
performing	O
range	B-Data_Structure
searches	I-Data_Structure
.	O
</s>
<s>
Analyses	O
of	O
binary	B-Language
search	I-Language
trees	I-Language
has	O
found	O
that	O
the	O
worst	O
case	O
time	O
for	O
range	B-Data_Structure
search	I-Data_Structure
in	O
a	O
k-dimensional	O
k-d	B-Data_Structure
tree	I-Data_Structure
containing	O
n	O
nodes	O
is	O
given	O
by	O
the	O
following	O
equation	O
.	O
</s>
<s>
In	O
high-dimensional	O
spaces	O
,	O
the	O
curse	B-Algorithm
of	I-Algorithm
dimensionality	I-Algorithm
causes	O
the	O
algorithm	O
to	O
need	O
to	O
visit	O
many	O
more	O
branches	O
than	O
in	O
lower-dimensional	O
spaces	O
.	O
</s>
<s>
Otherwise	O
,	O
when	O
k-d	B-Data_Structure
trees	I-Data_Structure
are	O
used	O
with	O
high-dimensional	O
data	O
,	O
most	O
of	O
the	O
points	O
in	O
the	O
tree	B-Application
will	O
be	O
evaluated	O
and	O
the	O
efficiency	O
is	O
no	O
better	O
than	O
exhaustive	O
search	O
,	O
and	O
,	O
if	O
a	O
good-enough	O
fast	O
answer	O
is	O
required	O
,	O
approximate	O
nearest-neighbour	O
methods	O
should	O
be	O
used	O
instead	O
.	O
</s>
<s>
Additionally	O
,	O
even	O
in	O
low-dimensional	O
space	O
,	O
if	O
the	O
average	O
pairwise	O
distance	O
between	O
the	O
k	O
nearest	O
neighbors	O
of	O
the	O
query	O
point	O
is	O
significantly	O
less	O
than	O
the	O
average	O
distance	O
between	O
the	O
query	O
point	O
and	O
each	O
of	O
the	O
k	O
nearest	O
neighbors	O
,	O
the	O
performance	O
of	O
nearest	B-Algorithm
neighbor	I-Algorithm
search	I-Algorithm
degrades	O
towards	O
linear	O
,	O
since	O
the	O
distances	O
from	O
the	O
query	O
point	O
to	O
each	O
nearest	O
neighbor	O
are	O
of	O
similar	O
magnitude	O
.	O
</s>
<s>
To	O
mitigate	O
the	O
potentially	O
significant	O
performance	O
degradation	O
of	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
search	O
in	O
the	O
worst	O
case	O
,	O
a	O
maximum	O
distance	O
parameter	O
can	O
be	O
provided	O
to	O
the	O
tree	B-Application
search	O
algorithm	O
,	O
and	O
the	O
recursive	O
search	O
can	O
be	O
pruned	O
whenever	O
the	O
closest	O
point	O
in	O
a	O
given	O
branch	O
of	O
the	O
tree	B-Application
cannot	O
be	O
closer	O
than	O
this	O
maximum	O
distance	O
.	O
</s>
<s>
This	O
may	O
result	O
in	O
a	O
nearest	B-Algorithm
neighbor	I-Algorithm
search	I-Algorithm
failing	O
to	O
return	O
a	O
nearest	O
neighbor	O
,	O
which	O
means	O
no	O
points	O
are	O
within	O
this	O
maximum	O
distance	O
from	O
the	O
query	O
point	O
.	O
</s>
<s>
Building	O
a	O
static	O
k-d	B-Data_Structure
tree	I-Data_Structure
from	O
n	O
points	O
has	O
the	O
following	O
worst-case	O
complexity	O
:	O
</s>
<s>
O(n log2 n )	O
if	O
an	O
sort	O
such	O
as	O
Heapsort	B-Application
or	O
Mergesort	B-Algorithm
is	O
used	O
to	O
find	O
the	O
median	O
at	O
each	O
level	O
of	O
the	O
nascent	O
tree	B-Application
;	O
</s>
<s>
O(n log n )	O
if	O
an	O
median	B-Algorithm
of	I-Algorithm
medians	I-Algorithm
algorithm	I-Algorithm
is	O
used	O
to	O
select	B-Algorithm
the	O
median	O
at	O
each	O
level	O
of	O
the	O
nascent	O
tree	B-Application
;	O
</s>
<s>
O(kn log n )	O
if	O
n	O
points	O
are	O
presorted	O
in	O
each	O
of	O
k	O
dimensions	O
using	O
an	O
sort	O
such	O
as	O
Heapsort	B-Application
or	O
Mergesort	B-Algorithm
prior	O
to	O
building	O
the	O
.	O
</s>
<s>
Inserting	O
a	O
new	O
point	O
into	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
takes	O
time	O
.	O
</s>
<s>
Removing	O
a	O
point	O
from	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
takes	O
time	O
.	O
</s>
<s>
Querying	O
an	O
axis-parallel	O
range	O
in	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
takes	O
time	O
,	O
where	O
m	O
is	O
the	O
number	O
of	O
the	O
reported	O
points	O
,	O
and	O
k	O
the	O
dimension	O
of	O
the	O
k-d	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
Finding	O
1	O
nearest	O
neighbour	O
in	O
a	O
balanced	B-Data_Structure
k-d	B-Data_Structure
tree	I-Data_Structure
with	O
randomly	O
distributed	O
points	O
takes	O
time	O
on	O
average	O
.	O
</s>
<s>
Instead	O
of	O
points	O
,	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
can	O
also	O
contain	O
rectangles	O
or	O
hyperrectangles	O
.	O
</s>
<s>
Thus	O
range	B-Data_Structure
search	I-Data_Structure
becomes	O
the	O
problem	O
of	O
returning	O
all	O
rectangles	O
intersecting	O
the	O
search	O
rectangle	O
.	O
</s>
<s>
The	O
tree	B-Application
is	O
constructed	O
the	O
usual	O
way	O
with	O
all	O
the	O
rectangles	O
at	O
the	O
leaves	O
.	O
</s>
<s>
In	O
an	O
orthogonal	O
range	B-Data_Structure
search	I-Data_Structure
,	O
the	O
opposite	O
coordinate	O
is	O
used	O
when	O
comparing	O
against	O
the	O
median	O
.	O
</s>
<s>
See	O
also	O
interval	B-Data_Structure
tree	I-Data_Structure
,	O
which	O
is	O
a	O
1-dimensional	O
special	O
case	O
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
define	O
a	O
k-d	B-Data_Structure
tree	I-Data_Structure
with	O
points	O
stored	O
solely	O
in	O
leaves	O
.	O
</s>
<s>
This	O
form	O
of	O
k-d	B-Data_Structure
tree	I-Data_Structure
allows	O
a	O
variety	O
of	O
split	O
mechanics	O
other	O
than	O
the	O
standard	O
median	O
split	O
.	O
</s>
<s>
Using	O
sliding-midpoint	O
,	O
an	O
approximate	O
nearest	B-Algorithm
neighbour	I-Algorithm
query	I-Algorithm
can	O
be	O
answered	O
in	O
.	O
</s>
