0% found this document useful (0 votes)
6K views10 pages

CCN Lab Manual TE VTU

The document describes an algorithm to find the minimum spanning tree of a graph using Prim's algorithm. It defines a class with methods to read in the graph cost matrix, run Prim's algorithm from a source vertex to find the minimum spanning tree cost, and display the edges of the minimum spanning tree. Prim's algorithm uses a cost array to track the minimum cost from the source to each unvisited vertex, and iteratively adds the lowest cost edge connecting an unvisited vertex to grow the spanning tree until all vertices are included.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6K views10 pages

CCN Lab Manual TE VTU

The document describes an algorithm to find the minimum spanning tree of a graph using Prim's algorithm. It defines a class with methods to read in the graph cost matrix, run Prim's algorithm from a source vertex to find the minimum spanning tree cost, and display the edges of the minimum spanning tree. Prim's algorithm uses a cost array to track the minimum cost from the source to each unvisited vertex, and iteratively adds the lowest cost edge connecting an unvisited vertex to grow the spanning tree until all vertices are included.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

!

"# $%%

&'
(
) *+
+
, !"#-+
, !"#-+
, !"#-+

.%+

&/ &%0 1 $0 2' 3 /'+


&/4 /) '+

. +
*. +

5 & 6.73%7'
(
& ..7%7'
(
*. +
*88+
88+
9

(
5 & ..7$7 11 6.:'
(
88+
*. +
*88+
88+
9

& ..:'
(
*.7%7+
*88+
9
.%+
9
9
*.73%7+
&/3 /'+
&/3 4 /) '+

. +
*. +

! " # $ % & % % '


5 & 6.73%7'
(
& ..7%7'
(
*. +
*88+
88+
9

(
5 & ..7$7 11 6.:'
(
88+
*. +
*88+
88+
9
& ..:'
(
88+
9
.%+
9
9
*.73%7+
&/3 /'+
&/3 4 3 /) '+
%+
9

&%0 1 $0 2'
$%$%$$$$$$

$%$%$$$$$%$

$%$%$$$$$$

! " # $ % & % % (
& 5 ; ; 2 < 2'

!"# $%%
&'
(
, !"#-) , !"#-) , !"#-+
) *+
+

&/ 3 /'+
&/4 /) '+
. +
*. +
5 & 6.73%7'
(
& ..7 7'
(
*. +
88+
*88+
& ..7 7'
(
*. +
88+
*88+
& ..7 7'
(
*. +
88+
*88+
&*88'.7 7+
&*88'.7 7+
&*88'.7 7+
9
9
9

(
*. +
*88+
88+
9
9

*.73%7+
&/3 /'+
&/3 4 /) '+

. +
*. +

! " # $ % & % % )
5 & 6.73%7'
(
& ..7 7'
(
*. +
88+
*88+
& ..7 7'
(
*. +
88+
*88+
& ..7 7'
(
*. +
88+
*88+

& .$+ .=+ 88'


88+

9
9
9

(
*. +
*88+
88+
9
9
*.73%7+
&/3 /'+
&/3 4 3 /) '+
%+
9

! " # $ % & % % *
# 2 2

#include <stdio.h>
#include <string.h>

void encrypt(char str[],int key)


{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] - key;
}
}

void decrypt(char str[],int key)


{
unsigned int i;
for(i=0;i<strlen(str);++i)
{
str[i] = str[i] + key;
}
}
int main()
{
char str[] = "smurffANDkdo";
printf("Passwrod = %s\n",str);
encrypt(str,0xFACA);
printf("Encrypted value = %s\n",str);
decrypt(str,0xFACA);
printf("Decrypted value = %s\n",str);
return 0;
}

! " # $ % & % % +
#include<stdio.h>
#include<conio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;

clrscr();

printf("enter the cost matrix\n");


for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);

printf("enter number of paths\n");


scanf("%d",&p);

printf("enter possible paths\n");


for(i=1;i<=p;i++)
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);

for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;

for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];

if(edp==ed)
break;
else
stp=edp;
}
}

min=t[st];
index=st;

for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}

printf("minimum cost %d",min);

! " # $ % & % % ,
printf("\n minimum cost path ");

for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}

getch();
}

/*OUTPUT:
enter the cost matrix :
0 1 4 2 0
0 0 0 2 3
0 0 0 3 0
0 0 0 0 5
0 0 0 0 0
enter number of paths : 4
enter possible paths :
1 2 4 5 0
1 2 5 0 0
1 4 5 0 0
1 3 4 5 0
minimum cost : 4
minimum cost path :
1–>2–>5*/

! " # $ % & % %
#include<iostream.h>

#define MAX 10

class prims
{
private : int cost[MAX][MAX], tree[MAX][MAX];
int n;
public : void readmatrix();
int spanningtree(int);
void display(int);
};

void prims :: readmatrix()


{
int i, j;
cout << "\nEnter the number of vertices in the Graph : ";
cin >> n;
cout << "\nEnter the Cost matrix of the Graph\n\n";
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
cin >> cost[i][j];
}

int prims :: spanningtree(int src)


{
int visited[MAX], d[MAX], parent[MAX];
int i, j, k, min, u, v, stcost;
for (i = 1; i <= n; i++)
{
d[i] = cost[src][i];
visited[i] = 0;
parent[i] = src;
}
visited[src] = 1;
stcost = 0;
k = 1;
for (i = 1; i < n; i++)
{
min = 999;
for (j = 1; j <= n; j++)
{
if (!visited[j] && d[j] < min)
{
min = d[j];
u = j;
}
}
visited[u] = 1;
stcost = stcost + d[u];
tree[k][1] = parent[u];
tree[k++][2] = u;

! " # $ % & % % -
for (v = 1; v <= n; v++)
if (!visited[v] && (cost[u][v] < d[v]))
{
d[v] = cost[u][v];
parent[v] = u;
}
}
return (stcost);
}

void prims :: display(int cost)


{
int i;
cout << "\nThe Edges of the Mininum Spanning Tree are\n\n";
for (i = 1; i < n; i++)
cout << tree[i][1] << " " << tree[i][2] << endl;
cout << "\nThe Total cost of the Minimum Spanning Tree is : " << cost;
}

int main()
{
int source, treecost;
prims pri;
pri.readmatrix();
cout << "\nEnter the Source : ";
cin >> source;
treecost = pri.spanningtree(source);
pri.display(treecost);
return 0;
}

! " # $ % & % % .
>?>@>>!AA

#include <stdio.h>

int crc_1021(int data)


{
int crc;
int x;

x = ((crc >> 8) ^ data) & 0xff;


x ^= x>>4;
crc = (crc << 8) ^ (x << 12) ^ (x <<5) ^ x;
crc &= 0xffff;

return(crc);

int main()

{
int crc;
printf("The CRC16-X25_ccitt of %d is %d. \n", crc, crc_1021(crc));
return 0;
}

! " # $ % & % % '/

You might also like