2. Content Layout List
• Minimal Spanning Tree
• Prim’s Algorithm
• Example
• Algorithm
• Analysis
• Complexity
3. Minimum Spanning Tree?
• A spanning tree is a subset of Graph G, which has all the vertices
covered with minimum possible number of edges.
• Hence, a spanning tree does not have cycles and it cannot be
disconnected.
4. Prim’s Algorithm
• Prim's algorithm is a greedy algorithm that finds a minimum spanning
tree for a weighted undirected graph.
• The algorithm was developed in 1930.
5. Algorithm
1. Prim(G,W)
2. VT = {v}
3. ET ={ ø }
4. For i=1 to |v|-1
5. Select an edge with minimum weight
6. e*=(u*,v*),such that u*€ VT & V* € V-VT, such
that inclusion of that edge does not forms a
cycle.
7. VT = VT U{V*}
8. ET = ET U{e*}
9. return ET
13. Analysis
T(V,E) = C+(V-1)[log E +C]
Complexity
T(V,E) € (V.log E)
1. Prim(G,W)
2. VT = { ø v} ------------------------------- C
3. ET ={ ø } ----------------------------------C
4. For i=1 to |v|-1 -----------------------(V-1)
5. { Select an edge with minimum weight
6. e*=(u*,v*),such that u*€ VT & V* € V-VT, such that
inclusion of that edge does not forms a cycle. } ---
------------------------------(log E)
7. VT = VT U{V*} -------------------------C
8. ET = ET U{e*} ---------------------------C
9. return ET --------------------------------------------- C