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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值