a)Prim算法,何为prim算法,只需要理解一点,让连通图中的所有边的权值变为最小,而且要包括连通图中的所有顶点
For example this graph, you should run prim's algorithm on the following weighted graph.
Draw a table showing the intermediate values of all the nodes in the priority queue at each iteration of the algorithm
first, choos a as a start node, so a-b is 2
a-c 4
c-d 1
c-e 2
e-f 1
e-i 3
f-g 4
d-h 4
Total weight is 19
which is the concept of prim algorithm
b)Kruskal算法
which is similar to Prim algorithm, it also need to get the minimum total weight
but its progress is different
first, get the minimum edges between two nodes, like c and d, like e and f
so ,c-d 1 and e-f 1
then, c-e 2, a-b 2
and, d-f 3, i-e 3
last, a-c 4, h-d 4, f-g 4
c)Bellman-Ford算法
it is also similar to other algorithms
from a to b,c,d
first, a-b 2 a-c 4 a-d 6
second, a-c-d 5 < 6, so it can occur, and a-c-e 6
third, a-c-e-i 10, a-c-d-h 9, a-c-e-f 7
forth, a-c-e-f-g 11