<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
(	O
also	O
known	O
as	O
Jarník	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
)	O
is	O
a	O
greedy	B-Algorithm
algorithm	I-Algorithm
that	O
finds	O
a	O
minimum	O
spanning	O
tree	O
for	O
a	O
weighted	O
undirected	O
graph	O
.	O
</s>
<s>
The	O
algorithm	O
was	O
developed	O
in	O
1930	O
by	O
Czech	O
mathematician	O
Vojtěch	O
Jarník	O
and	O
later	O
rediscovered	O
and	O
republished	O
by	O
computer	B-General_Concept
scientists	I-General_Concept
Robert	O
C	O
.	O
Prim	O
in	O
1957	O
and	O
Edsger	O
W	O
.	O
Dijkstra	O
in	O
1959	O
.	O
</s>
<s>
or	O
the	O
DJP	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Other	O
well-known	O
algorithms	O
for	O
this	O
problem	O
include	O
Kruskal	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
and	O
Borůvka	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
These	O
algorithms	O
find	O
the	O
minimum	O
spanning	O
forest	O
in	O
a	O
possibly	O
disconnected	O
graph	O
;	O
in	O
contrast	O
,	O
the	O
most	O
basic	O
form	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
only	O
finds	O
minimum	O
spanning	O
trees	O
in	O
connected	O
graphs	O
.	O
</s>
<s>
However	O
,	O
running	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
separately	O
for	O
each	O
connected	O
component	O
of	O
the	O
graph	O
,	O
it	O
can	O
also	O
be	O
used	O
to	O
find	O
the	O
minimum	O
spanning	O
forest	O
.	O
</s>
<s>
However	O
,	O
for	O
graphs	O
that	O
are	O
sufficiently	O
dense	O
,	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
made	O
to	O
run	O
in	O
linear	O
time	O
,	O
meeting	O
or	O
improving	O
the	O
time	O
bounds	O
for	O
other	O
algorithms	O
.	O
</s>
<s>
In	O
more	O
detail	O
,	O
it	O
may	O
be	O
implemented	O
following	O
the	O
pseudocode	B-Language
below	O
.	O
</s>
<s>
Different	O
variations	O
of	O
the	O
algorithm	O
differ	O
from	O
each	O
other	O
in	O
how	O
the	O
set	O
Q	O
is	O
implemented	O
:	O
as	O
a	O
simple	O
linked	B-Data_Structure
list	I-Data_Structure
or	O
array	B-Data_Structure
of	O
vertices	O
,	O
or	O
as	O
a	O
more	O
complicated	O
priority	B-Application
queue	I-Application
data	O
structure	O
.	O
</s>
<s>
In	O
general	O
,	O
a	O
priority	B-Application
queue	I-Application
will	O
be	O
quicker	O
at	O
finding	O
the	O
vertex	O
v	O
with	O
minimum	O
cost	O
,	O
but	O
will	O
entail	O
more	O
expensive	O
updates	O
when	O
the	O
value	O
of	O
C[w]	O
changes	O
.	O
</s>
<s>
The	O
time	O
complexity	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
depends	O
on	O
the	O
data	O
structures	O
used	O
for	O
the	O
graph	O
and	O
for	O
ordering	O
the	O
edges	O
by	O
weight	O
,	O
which	O
can	O
be	O
done	O
using	O
a	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
A	O
simple	O
implementation	O
of	O
Prim	O
's	O
,	O
using	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
or	O
an	O
adjacency	B-Data_Structure
list	I-Data_Structure
graph	O
representation	O
and	O
linearly	O
searching	O
an	O
array	B-Data_Structure
of	O
weights	O
to	O
find	O
the	O
minimum	O
weight	O
edge	O
to	O
add	O
,	O
requires	O
O( |V|2	O
)	O
running	O
time	O
.	O
</s>
<s>
However	O
,	O
this	O
running	O
time	O
can	O
be	O
greatly	O
improved	O
further	O
by	O
using	O
heaps	B-Application
to	O
implement	O
finding	O
minimum	O
weight	O
edges	O
in	O
the	O
algorithm	O
's	O
inner	O
loop	O
.	O
</s>
<s>
A	O
first	O
improved	O
version	O
uses	O
a	O
heap	B-Application
to	O
store	O
all	O
edges	O
of	O
the	O
input	O
graph	O
,	O
ordered	O
by	O
their	O
weight	O
.	O
</s>
<s>
The	O
heap	B-Application
should	O
order	O
the	O
vertices	O
by	O
the	O
smallest	O
edge-weight	O
that	O
connects	O
them	O
to	O
any	O
vertex	O
in	O
the	O
partially	O
constructed	O
minimum	O
spanning	O
tree	O
(	O
MST	O
)	O
(	O
or	O
infinity	O
if	O
no	O
such	O
edge	O
exists	O
)	O
.	O
</s>
<s>
Using	O
a	O
simple	O
binary	B-Application
heap	I-Application
data	O
structure	O
,	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
now	O
be	O
shown	O
to	O
run	O
in	O
time	O
O( |E|	O
log	O
|V|	O
)	O
where	O
|E|	O
is	O
the	O
number	O
of	O
edges	O
and	O
|V|	O
is	O
the	O
number	O
of	O
vertices	O
.	O
</s>
<s>
Using	O
a	O
more	O
sophisticated	O
Fibonacci	B-Application
heap	I-Application
,	O
this	O
can	O
be	O
brought	O
down	O
to	O
O( |E|	O
+	O
|V|	O
log	O
|V|	O
)	O
,	O
which	O
is	O
asymptotically	O
faster	O
when	O
the	O
graph	O
is	O
dense	O
enough	O
that	O
|E|	O
is	O
ω( |V|	O
)	O
,	O
and	O
linear	O
time	O
when	O
|E|	O
is	O
at	O
least	O
|V|log|V|	O
.	O
</s>
<s>
For	O
graphs	O
of	O
even	O
greater	O
density	O
(	O
having	O
at	O
least	O
|V|c	O
edges	O
for	O
some	O
c>1	O
)	O
,	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
made	O
to	O
run	O
in	O
linear	O
time	O
even	O
more	O
simply	O
,	O
by	O
using	O
a	O
d-ary	B-Application
heap	I-Application
in	O
place	O
of	O
a	O
Fibonacci	B-Application
heap	I-Application
.	O
</s>
<s>
At	O
every	O
iteration	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
an	O
edge	O
must	O
be	O
found	O
that	O
connects	O
a	O
vertex	O
in	O
a	O
subgraph	O
to	O
a	O
vertex	O
outside	O
the	O
subgraph	O
.	O
</s>
<s>
The	O
output	O
Y	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
a	O
tree	O
,	O
because	O
the	O
edge	O
and	O
vertex	O
added	O
to	O
tree	O
Y	O
are	O
connected	O
.	O
</s>
<s>
The	O
main	O
loop	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
inherently	O
sequential	O
and	O
thus	O
not	O
parallelizable	B-Operating_System
.	O
</s>
<s>
The	O
following	O
pseudocode	B-Language
demonstrates	O
this	O
.	O
</s>
<s>
The	O
running	O
time	O
is	O
,	O
assuming	O
that	O
the	O
reduce	O
and	O
broadcast	B-Operating_System
operations	O
can	O
be	O
performed	O
in	O
.	O
</s>
<s>
A	O
variant	O
of	O
Prim	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
for	O
shared	O
memory	O
machines	O
,	O
in	O
which	O
Prim	O
's	O
sequential	O
algorithm	O
is	O
being	O
run	O
in	O
parallel	O
,	O
starting	O
from	O
different	O
vertices	O
,	O
has	O
also	O
been	O
explored	O
.	O
</s>
<s>
It	O
should	O
,	O
however	O
,	O
be	O
noted	O
that	O
more	O
sophisticated	O
algorithms	O
exist	O
to	O
solve	O
the	O
distributed	B-Operating_System
minimum	I-Operating_System
spanning	I-Operating_System
tree	I-Operating_System
problem	O
in	O
a	O
more	O
efficient	O
manner	O
.	O
</s>
