<s>
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
(	O
)	O
is	O
an	O
algorithm	O
for	O
finding	O
the	O
shortest	O
paths	O
between	O
nodes	O
in	O
a	O
weighted	O
graph	B-Application
,	O
which	O
may	O
represent	O
,	O
for	O
example	O
,	O
road	O
networks	O
.	O
</s>
<s>
Dijkstra	O
's	O
original	O
algorithm	O
found	O
the	O
shortest	O
path	O
between	O
two	O
given	O
nodes	O
,	O
but	O
a	O
more	O
common	O
variant	O
fixes	O
a	O
single	O
node	O
as	O
the	O
"	O
source	O
"	O
node	O
and	O
finds	O
shortest	O
paths	O
from	O
the	O
source	O
to	O
all	O
other	O
nodes	O
in	O
the	O
graph	B-Application
,	O
producing	O
a	O
shortest-path	O
tree	O
.	O
</s>
<s>
For	O
a	O
given	O
source	O
node	O
in	O
the	O
graph	B-Application
,	O
the	O
algorithm	O
finds	O
the	O
shortest	O
path	O
between	O
that	O
node	O
and	O
every	O
other	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
nodes	O
of	O
the	O
graph	B-Application
represent	O
cities	O
and	O
costs	O
of	O
edge	O
paths	O
represent	O
driving	O
distances	O
between	O
pairs	O
of	O
cities	O
connected	O
by	O
a	O
direct	O
road	O
(	O
for	O
simplicity	O
,	O
ignore	O
red	O
lights	O
,	O
stop	O
signs	O
,	O
toll	O
roads	O
and	O
other	O
obstructions	O
)	O
,	O
then	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
to	O
find	O
the	O
shortest	O
route	O
between	O
one	O
city	O
and	O
all	O
other	O
cities	O
.	O
</s>
<s>
A	O
widely	O
used	O
application	O
of	O
shortest	O
path	O
algorithms	O
is	O
network	O
routing	B-Protocol
protocols	I-Protocol
,	O
most	O
notably	O
IS-IS	B-Protocol
(	O
Intermediate	B-Protocol
System	I-Protocol
to	I-Protocol
Intermediate	I-Protocol
System	I-Protocol
)	O
and	O
OSPF	B-Protocol
(	O
Open	B-Protocol
Shortest	I-Protocol
Path	I-Protocol
First	I-Protocol
)	O
.	O
</s>
<s>
It	O
is	O
also	O
employed	O
as	O
a	O
subroutine	O
in	O
other	O
algorithms	O
such	O
as	O
Johnson	B-Algorithm
's	I-Algorithm
.	O
</s>
<s>
The	O
Dijkstra	B-Algorithm
algorithm	I-Algorithm
uses	O
labels	O
that	O
are	O
positive	O
integers	O
or	O
real	O
numbers	O
,	O
which	O
are	O
totally	O
ordered	O
.	O
</s>
<s>
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
uses	O
a	O
data	O
structure	O
for	O
storing	O
and	O
querying	O
partial	O
solutions	O
sorted	O
by	O
distance	O
from	O
the	O
start	O
.	O
</s>
<s>
Dijkstra	O
's	O
original	O
algorithm	O
does	O
not	O
use	O
a	O
min-priority	B-Application
queue	I-Application
and	O
runs	O
in	O
time	O
(	O
where	O
is	O
the	O
number	O
of	O
nodes	O
)	O
.	O
</s>
<s>
propose	O
using	O
a	O
Fibonacci	B-Application
heap	I-Application
min-priority	B-Application
queue	I-Application
to	O
optimize	O
the	O
running	O
time	O
complexity	O
to	O
.	O
</s>
<s>
Additionally	O
,	O
if	O
preprocessing	O
is	O
allowed	O
algorithms	O
such	O
as	O
contraction	B-Protocol
hierarchies	I-Protocol
can	O
be	O
up	O
to	O
seven	O
orders	O
of	O
magnitude	O
faster	O
.	O
</s>
<s>
In	O
some	O
fields	O
,	O
artificial	B-Application
intelligence	I-Application
in	O
particular	O
,	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
or	O
a	O
variant	O
of	O
it	O
is	O
known	O
as	O
uniform	O
cost	O
search	O
and	O
formulated	O
as	O
an	O
instance	O
of	O
the	O
more	O
general	O
idea	O
of	O
best-first	B-Algorithm
search	I-Algorithm
.	O
</s>
<s>
As	O
a	O
solution	O
,	O
he	O
re-discovered	O
the	O
algorithm	O
known	O
as	O
Prim	B-Algorithm
's	I-Algorithm
minimal	I-Algorithm
spanning	I-Algorithm
tree	I-Algorithm
algorithm	I-Algorithm
(	O
known	O
earlier	O
to	O
Jarník	O
,	O
and	O
also	O
rediscovered	O
by	O
Prim	O
)	O
.	O
</s>
<s>
Let	O
the	O
distance	O
of	O
node	O
Y	O
be	O
the	O
distance	O
from	O
the	O
initial	O
node	O
to	O
Y	O
.	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
will	O
initially	O
start	O
with	O
infinite	O
distances	O
and	O
will	O
try	O
to	O
improve	O
them	O
step	O
by	O
step	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
current	O
node	O
A	B-Application
is	I-Application
marked	O
with	O
a	O
distance	O
of	O
6	O
,	O
and	O
the	O
edge	O
connecting	O
it	O
with	O
a	O
neighbor	O
B	O
has	O
length	O
2	O
,	O
then	O
the	O
distance	O
to	O
B	O
through	O
A	O
will	O
be	O
6	O
+	O
2	O
=	O
8	O
.	O
</s>
<s>
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
initially	O
marks	O
the	O
distance	O
(	O
from	O
the	O
starting	O
point	O
)	O
to	O
every	O
other	O
intersection	O
on	O
the	O
map	O
with	O
infinity	O
.	O
</s>
<s>
In	O
the	O
following	O
pseudocode	B-Language
algorithm	O
,	O
is	O
an	O
array	O
that	O
contains	O
the	O
current	O
distances	O
from	O
the	O
to	O
other	O
vertices	O
,	O
i.e.	O
</s>
<s>
1	O
function	O
Dijkstra(Graph, source )	O
:	O
</s>
<s>
3	O
for	O
each	O
vertex	O
v	O
in	O
Graph.Vertices	O
:	O
</s>
<s>
When	O
the	O
algorithm	O
completes	O
,	O
data	O
structure	O
will	O
actually	O
describe	O
a	O
graph	B-Application
that	O
is	O
a	O
subset	O
of	O
the	O
original	O
graph	B-Application
with	O
some	O
edges	O
removed	O
.	O
</s>
<s>
Its	O
key	O
property	O
will	O
be	O
that	O
if	O
the	O
algorithm	O
was	O
run	O
with	O
some	O
starting	O
node	O
,	O
then	O
every	O
path	O
from	O
that	O
node	O
to	O
any	O
other	O
node	O
in	O
the	O
new	O
graph	B-Application
will	O
be	O
the	O
shortest	O
path	O
between	O
those	O
nodes	O
in	O
the	O
original	O
graph	B-Application
,	O
and	O
all	O
paths	O
of	O
that	O
length	O
from	O
the	O
original	O
graph	B-Application
will	O
be	O
present	O
in	O
the	O
new	O
graph	B-Application
.	O
</s>
<s>
Then	O
to	O
actually	O
find	O
all	O
these	O
shortest	O
paths	O
between	O
two	O
given	O
nodes	O
we	O
would	O
use	O
a	O
path	O
finding	O
algorithm	O
on	O
the	O
new	O
graph	B-Application
,	O
such	O
as	O
depth-first	B-Algorithm
search	I-Algorithm
.	O
</s>
<s>
A	O
min-priority	B-Application
queue	I-Application
is	O
an	O
abstract	O
data	O
type	O
that	O
provides	O
3	O
basic	O
operations	O
:	O
,	O
and	O
.	O
</s>
<s>
Notably	O
,	O
Fibonacci	B-Application
heap	I-Application
or	O
Brodal	B-Application
queue	I-Application
offer	O
optimal	O
implementations	O
for	O
those	O
3	O
operations	O
.	O
</s>
<s>
As	O
the	O
algorithm	O
is	O
slightly	O
different	O
,	O
it	O
is	O
mentioned	O
here	O
,	O
in	O
pseudocode	B-Language
as	O
well	O
:	O
</s>
<s>
1	O
function	O
Dijkstra(Graph, source )	O
:	O
</s>
<s>
6	O
for	O
each	O
vertex	O
v	O
in	O
Graph.Vertices	O
:	O
</s>
<s>
Instead	O
of	O
filling	O
the	O
priority	B-Application
queue	I-Application
with	O
all	O
nodes	O
in	O
the	O
initialization	O
phase	O
,	O
it	O
is	O
also	O
possible	O
to	O
initialize	O
it	O
to	O
contain	O
only	O
source	O
;	O
then	O
,	O
inside	O
the	O
if	O
alt	O
<	O
dist[v]	O
block	O
,	O
the	O
becomes	O
an	O
operation	O
if	O
the	O
node	O
is	O
not	O
already	O
in	O
the	O
queue	O
.	O
</s>
<s>
Yet	O
another	O
alternative	O
is	O
to	O
add	O
nodes	O
unconditionally	O
to	O
the	O
priority	B-Application
queue	I-Application
and	O
to	O
instead	O
check	O
after	O
extraction	O
that	O
it	O
is	O
n't	O
revisiting	O
,	O
or	O
that	O
no	O
shorter	O
connection	O
was	O
found	O
yet	O
.	O
</s>
<s>
These	O
alternatives	O
can	O
use	O
entirely	O
array-based	O
priority	B-Application
queues	I-Application
without	O
decrease-key	O
functionality	O
,	O
which	O
have	O
been	O
found	O
to	O
achieve	O
even	O
faster	O
computing	O
times	O
in	O
practice	O
.	O
</s>
<s>
Proof	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
constructed	O
by	O
induction	O
on	O
the	O
number	O
of	O
visited	O
nodes	O
.	O
</s>
<s>
Bounds	O
of	O
the	O
running	O
time	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
on	O
a	O
graph	B-Application
with	O
edges	O
and	O
vertices	O
can	O
be	O
expressed	O
as	O
a	O
function	O
of	O
the	O
number	O
of	O
edges	O
,	O
denoted	O
,	O
and	O
the	O
number	O
of	O
vertices	O
,	O
denoted	O
,	O
using	O
big-O	O
notation	O
.	O
</s>
<s>
In	O
the	O
following	O
,	O
upper	O
bounds	O
can	O
be	O
simplified	O
because	O
is	O
for	O
any	O
graph	B-Application
,	O
but	O
that	O
simplification	O
disregards	O
the	O
fact	O
that	O
in	O
some	O
problems	O
,	O
other	O
upper	O
bounds	O
on	O
may	O
hold	O
.	O
</s>
<s>
The	O
simplest	O
version	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
stores	O
the	O
vertex	O
set	O
as	O
a	O
linked	O
list	O
or	O
array	O
,	O
and	O
edges	O
as	O
an	O
adjacency	B-Data_Structure
list	I-Data_Structure
or	O
matrix	B-Algorithm
.	O
</s>
<s>
For	O
sparse	O
graphs	O
,	O
that	O
is	O
,	O
graphs	O
with	O
far	O
fewer	O
than	O
edges	O
,	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
implemented	O
more	O
efficiently	O
by	O
storing	O
the	O
graph	B-Application
in	O
the	O
form	O
of	O
adjacency	B-Data_Structure
lists	I-Data_Structure
and	O
using	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
,	O
binary	B-Application
heap	I-Application
,	O
pairing	B-Application
heap	I-Application
,	O
or	O
Fibonacci	B-Application
heap	I-Application
as	O
a	O
priority	B-Application
queue	I-Application
to	O
implement	O
extracting	O
minimum	O
efficiently	O
.	O
</s>
<s>
To	O
perform	O
decrease-key	O
steps	O
in	O
a	O
binary	B-Application
heap	I-Application
efficiently	O
,	O
it	O
is	O
necessary	O
to	O
use	O
an	O
auxiliary	O
data	O
structure	O
that	O
maps	O
each	O
vertex	O
to	O
its	O
position	O
in	O
the	O
heap	B-Application
,	O
and	O
to	O
keep	O
this	O
structure	O
up	O
to	O
date	O
as	O
the	O
priority	B-Application
queue	I-Application
changes	O
.	O
</s>
<s>
time	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
(	O
where	O
denotes	O
the	O
binary	O
logarithm	O
)	O
;	O
for	O
connected	O
graphs	O
this	O
time	O
bound	O
can	O
be	O
simplified	O
to	O
.	O
</s>
<s>
In	O
common	O
presentations	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
initially	O
all	O
nodes	O
are	O
entered	O
into	O
the	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
This	O
is	O
,	O
however	O
,	O
not	O
necessary	O
:	O
the	O
algorithm	O
can	O
start	O
with	O
a	O
priority	B-Application
queue	I-Application
that	O
contains	O
only	O
one	O
item	O
,	O
and	O
insert	O
new	O
items	O
as	O
they	O
are	O
discovered	O
(	O
instead	O
of	O
doing	O
a	O
decrease-key	O
,	O
check	O
whether	O
the	O
key	O
is	O
in	O
the	O
queue	O
;	O
if	O
it	O
is	O
,	O
decrease	O
its	O
key	O
,	O
otherwise	O
insert	O
it	O
)	O
.	O
</s>
<s>
This	O
variant	O
has	O
the	O
same	O
worst-case	B-General_Concept
bounds	O
as	O
the	O
common	O
variant	O
,	O
but	O
maintains	O
a	O
smaller	O
priority	B-Application
queue	I-Application
in	O
practice	O
,	O
speeding	O
up	O
the	O
queue	O
operations	O
.	O
</s>
<s>
Moreover	O
,	O
not	O
inserting	O
all	O
nodes	O
in	O
a	O
graph	B-Application
makes	O
it	O
possible	O
to	O
extend	O
the	O
algorithm	O
to	O
find	O
the	O
shortest	O
path	O
from	O
a	O
single	O
source	O
to	O
the	O
closest	O
of	O
a	O
set	O
of	O
target	O
nodes	O
on	O
infinite	O
graphs	O
or	O
those	O
too	O
large	O
to	O
represent	O
in	O
memory	O
.	O
</s>
<s>
The	O
complexity	O
of	O
this	O
algorithm	O
can	O
be	O
expressed	O
in	O
an	O
alternative	O
way	O
for	O
very	O
large	O
graphs	O
:	O
when	O
is	O
the	O
length	O
of	O
the	O
shortest	O
path	O
from	O
the	O
start	O
node	O
to	O
any	O
node	O
satisfying	O
the	O
"	O
goal	O
"	O
predicate	O
,	O
each	O
edge	O
has	O
cost	O
at	O
least	O
,	O
and	O
the	O
number	O
of	O
neighbors	O
per	O
node	O
is	O
bounded	O
by	O
,	O
then	O
the	O
algorithm	O
's	O
worst-case	B-General_Concept
time	O
and	O
space	O
complexity	O
are	O
both	O
in	O
.	O
</s>
<s>
Further	O
optimizations	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
for	O
the	O
single-target	O
case	O
include	O
bidirectional	B-Algorithm
variants	O
,	O
goal-directed	O
variants	O
such	O
as	O
the	O
A*	B-Protocol
algorithm	I-Protocol
(	O
see	O
)	O
,	O
graph	B-Application
pruning	O
to	O
determine	O
which	O
nodes	O
are	O
likely	O
to	O
form	O
the	O
middle	O
segment	O
of	O
shortest	O
paths	O
(	O
reach-based	O
routing	O
)	O
,	O
and	O
hierarchical	O
decompositions	O
of	O
the	O
input	O
graph	B-Application
that	O
reduce	O
routing	O
to	O
connecting	O
and	O
to	O
their	O
respective	O
"	O
transit	B-Protocol
nodes	I-Protocol
"	O
followed	O
by	O
shortest-path	O
computation	O
between	O
these	O
transit	B-Protocol
nodes	I-Protocol
using	O
a	O
"	O
highway	O
"	O
.	O
</s>
<s>
When	O
arc	O
weights	O
are	O
small	O
integers	O
(	O
bounded	O
by	O
a	O
parameter	O
)	O
,	O
specialized	O
queues	O
which	O
take	O
advantage	O
of	O
this	O
fact	O
can	O
be	O
used	O
to	O
speed	O
up	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
first	O
algorithm	O
of	O
this	O
type	O
was	O
Dial	O
's	O
algorithm	O
for	O
graphs	O
with	O
positive	O
integer	O
edge	O
weights	O
,	O
which	O
uses	O
a	O
bucket	B-Application
queue	I-Application
to	O
obtain	O
a	O
running	O
time	O
.	O
</s>
<s>
The	O
use	O
of	O
a	O
Van	B-Application
Emde	I-Application
Boas	I-Application
tree	I-Application
as	O
the	O
priority	B-Application
queue	I-Application
brings	O
the	O
complexity	O
to	O
.	O
</s>
<s>
Another	O
interesting	O
variant	O
based	O
on	O
a	O
combination	O
of	O
a	O
new	O
radix	B-Application
heap	I-Application
and	O
the	O
well-known	O
Fibonacci	B-Application
heap	I-Application
runs	O
in	O
time	O
.	O
</s>
<s>
A	O
single	O
edge	O
appearing	O
in	O
the	O
optimal	O
solution	O
is	O
removed	O
from	O
the	O
graph	B-Application
,	O
and	O
the	O
optimum	O
solution	O
to	O
this	O
new	O
graph	B-Application
is	O
calculated	O
.	O
</s>
<s>
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
usually	O
the	O
working	O
principle	O
behind	O
link-state	B-Protocol
routing	I-Protocol
protocols	I-Protocol
,	O
OSPF	B-Protocol
and	O
IS-IS	B-Protocol
being	O
the	O
most	O
common	O
ones	O
.	O
</s>
<s>
Unlike	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
the	O
Bellman	B-Algorithm
–	I-Algorithm
Ford	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
used	O
on	O
graphs	O
with	O
negative	O
edge	O
weights	O
,	O
as	O
long	O
as	O
the	O
graph	B-Application
contains	O
no	O
negative	O
cycle	O
reachable	O
from	O
the	O
source	O
vertex	O
s	O
.	O
The	O
presence	O
of	O
such	O
cycles	O
means	O
there	O
is	O
no	O
shortest	O
path	O
,	O
since	O
the	O
total	O
weight	O
becomes	O
lower	O
each	O
time	O
the	O
cycle	O
is	O
traversed	O
.	O
</s>
<s>
In	O
graph	B-Application
theory	O
that	O
is	O
normally	O
not	O
allowed	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
adapt	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
to	O
handle	O
negative	O
weight	O
edges	O
by	O
combining	O
it	O
with	O
the	O
Bellman-Ford	B-Algorithm
algorithm	I-Algorithm
(	O
to	O
remove	O
negative	O
edges	O
and	O
detect	O
negative	O
cycles	O
)	O
;	O
such	O
an	O
algorithm	O
is	O
called	O
Johnson	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
A*	B-Protocol
algorithm	I-Protocol
is	O
a	O
generalization	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
that	O
cuts	O
down	O
on	O
the	O
size	O
of	O
the	O
subgraph	O
that	O
must	O
be	O
explored	O
,	O
if	O
additional	O
information	O
is	O
available	O
that	O
provides	O
a	O
lower	O
bound	O
on	O
the	O
"	O
distance	O
"	O
to	O
the	O
target	O
.	O
</s>
<s>
The	O
process	O
that	O
underlies	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
similar	O
to	O
the	O
greedy	B-Algorithm
process	O
used	O
in	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Prim	O
's	O
purpose	O
is	O
to	O
find	O
a	O
minimum	O
spanning	O
tree	O
that	O
connects	O
all	O
nodes	O
in	O
the	O
graph	B-Application
;	O
Dijkstra	O
is	O
concerned	O
with	O
only	O
two	O
nodes	O
.	O
</s>
<s>
Breadth-first	B-Algorithm
search	I-Algorithm
can	O
be	O
viewed	O
as	O
a	O
special-case	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
on	O
unweighted	O
graphs	O
,	O
where	O
the	O
priority	B-Application
queue	I-Application
degenerates	O
into	O
a	O
FIFO	O
queue	O
.	O
</s>
<s>
The	O
fast	B-Algorithm
marching	I-Algorithm
method	I-Algorithm
can	O
be	O
viewed	O
as	O
a	O
continuous	O
version	O
of	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
which	O
computes	O
the	O
geodesic	O
distance	O
on	O
a	O
triangle	O
mesh	O
.	O
</s>
<s>
From	O
a	O
dynamic	B-Algorithm
programming	I-Algorithm
point	O
of	O
view	O
,	O
Dijkstra	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
a	O
successive	O
approximation	O
scheme	O
that	O
solves	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
functional	O
equation	O
for	O
the	O
shortest	O
path	O
problem	O
by	O
the	O
Reaching	O
method	O
.	O
</s>
<s>
Least-cost	B-Application
paths	I-Application
are	O
calculated	O
for	O
instance	O
to	O
establish	O
tracks	O
of	O
electricity	O
lines	O
or	O
oil	O
pipelines	O
.	O
</s>
