<s>
The	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
is	O
an	O
algorithm	O
that	O
computes	O
shortest	O
paths	O
from	O
a	O
single	O
source	O
vertex	O
to	O
all	O
of	O
the	O
other	O
vertices	O
in	O
a	O
weighted	O
digraph	O
.	O
</s>
<s>
It	O
is	O
slower	O
than	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
for	O
the	O
same	O
problem	O
,	O
but	O
more	O
versatile	O
,	O
as	O
it	O
is	O
capable	O
of	O
handling	O
graphs	O
in	O
which	O
some	O
of	O
the	O
edge	O
weights	O
are	O
negative	O
numbers	O
.	O
</s>
<s>
Edward	O
F	O
.	O
Moore	O
also	O
published	O
a	O
variation	O
of	O
the	O
algorithm	O
in	O
1959	O
,	O
and	O
for	O
this	O
reason	O
it	O
is	O
also	O
sometimes	O
called	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
–	I-Algorithm
Moore	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
If	O
a	O
graph	B-Application
contains	O
a	O
"	O
negative	O
cycle	O
"	O
(	O
i.e.	O
</s>
<s>
In	O
such	O
a	O
case	O
,	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
can	O
detect	O
and	O
report	O
the	O
negative	O
cycle	O
.	O
</s>
<s>
Like	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
proceeds	O
by	O
relaxation	O
,	O
in	O
which	O
approximations	O
to	O
the	O
correct	O
distance	O
are	O
replaced	O
by	O
better	O
ones	O
until	O
they	O
eventually	O
reach	O
the	O
solution	O
.	O
</s>
<s>
However	O
,	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
uses	O
a	O
priority	B-Application
queue	I-Application
to	O
greedily	B-Algorithm
select	O
the	O
closest	O
vertex	O
that	O
has	O
not	O
yet	O
been	O
processed	O
,	O
and	O
performs	O
this	O
relaxation	O
process	O
on	O
all	O
of	O
its	O
outgoing	O
edges	O
;	O
by	O
contrast	O
,	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
simply	O
relaxes	O
all	O
the	O
edges	O
,	O
and	O
does	O
this	O
times	O
,	O
where	O
is	O
the	O
number	O
of	O
vertices	O
in	O
the	O
graph	B-Application
.	O
</s>
<s>
This	O
method	O
allows	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
to	O
be	O
applied	O
to	O
a	O
wider	O
class	O
of	O
inputs	O
than	O
Dijkstra	O
.	O
</s>
<s>
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
runs	O
in	O
time	O
,	O
where	O
and	O
are	O
the	O
number	O
of	O
vertices	O
and	O
edges	O
respectively	O
.	O
</s>
<s>
A	O
final	O
scan	O
of	O
all	O
the	O
edges	O
is	O
performed	O
and	O
if	O
any	O
distance	O
is	O
updated	O
,	O
then	O
a	O
path	O
of	O
length	O
edges	O
has	O
been	O
found	O
which	O
can	O
only	O
occur	O
if	O
at	O
least	O
one	O
negative	O
cycle	O
exists	O
in	O
the	O
graph	B-Application
.	O
</s>
<s>
The	O
correctness	O
of	O
the	O
algorithm	O
can	O
be	O
shown	O
by	B-Algorithm
induction	I-Algorithm
:	O
</s>
<s>
For	O
the	O
base	O
case	O
of	O
induction	B-Algorithm
,	O
consider	O
i	O
=	O
0	O
and	O
the	O
moment	O
before	O
for	O
loop	O
is	O
executed	O
for	O
the	O
first	O
time	O
.	O
</s>
<s>
However	O
,	O
since	O
it	O
terminates	O
upon	O
finding	O
a	O
negative	O
cycle	O
,	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
for	O
applications	O
in	O
which	O
this	O
is	O
the	O
target	O
to	O
be	O
sought	O
–	O
for	O
example	O
in	O
cycle-cancelling	B-Algorithm
techniques	O
in	O
network	B-Algorithm
flow	I-Algorithm
analysis	O
.	O
</s>
<s>
A	O
distributed	O
variant	O
of	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
is	O
used	O
in	O
distance-vector	B-Protocol
routing	I-Protocol
protocols	I-Protocol
,	O
for	O
example	O
the	O
Routing	B-Protocol
Information	I-Protocol
Protocol	I-Protocol
(	O
RIP	O
)	O
.	O
</s>
<s>
The	O
algorithm	O
is	O
distributed	O
because	O
it	O
involves	O
a	O
number	O
of	O
nodes	O
(	O
routers	O
)	O
within	O
an	O
Autonomous	B-Architecture
system	I-Architecture
(	O
AS	O
)	O
,	O
a	O
collection	O
of	O
IP	O
networks	O
typically	O
owned	O
by	O
an	O
ISP	O
.	O
</s>
<s>
The	O
main	O
disadvantages	O
of	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
in	O
this	O
setting	O
are	O
as	O
follows	O
:	O
</s>
<s>
Changes	O
in	O
network	B-Architecture
topology	I-Architecture
are	O
not	O
reflected	O
quickly	O
since	O
updates	O
are	O
spread	O
node-by-node	O
.	O
</s>
<s>
The	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
may	O
be	O
improved	O
in	O
practice	O
(	O
although	O
not	O
in	O
the	O
worst	O
case	O
)	O
by	O
the	O
observation	O
that	O
,	O
if	O
an	O
iteration	O
of	O
the	O
main	O
loop	O
of	O
the	O
algorithm	O
terminates	O
without	O
making	O
any	O
changes	O
,	O
the	O
algorithm	O
can	O
be	O
immediately	O
terminated	O
,	O
as	O
subsequent	O
iterations	O
will	O
not	O
make	O
any	O
more	O
changes	O
.	O
</s>
<s>
A	O
variation	O
of	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
known	O
as	O
Shortest	B-Algorithm
Path	I-Algorithm
Faster	I-Algorithm
Algorithm	I-Algorithm
,	O
first	O
described	O
by	O
,	O
reduces	O
the	O
number	O
of	O
relaxation	O
steps	O
that	O
need	O
to	O
be	O
performed	O
within	O
each	O
iteration	O
of	O
the	O
algorithm	O
.	O
</s>
<s>
described	O
another	O
improvement	O
to	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Another	O
improvement	O
,	O
by	O
,	O
replaces	O
the	O
arbitrary	O
linear	O
order	O
of	O
the	O
vertices	O
used	O
in	O
Yen	O
's	O
second	O
improvement	O
by	O
a	O
random	B-Algorithm
permutation	I-Algorithm
.	O
</s>
