<s>
In	O
computational	O
geometry	O
,	O
the	O
bin	B-Data_Structure
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
allows	O
efficient	O
region	O
queries	O
.	O
</s>
<s>
Each	O
time	O
a	O
data	O
point	O
falls	O
into	O
a	O
bin	B-Data_Structure
,	O
the	O
frequency	O
of	O
that	O
bin	B-Data_Structure
is	O
increased	O
by	O
one	O
.	O
</s>
<s>
The	O
data	B-General_Concept
structure	I-General_Concept
partitions	O
a	O
region	O
of	O
the	O
2D	O
plane	O
into	O
uniform-sized	O
bins	B-Data_Structure
.	O
</s>
<s>
The	O
bounding	B-Algorithm
box	I-Algorithm
of	O
the	O
bins	B-Data_Structure
encloses	O
all	O
candidate	O
rectangles	O
to	O
be	O
queried	O
.	O
</s>
<s>
All	O
the	O
bins	B-Data_Structure
are	O
arranged	O
in	O
a	O
2D	O
array	O
.	O
</s>
<s>
The	O
size	O
of	O
a	O
candidate	O
's	O
array	O
is	O
the	O
number	O
of	O
bins	B-Data_Structure
it	O
intersects	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
top	O
figure	O
,	O
candidate	O
B	O
has	O
6	O
elements	O
arranged	O
in	O
a	O
3	O
row	O
by	O
2	O
column	O
array	O
because	O
it	O
intersects	O
6	O
bins	B-Data_Structure
in	O
such	O
an	O
arrangement	O
.	O
</s>
<s>
Each	O
bin	B-Data_Structure
contains	O
the	O
head	O
of	O
a	O
singly	O
linked	O
list	O
.	O
</s>
<s>
If	O
a	O
candidate	O
intersects	O
a	O
bin	B-Data_Structure
,	O
it	O
is	O
chained	O
to	O
the	O
bin	B-Data_Structure
's	O
linked	O
list	O
.	O
</s>
<s>
Each	O
element	O
in	O
a	O
candidate	O
's	O
array	O
is	O
a	O
link	O
node	O
in	O
the	O
corresponding	O
bin	B-Data_Structure
's	O
linked	O
list	O
.	O
</s>
<s>
From	O
the	O
query	O
rectangle	O
Q	O
,	O
we	O
can	O
find	O
out	O
which	O
bin	B-Data_Structure
its	O
lower-left	O
corner	O
intersects	O
efficiently	O
by	O
simply	O
subtracting	O
the	O
bin	B-Data_Structure
's	O
bounding	B-Algorithm
box	I-Algorithm
's	O
lower-left	O
corner	O
from	O
the	O
lower-left	O
corner	O
of	O
Q	O
and	O
dividing	O
the	O
result	O
by	O
the	O
width	O
and	O
height	O
of	O
a	O
bin	B-Data_Structure
respectively	O
.	O
</s>
<s>
We	O
then	O
can	O
iterate	O
the	O
bins	B-Data_Structure
Q	O
intersects	O
and	O
examine	O
all	O
the	O
candidates	O
in	O
the	O
linked-lists	O
of	O
these	O
bins	B-Data_Structure
.	O
</s>
<s>
Insertion	O
is	O
linear	O
to	O
the	O
number	O
of	O
bins	B-Data_Structure
a	O
candidate	O
intersects	O
because	O
inserting	O
a	O
candidate	O
into	O
1	O
bin	B-Data_Structure
is	O
constant	O
time	O
.	O
</s>
<s>
Deletion	O
is	O
more	O
expensive	O
because	O
we	O
need	O
to	O
search	O
the	O
singly	O
linked	O
list	O
of	O
each	O
bin	B-Data_Structure
the	O
candidate	O
intersects	O
.	O
</s>
<s>
However	O
,	O
instead	O
of	O
locking	O
the	O
whole	O
data	B-General_Concept
structure	I-General_Concept
,	O
a	O
sub-range	O
of	O
bins	B-Data_Structure
may	O
be	O
locked	O
.	O
</s>
<s>
The	O
analysis	O
is	O
similar	O
to	O
a	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
The	O
worst-case	O
scenario	O
is	O
that	O
all	O
candidates	O
are	O
concentrated	O
in	O
one	O
bin	B-Data_Structure
.	O
</s>
<s>
If	O
the	O
candidates	O
are	O
evenly	O
spaced	O
so	O
that	O
each	O
bin	B-Data_Structure
has	O
a	O
constant	O
number	O
of	O
candidates	O
,	O
The	O
query	O
is	O
O(k )	O
where	O
k	O
is	O
the	O
number	O
of	O
bins	B-Data_Structure
the	O
query	O
rectangle	O
intersects	O
.	O
</s>
<s>
Insert	O
and	O
delete	O
are	O
O(m )	O
where	O
m	O
is	O
the	O
number	O
of	O
bins	B-Data_Structure
the	O
inserting	O
candidate	O
intersects	O
.	O
</s>
<s>
Like	O
a	O
hash	B-Algorithm
table	I-Algorithm
,	O
bin	B-Data_Structure
's	O
efficiency	O
depends	O
a	O
lot	O
on	O
the	O
distribution	O
of	O
both	O
location	O
and	O
size	O
of	O
candidates	O
and	O
queries	O
.	O
</s>
<s>
The	O
bin	B-Data_Structure
's	O
size	O
should	O
be	O
such	O
that	O
it	O
contains	O
as	O
few	O
candidates	O
as	O
possible	O
but	O
large	O
enough	O
so	O
that	O
candidates	O
do	O
not	O
span	O
too	O
many	O
bins	B-Data_Structure
.	O
</s>
<s>
If	O
a	O
candidate	O
span	O
many	O
bins	B-Data_Structure
,	O
a	O
query	O
has	O
to	O
skip	O
this	O
candidate	O
over	O
and	O
over	O
again	O
after	O
it	O
is	O
reported	O
at	O
the	O
first	O
bin	B-Data_Structure
of	O
intersection	O
.	O
</s>
<s>
This	O
requires	O
the	O
number	O
of	O
bins	B-Data_Structure
along	O
an	O
axis	O
direction	O
to	O
be	O
an	O
exponent	O
of	O
2	O
.	O
</s>
<s>
Against	O
k-d	B-Data_Structure
tree	I-Data_Structure
,	O
the	O
bin	B-Data_Structure
structure	O
allows	O
efficient	O
insertion	O
and	O
deletion	O
without	O
the	O
complexity	O
of	O
rebalancing	O
.	O
</s>
<s>
This	O
can	O
be	O
very	O
useful	O
in	O
algorithms	O
that	O
need	O
to	O
incrementally	O
add	O
shapes	O
to	O
the	O
search	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
