11.prims and kruskals algorithm

1

Click here to load reader

Upload: prabhu

Post on 08-Apr-2015

373 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 11.Prims and Kruskals Algorithm

DATA STRUCTURES AND ALGORITHMS LABORATORY (EE2209)

Staff Name : M. SARITHA Class : II Year EEE

Designation : AP Semester : III Sem ‘A’ Sec

Ex. No. 11: Implementation of Prim's and Kruskal's Algorithm

Find the minimum spanning tree for a given weighted undirected graph using Prim's andKruskal's algorithm.

For Prim's algorithm, get the number of vertices of the graph and represent the graph usingadjacency matrix. Display the adjacency matrix representation of the graph and also display all thetables consisting of three pieces of information namely known, Pv, Dv for all the vertices after visitingeach and every vertex. Finally display the edges in the spanning tree and the total cost.

For Kruskal's algorithm, get the number of vertices of the graph and represent the graph usingadjacency matrix. Display the adjacency matrix representation of the graph and the edges with theincreasing cost. Finally display the accepted edges of the minimum spanning tree and the total cost.

All the operations should be implemented as user-defined functions. Define the structure anduser-defined functions in a header file and define the main function in C file.

Test cases:

For Prim's Algorithm For Kruskal's Algorithm