问题
Prim’s Algorithm
An algorithm for finding a minimum spanning tree.
- Begin by choosing any edge with smallest weight, putting it into the spanning tree.
- Successively add to the tree edges of minimum weight that are incident to a vertex already in the tree, never forming a simple circuit with those edges already in the tree.
- Stop when n − 1 edges have been added.
I know that you must start at node A. Also by giving a list of the order in which nodes and/or edges are added.
But im not sure on the exact steps to find the minimum weight spanning tree.
回答1:
Select all unvisited edges from A
A - B = 2
A - E = 2
A - F = 5
Find cheapest : A - B
Select all unvisited edges from A and B
A - E = 2
A - F = 5
B - C = 1
B - E = 2
B - F = 4
Find cheapest : B - C
Select all unvisited edges from A, B and C
A - E = 2
A - F = 5
B - E = 2
B - F = 4
C - D = 4
C - E = 1
Find cheapest : C - E
Select all unvisited edges from A, B, C and E
A - E = 2
A - F = 5
B - E = 2
B - F = 4
C - D = 4
E - D = 3
E - F = 1
Find cheapest : E - F
Node D is the only unvisited node, so it can either be; D -E OR C - D.
Cheapest = E - D : 3
Now all nodes have been visited, remove unused edges
Minimum weight spanning tree would look like this
来源:https://stackoverflow.com/questions/43811258/how-to-find-a-minimum-weight-spanning-tree-for-the-following-graph-using-prims-a