Prim's Algorithm Prim's Algorithm proceeds very much like the shortest-path
algorithm. There is a set IN, which initially
contains one arbitrary node. For every node Z
not in IN, we keep track of the shortest distance from Z
and any node in IN. We successively add nodes to IN
moving to the nearest adjacent node.
The example at right begins with nine (9) nodes and their
arcs along with arc lengths. The end result will be tree
that connects each node using the shortest distance.
|
|
Kruskal's Kruskal's algorithm
is an alternative method for generating a minimal
spanning tree. It works by building up a spanning tree
from the arcs, ordered from smallest in weight to
largest. The only reason to reject a smaller arc over a
larger is if it creates a cycle.
The example at right begins with nine (9) nodes without
their arcs along with arc lengths. The end result will
be a tree that connects each node using the shortest distance.
We start by grouping the arcs together according to their
length, then connecting the arcs until all nodes have
incorporated into a connected structure.The
only restriction is that an arc is not added if adding it
will cause a cycle.
|
|
Arc Lengths |
Arc Groupings |
1: |
(1,3)(3,4)(5,7)(8,9) |
2: |
(1,2)(2,5)(3,5)(7,8)(7,9) |
3: |
(2,4)(4,6)(6,7) |
4: |
(4,5) |
|
|
|
|