Algorithm of spanning tree 1. Implement the Kruskal's algorithm of spanning tree 2. Write comments in each line as you understand 3. Screenshots of three times output, for 5 verteces, 7 verteces, 8 verteces ============================================================= /// Implementation of Kruskal"s algorithm on Spanning Tree #include #define max 99 int k; int array[8]; int u,v; void main() { int vertex, edge =1; /// ***We initialized but didn't increment no where int i,j, p,q; int edgecost[8][8]; int min = max, totalmincost = 0; /// To find out the minimum and total of those printf("\nEnter the quantity of Verteces: "); scanf("%d", &vertex); /// 1,2 -> 0 printf("\nEnter the cost values in matrix:\n"); for(i=1; i<=vertex; i++) { printf("\n"); for(j=1; j<=vertex; j++) { printf("cost[%d][%d]: ", i,j); scanf("%d", &edgecost[i][j]); if(edgecost[i][j] == 0) edgecost[i][j] = max; } } printf("\nEdge(s) with minimum cost:"); while(edge

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Algorithm of spanning tree


1. Implement the

Kruskal's algorithm of spanning tree
2. Write comments in each line as you understand
3. Screenshots of three times output, for 5 verteces, 7 verteces, 8 verteces
=============================================================


/// Implementation of Kruskal"s algorithm on Spanning Tree


#include<stdio.h>
#define max 99


int k;
int array[8];
int u,v;


void main()
{
int vertex, edge =1; /// ***We initialized but didn't increment no where
int i,j, p,q;
int edgecost[8][8];
int min = max, totalmincost = 0; /// To find out the minimum and total of those


printf("\nEnter the quantity of Verteces: ");
scanf("%d", &vertex);
/// 1,2 -> 0


printf("\nEnter the cost values in matrix:\n");
for(i=1; i<=vertex; i++)
{
printf("\n");
for(j=1; j<=vertex; j++)
{
printf("cost[%d][%d]: ", i,j);
scanf("%d", &edgecost[i][j]);


if(edgecost[i][j] == 0)
edgecost[i][j] = max;
}
}


printf("\nEdge(s) with minimum cost:");


while(edge<vertex)
{
for(i=1, min = max; i<=vertex; i++)
{
for(j=1; j<=vertex; j++)
{
if(edgecost[i][j] < min)
{
min = edgecost[i][j];
u=i;
v=j;


p=i;
q=j;
}
}
}


u = search(u);
v = search(v);


if(combination(u,v))
{
printf("\nEdge(%d,%d) with minimum cost of %d", p,q,min);
totalmincost = totalmincost + min;


///========================================================
edge = edge +1; /// We initialized but didn't increment, was need to do it
///========================================================
}
edgecost[p][q] = edgecost[q][p] = max;

 


}


printf("\n\nTotal of minimum cost: %d", totalmincost);


printf("\n\n\n");
return 0;
}

 

 


/// 0,1,2,0,0,3,0.......
int search(int k)
{
while(array[k])
k = array[k];
return k;
}

 

 


/// comparison between vertex, edge
int combination(int u, int v)
{
if(u != v)
{
array[v] = u;
return 1;
}
return 0;


}

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY