Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MinSpanTree(G) uses Kruskal s Algorithm to find and return the edges of the minimum spanning tree of graph G. typedef struct { Vertex v; Vertex

MinSpanTree(G) uses Kruskals Algorithm to find and return the edges of the minimum spanning tree of graph G.

typedef struct {

Vertex v; Vertex w; int weight;

} Edge;

Edge *MinSpanTree( Graph G )

{ Edge e, *GraphEdges, *TreeEdges;

DisjSet S;

PriorityQueue H;

SetType w_set, v_set;

N = NumOfVex( G );

S = CreateDisjSet( N ); /* create disjoint set S */

GraphEdges = GetEdges(G); /* get all edges of graph G */

TreeEdges = malloc( sizeof(Edge) * N );

H = BuildHeap( GraphEdges, N ); /* build min heap H from the edges of graph G */

edges_accepted = 0;

while (edges_accepted < N-1 ) {

if (IsEmpty( H )) {

free( TreeEdges );

TreeEdges = NULL;

break;

}

e = ______(1)______;

v_set = ______(2)______;

w_set = ______(3)______;

if( w_set != v_set ) {

TreeEdges[edges_accepted++] = e;

________(4)_______;

}

}

free( GraphEdges );

DestroyHeap( H );

DestroyDisjSet( S );

return TreeEdges;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

=+ Who is the negotiation partner at company level?

Answered: 1 week ago

Question

=+Which associations exist?

Answered: 1 week ago