Question: 1 . Please write the c language code . Write a Program to compute the Minimum spanning tree of a connected undirected graph G using

1. Please write the c language code . Write a Program to compute the Minimum spanning tree of a connected undirected graph G using
Prims algorithm . Print the sequence with which edges are picked by algorithm and total edge
weight of spanning tree. The goal is to implement the following functions:
(a) Sequence(x) : Print sequence in which edges will be picked if x is starting node.
(b) Total weight() : Print total cost of the minimum spanning tree.
Input format:
First line contains an integer n in [1,1000], that denotes the number of vertices in the graph.
The subsequent n lines contain an Adjacency matrix of size (n * n). If two nodes are directly
connected by an edge, it is denoted by a positive integer in the matrix; else it is denoted by
0. The positive integer corresponds to the weight on the edge. Assume that all edge weights
will be distinct.
Each line of input is a character from the menu list [s,t,x].
Input s calls the function Sequence(x).
Input t calls the function Total weight().
Input x terminates the execution of the program.
All the inputs in a line are separated by space.
Output format:
Line contains an integer representation of the total edge weight of the spanning tree or , Line
contains sequence of integer representing sequence of edges.
Sample Input 1:
6
020370
201080
010405
304006
780000
005600
t
s(1)
x
Sample Output 1:
18
1210032504
Sample Input 2:
5
01500
10200
52036
00304
00640
t
s(1)
x
Sample Output 2:
10
10102334

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!