nextupprevious
Next:8.4 Traveling Salesman ProblemUp:8.3 Minimum-Cost Spanning TreesPrevious:8.3.2 Prim's Algorithm

8.3.3 Kruskal's Algorithm

REF.
J.B. Kruskal. On the shortest spanning subtree of a graph and the traveling salesman problem. Proceedings of the American Mathematical Society, Volume 7, pp. 48-50, 1956.


void kruskal (vertex-set V; edge-set E; edge-set T)

     int ncomp; /* current number of components */

    priority-queue edges /* partially ordered tree */

    mfset components; /* merge-find set data structure */

    vertex u, v; edge e;

    int nextcomp; /* name for new component */

    int ucomp, vcomp; /* component names */

        {

            makenull (T); makenull (edges);

            nextcomp = 0; ncomp = n;

            for (v$ \in$V) /* initialize a component to have one vertex of V*/

            { nextcomp++ ;

                initial (nextcomp, v, components);

            }

        for (e$ \in$E)

            insert (e, edges); /* initialize priority queue of edges */

                while (ncomp > 1)

            {

            e = deletemin (edges);

            let e = (u, v);

            ucomp = find(u, components);

            vcomp = find(v, components);

            if (ucomp! = vcomp)

                {

                merge (ucomp, vcomp, components);

                ncomp = ncomp - 1;

                }

            }

    }


Implementation

Running Time of Kruskal's Algorithm Example: See Figure 8.13.

E = {(1,3), (4,6), (2,5), (3,6), (3,4), (1,4), (2,3), (1,2), (3,5), (5,6) }


nextupprevious
Next:8.4 Traveling Salesman ProblemUp:8.3 Minimum-Cost Spanning TreesPrevious:8.3.2 Prim's Algorithm
eEL,CSA_Dept,IISc,Bangalore