Insertion Sort Program
Insertion Sort Program
int main()
int n, array[1000], c, d, t;
scanf("%d", &n);
scanf("%d", &array[c]);
d = c;
t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d--;
printf("%d\n", array[c]);
return 0;
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]= { 0 }
,min,mincost=0,cost[10][10];
void main()
clrscr();
scanf("%d",&n);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++) {
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
visited[1]=1;
printf("\n");
while(ne<n) {
for (i=1,min=999;i<=n;i++)
for (j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0) {
min=cost[i][j];
b=v=j;
if(visited[u]==0 || visited[v]==0) {
mincost+=min;
visited[b]=1;
cost[a][b]=cost[b][a]=999;
getch();
PRIM’S ALGORITHM
ABES Engineering College Sign of Faculty With Date
Roll No:………………………………Date:……………………….Page No:…………………..
Step 3: Select an edge e connecting the tree vertex and fringe vertex that has minimum weight
Step 4: Add the selected edge and the vertex to the minimum spanning tree T
[END OF LOOP]
Step 5: EXIT.
KRUSKAL’S ALGORITHM
#include<conio.h>
#include<stdlib.h>
int i,j,k,a,b,u,v,n,ne=1;
int min,mincost=0,cost[9][9],parent[9];
int find(int);
int uni(int,int);
void main()
//clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
while(ne < n)
for(i=1,min=999;i<=n;i++)
min=cost[i][j];
a=u=i;
b=v=j;
u=find(u);
v=find(v);
if(uni(u,v))
mincost +=min;
cost[a][b]=cost[b][a]=999;
getch();
int find(int i)
while(parent[i])
i=parent[i];
if(i!=j)
parent[j]=i;
return 1;
return 0;
#include<conio.h>
#define MAX 10
void main(){
int G[MAX][MAX], i, j, n, u;
// clrscr();
scanf("%d", &n);
scanf("%d", &G[i][j]);
scanf("%d", &u);
dijikstra(G,n,u);
getch();
if(G[i][j]==0)
cost[i][j]=INFINITY;
cost[i][j]=G[i][j];
for(i=0;i< n;i++)
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
distance[startnode]=0;
visited[startnode]=1;
count=1;
mindistance=INFINITY;
mindistance=distance[i];
nextnode=i;
visited[nextnode]=1;
if(!visited[i])
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
if(i!=startnode)
j=i;
do
j=pred[j];
while(j!=startnode);
DIJKSTRA’S ALGORITHM