ADA演算法知識(三) Prim演算法、Kruskal演算法、Bellman-Ford演算法
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