<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
(	O
also	O
known	O
as	O
Floyd	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
the	O
Roy	O
–	O
Warshall	B-Algorithm
algorithm	I-Algorithm
,	O
the	O
Roy	B-Algorithm
–	I-Algorithm
Floyd	I-Algorithm
algorithm	I-Algorithm
,	O
or	O
the	O
WFI	O
algorithm	O
)	O
is	O
an	O
algorithm	O
for	O
finding	O
shortest	O
paths	O
in	O
a	O
directed	O
weighted	O
graph	B-Application
with	O
positive	O
or	O
negative	O
edge	O
weights	O
(	O
but	O
with	O
no	O
negative	O
cycles	O
)	O
.	O
</s>
<s>
Versions	O
of	O
the	O
algorithm	O
can	O
also	O
be	O
used	O
for	O
finding	O
the	O
transitive	O
closure	O
of	O
a	O
relation	O
,	O
or	O
(	O
in	O
connection	O
with	O
the	O
Schulze	O
voting	O
system	O
)	O
widest	O
paths	O
between	O
all	O
pairs	O
of	O
vertices	O
in	O
a	O
weighted	O
graph	B-Application
.	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
is	O
an	O
example	O
of	O
dynamic	B-Algorithm
programming	I-Algorithm
,	O
and	O
was	O
published	O
in	O
its	O
currently	O
recognized	O
form	O
by	O
Robert	O
Floyd	O
in	O
1962	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
essentially	O
the	O
same	O
as	O
algorithms	O
previously	O
published	O
by	O
Bernard	O
Roy	O
in	O
1959	O
and	O
also	O
by	O
Stephen	O
Warshall	O
in	O
1962	O
for	O
finding	O
the	O
transitive	O
closure	O
of	O
a	O
graph	B-Application
,	O
and	O
is	O
closely	O
related	O
to	O
Kleene	B-General_Concept
's	I-General_Concept
algorithm	I-General_Concept
(	O
published	O
in	O
1956	O
)	O
for	O
converting	O
a	O
deterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
into	O
a	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
compares	O
many	O
possible	O
paths	O
through	O
the	O
graph	B-Application
between	O
each	O
pair	O
of	O
vertices	O
.	O
</s>
<s>
It	O
is	O
guaranteed	O
to	O
find	O
all	O
shortest	O
paths	O
and	O
is	O
able	O
to	O
do	O
this	O
with	O
comparisons	O
in	O
a	O
graph	B-Application
,	O
even	O
though	O
there	O
may	O
be	O
edges	O
in	O
the	O
graph	B-Application
.	O
</s>
<s>
Consider	O
a	O
graph	B-Application
with	O
vertices	O
numbered	O
1	O
through	O
.	O
</s>
<s>
These	O
formulas	O
are	O
the	O
heart	O
of	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
above	O
is	O
executed	O
on	O
the	O
graph	B-Application
on	O
the	O
left	O
below	O
:	O
</s>
<s>
Prior	O
to	O
the	O
first	O
recursion	O
of	O
the	O
outer	O
loop	O
,	O
labeled	O
above	O
,	O
the	O
only	O
known	O
paths	O
correspond	O
to	O
the	O
single	O
edges	O
in	O
the	O
graph	B-Application
.	O
</s>
<s>
For	O
numerically	O
meaningful	O
output	O
,	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
assumes	O
that	O
there	O
are	O
no	O
negative	O
cycles	O
.	O
</s>
<s>
Nevertheless	O
,	O
if	O
there	O
are	O
negative	O
cycles	O
,	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
to	O
detect	O
them	O
.	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
iteratively	O
revises	O
path	O
lengths	O
between	O
all	O
pairs	O
of	O
vertices	O
,	O
including	O
where	O
;	O
</s>
<s>
Hence	O
,	O
to	O
detect	O
negative	O
cycles	O
using	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
,	O
one	O
can	O
inspect	O
the	O
diagonal	O
of	O
the	O
path	O
matrix	O
,	O
and	O
the	O
presence	O
of	O
a	O
negative	O
number	O
indicates	O
that	O
the	O
graph	B-Application
contains	O
at	O
least	O
one	O
negative	O
cycle	O
.	O
</s>
<s>
During	O
the	O
execution	O
of	O
the	O
algorithm	O
,	O
if	O
there	O
is	O
a	O
negative	O
cycle	O
,	O
exponentially	O
large	O
numbers	O
can	O
appear	O
,	O
as	O
large	O
as	O
,	O
where	O
is	O
the	O
largest	O
absolute	O
value	O
of	O
a	O
negative	O
edge	O
in	O
the	O
graph	B-Application
.	O
</s>
<s>
Obviously	O
,	O
in	O
an	O
undirected	O
graph	B-Application
a	O
negative	O
edge	O
creates	O
a	O
negative	O
cycle	O
(	O
i.e.	O
,	O
a	O
closed	O
walk	O
)	O
involving	O
its	O
incident	O
vertices	O
.	O
</s>
<s>
Considering	O
all	O
edges	O
of	O
the	O
above	O
example	O
graph	B-Application
as	O
undirected	O
,	O
e.g.	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
typically	O
only	O
provides	O
the	O
lengths	O
of	O
the	O
paths	O
between	O
all	O
pairs	O
of	O
vertices	O
.	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
to	O
solve	O
the	O
following	O
problems	O
,	O
among	O
others	O
:	O
</s>
<s>
Shortest	O
paths	O
in	O
directed	O
graphs	O
(	O
Floyd	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
)	O
.	O
</s>
<s>
Transitive	O
closure	O
of	O
directed	O
graphs	O
(	O
Warshall	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
)	O
.	O
</s>
<s>
In	O
Warshall	O
's	O
original	O
formulation	O
of	O
the	O
algorithm	O
,	O
the	O
graph	B-Application
is	O
unweighted	O
and	O
represented	O
by	O
a	O
Boolean	O
adjacency	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
For	O
C#	B-Application
,	O
at	O
(	O
A	O
fork	O
of	O
QuickGraph	O
with	O
better	O
compatibility	O
with	O
projects	O
using	O
Portable	O
Class	O
Libraries	O
.	O
)	O
</s>
<s>
The	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
is	O
a	O
good	O
choice	O
for	O
computing	O
paths	O
between	O
all	O
pairs	O
of	O
vertices	O
in	O
dense	O
graphs	O
,	O
in	O
which	O
most	O
or	O
all	O
pairs	O
of	O
vertices	O
are	O
connected	O
by	O
edges	O
.	O
</s>
<s>
For	O
sparse	O
graphs	O
with	O
non-negative	O
edge	O
weights	O
,	O
lower	O
asymptotic	O
complexity	O
can	O
be	O
obtained	O
by	O
running	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
from	O
each	O
possible	O
starting	O
vertex	O
,	O
since	O
the	O
worst-case	O
running	O
time	O
of	O
repeated	O
Dijkstra	O
(	O
using	O
Fibonacci	B-Application
heaps	I-Application
)	O
is	O
smaller	O
than	O
the	O
running	O
time	O
of	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
when	O
is	O
significantly	O
smaller	O
than	O
.	O
</s>
<s>
For	O
sparse	O
graphs	O
with	O
negative	O
edges	O
but	O
no	O
negative	O
cycles	O
,	O
Johnson	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
,	O
with	O
the	O
same	O
asymptotic	O
running	O
time	O
as	O
the	O
repeated	O
Dijkstra	O
approach	O
.	O
</s>
<s>
In	O
addition	O
,	O
because	O
of	O
the	O
high	O
constant	O
factors	O
in	O
their	O
running	O
time	O
,	O
they	O
would	O
only	O
provide	O
a	O
speedup	O
over	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Warshall	I-Algorithm
algorithm	I-Algorithm
for	O
very	O
large	O
graphs	O
.	O
</s>
