<s>
In	O
computing	O
,	O
a	O
distance	B-Application
oracle	I-Application
(	O
DO	O
)	O
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
for	O
calculating	O
distances	O
between	O
vertices	O
in	O
a	O
graph	B-Application
.	O
</s>
<s>
Let	O
G(V,E )	O
be	O
an	O
undirected	O
,	O
weighted	O
graph	B-Application
,	O
with	O
n	O
=|V	O
|	O
nodes	O
and	O
m	O
=	O
|E|	O
edges	O
.	O
</s>
<s>
One	O
way	O
to	O
do	O
this	O
is	O
just	O
run	O
the	O
Dijkstra	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
This	O
takes	O
time	O
,	O
and	O
requires	O
no	O
extra	O
space	O
(	O
besides	O
the	O
graph	B-Application
itself	O
)	O
.	O
</s>
<s>
In	O
order	O
to	O
answer	O
many	O
queries	O
more	O
efficiently	O
,	O
we	O
can	O
spend	O
some	O
time	O
in	O
pre-processing	O
the	O
graph	B-Application
and	O
creating	O
an	O
auxiliary	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
A	O
simple	O
data	B-General_Concept
structure	I-General_Concept
that	O
achieves	O
this	O
goal	O
is	O
a	O
matrix	O
which	O
specifies	O
,	O
for	O
each	O
pair	O
of	O
nodes	O
,	O
the	O
distance	O
between	O
them	O
.	O
</s>
<s>
It	O
can	O
be	O
initialized	O
in	O
time	O
using	O
an	O
all-pairs	O
shortest	O
paths	O
algorithm	O
,	O
such	O
as	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
For	O
every	O
bunch	O
,	O
construct	O
a	O
hash	B-Algorithm
table	I-Algorithm
that	O
holds	O
,	O
for	O
every	O
,	O
the	O
distance	O
.	O
</s>
<s>
(	O
swap	O
the	O
two	O
input	O
nodes	O
;	O
this	O
does	O
not	O
change	O
the	O
distance	O
between	O
them	O
since	O
the	O
graph	B-Application
is	O
undirected	O
)	O
.	O
</s>
<s>
If	O
there	O
is	O
a	O
DO	O
with	O
an	O
approximation	O
factor	O
of	O
at	O
most	O
2	O
,	O
then	O
it	O
is	O
possible	O
to	O
build	O
a	O
set	B-Data_Structure
intersection	I-Data_Structure
oracle	I-Data_Structure
(	O
SIO	O
)	O
with	O
query	O
time	O
and	O
space	O
requirements	O
,	O
where	O
n	O
is	O
the	O
number	O
of	O
sets	O
and	O
N	O
the	O
sum	O
of	O
their	O
sizes	O
;	O
see	O
set	B-Data_Structure
intersection	I-Data_Structure
oracle	I-Data_Structure
#Reduction	O
to	O
approximate	O
distance	B-Application
oracle	I-Application
.	O
</s>
