Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class

Similar presentations


Presentation on theme: "Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class"— Presentation transcript:

1 Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class
There are Slight Changes From the Code These Slides are not Complete

2 Example – MST (Prim’s Algorithm)
Assume a connected graph has nodes labeled by some identifying letter or number, arcs which are non-directional and have positive weights associated with them. The MST problem is to find a minimum spanning tree.

3 Representing a Non-directed Graph - 2 PEs Needed for Each Edge Yellow is memory for PE10.
TAIL HEAD WEIGHT STATE XX NXTNODE GRAPH 1 a b 2 3 c 4 5 e f 6 7 8 9 10

4 We will maintain three sets of nodes whose membership will change during the run.
2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 V1 will be nodes selected to be in the tree. V2 will be candidates at the current step to be added to V1. V3 will be nodes not considered yet.

5 Colors Used in Graphic Visualization
V1 nodes and their selected edges will be in red. V2 nodes with their candidate edges will be in blue. V3 nodes and all other edges will remain white.

6 Select an arbitrary node to place in V1, say A
Select an arbitrary node to place in V1, say A. Put into V2, all nodes adjacent to A. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Look at the code presented. Is the first node picked this way? Is there any problem?

7 Choose the blue edge with the smallest weight, AB, and put its other node, B, into V1. Mark that edge with red also. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 If an edge is selected, throw out its reverse edge, i.e. put B  A in V0.

8 Add all the edges incident to B to the candidate list. .
2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Note that AG has weight 3 and BG has weight 6. So, there is no sense of including BG in V2. But, in associative computing, there is no harm in doing so.

9 Add the node, G, whose edge has the smallest weight that is colored blue and add it to V1.Color A  G red. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Throw out blue edges that could form a cycle – i.e. edges whose head or tail is G and blue ( as well as their reverse edges).

10 Add the node, G, whose edge has the smallest weight that is colored blue and add it to V1.Color A  G red. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Throw out blue edges that could form a cycle – i.e. edges whose head or tail is G and blue ( as well as their reverse edges). 

11 Throw out BG and GB 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 After creating more slides interacting with the class, we have the final solution.

12 The final solution after 8 iterations total.
2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 The subgraph is clearly a tree – no cycles and connected. The tree spans – i.e. all nodes are included. While not obvious, it can be shown that this algorithm always produces a minimal spanning tree. The algorithm is known as Prim’s Algorithm for MST.


Download ppt "Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class"

Similar presentations


Ads by Google