<s>
The	O
Shortest	B-Algorithm
Path	I-Algorithm
Faster	I-Algorithm
Algorithm	I-Algorithm
(	O
SPFA	B-Algorithm
)	O
is	O
an	O
improvement	O
of	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
which	O
computes	O
single-source	O
shortest	O
paths	O
in	O
a	O
weighted	O
directed	O
graph	O
.	O
</s>
<s>
However	O
,	O
the	O
worst-case	O
complexity	O
of	O
SPFA	B-Algorithm
is	O
the	O
same	O
as	O
that	O
of	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
,	O
so	O
for	O
graphs	O
with	O
nonnegative	O
edge	O
weights	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
preferred	O
.	O
</s>
<s>
The	O
SPFA	B-Algorithm
algorithm	O
was	O
first	O
published	O
by	O
Edward	O
F	O
.	O
Moore	O
in	O
1959	O
,	O
as	O
a	O
generalization	O
of	O
breadth	B-Algorithm
first	I-Algorithm
search	I-Algorithm
;	O
SPFA	B-Algorithm
is	O
Moore	O
's	O
“	O
Algorithm	O
D.	O
”	O
The	O
name	O
,	O
“	O
Shortest	B-Algorithm
Path	I-Algorithm
Faster	I-Algorithm
Algorithm	I-Algorithm
(	O
SPFA	B-Algorithm
)	O
,	O
”	O
was	O
given	O
by	O
FanDing	O
Duan	O
,	O
a	O
Chinese	O
researcher	O
who	O
rediscovered	O
the	O
algorithm	O
in	O
1994	O
.	O
</s>
<s>
Given	O
a	O
weighted	O
directed	O
graph	O
and	O
a	O
source	O
vertex	O
,	O
the	O
SPFA	B-Algorithm
algorithm	O
finds	O
the	O
shortest	O
path	O
from	O
,	O
to	O
each	O
vertex	O
,	O
in	O
the	O
graph	O
.	O
</s>
<s>
The	O
basic	O
idea	O
of	O
SPFA	B-Algorithm
is	O
the	O
same	O
as	O
the	O
Bellman-Ford	B-Algorithm
algorithm	I-Algorithm
in	O
that	O
each	O
vertex	O
is	O
used	O
as	O
a	O
candidate	O
to	O
relax	O
its	O
adjacent	O
vertices	O
.	O
</s>
<s>
The	O
improvement	O
over	O
the	O
latter	O
is	O
that	O
instead	O
of	O
trying	O
all	O
vertices	O
blindly	O
,	O
SPFA	B-Algorithm
maintains	O
a	O
queue	O
of	O
candidate	O
vertices	O
and	O
adds	O
a	O
vertex	O
to	O
the	O
queue	O
only	O
if	O
that	O
vertex	O
is	O
relaxed	O
.	O
</s>
<s>
The	O
worst-case	O
running	O
time	O
of	O
the	O
algorithm	O
is	O
,	O
just	O
like	O
the	O
standard	O
Bellman-Ford	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Experiments	O
suggest	O
that	O
the	O
average	O
running	O
time	O
is	O
,	O
and	O
indeed	O
this	O
is	O
true	O
on	O
random	O
graphs	O
,	O
but	O
it	O
is	O
possible	O
to	O
construct	O
sparse	O
graphs	O
where	O
SPFA	B-Algorithm
runs	O
in	O
time	O
like	O
the	O
usual	O
Bellman-Ford	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
In	O
fact	O
,	O
if	O
is	O
a	O
priority	B-Application
queue	I-Application
,	O
then	O
the	O
algorithm	O
pretty	O
much	O
resembles	O
Dijkstra	O
's	O
.	O
</s>
<s>
However	O
,	O
since	O
a	O
priority	B-Application
queue	I-Application
is	O
not	O
used	O
here	O
,	O
two	O
techniques	O
are	O
sometimes	O
employed	O
to	O
improve	O
the	O
quality	O
of	O
the	O
queue	O
,	O
which	O
in	O
turn	O
improves	O
the	O
average-case	O
performance	O
(	O
but	O
not	O
the	O
worst-case	O
performance	O
)	O
.	O
</s>
