(15) What is the difference in Kruskal's and Prim's algorithm? - Quora
The basic difference is in which edge you choose to add next to the spanning tree in each step.In Prim's, you always keep a connected component, starting with a single vertex. You look at all edges from the current component to other vertices and find the smallest among them. You then add the neighbouring vertex to the component, increasing its size by 1. In N-1 steps, every vertex would be merged to the current one if we have a connected graph.
In Kruskal's, you do not keep one connected component but a forest. At each stage, you look at the globally smallest edge that does not create a cycle in the current forest. Such an edge has to necessarily merge two trees in the current forest into one. Since you start with N single-vertex trees, in N-1 steps, they would all have merged into one if the graph was connected.
Read full article from (15) What is the difference in Kruskal's and Prim's algorithm? - Quora
No comments:
Post a Comment