Greedy Algorithms | Set 5 (Prim’s Minimum Spanning Tree (MST)) – Minimum Spanning Tree We have discussed Kruskal’s algorithm for Minimum Spanning Tree.
minimum spanning tree algorithm
Dijkstra’s shortest path algorithm – Greedy algorithm – Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning tree. Like Prim’s MST, we generate a SPT (shortest path tree) with given source as root.
Prim’s MST for Adjacency List Representation – Greedy algorithm – We have discussed Prim’s algorithm and implementation for adjacency matrix representation. The time complexity for the matrix representation is O(V^2).
Prim’s Minimum Spanning Tree – Greedy Algorithm – We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. It starts with an empty spanning tree the idea is to maintain two sets of vertices.
Kruskal’s Minimum Spanning Tree Algorithm-Greedy Algorithm-Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together. A single graph can have many different spanning trees