Search code examples
algorithmminimum-spanning-tree

about cut in minimum spanning tree


I am reading about minimum spanning trees algorithms. It is mentioned about cut. A cut (S, V-S) of an undirected graph G = (V, E) is a parition of V. An edge is a light edge crossing a cut if its weight is the minimum of any edge crossing the cut.

How above definitions is used in Kruskal's and Prims algorithms?

I am not getting how cut is used in Kruskals and Prim's algorithms

Thanks


Solution

  • In Prim's algorithm, first a vertex(any) is chosen. Now, cut such that, that the chosen vertex belongs to S and rest are V-S. Now, you chose the lightest weight edge and add the connecting vertex to S. And, you continue doing it till all the vertices are in S.

    In Kruskal's algorithm, you keep adding the minimum weight edge in the graph to the set S. You can cut the graph in any manner, but if that cut passes through the minimum weight edge, then that edge will be the lightest edge. And, it has to be added to the minimum spanning tree (provided that it connects two different trees).

    I hope that helps.