BFS-Binary First Search
BFS-Binary First Search
RAGUL SINGH(1806037)
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
int a[10][10],q[10],visited[10],n,i,j,f=0,r=-1;
voidbfs(int v)
{
for (i=1;i<=n;i++)
if(a[v][i] && !visited[i])
q[++r]=i;
if(f<=r)
{
visited[q[f]]=1;
bfs(q[f++]);
}
}
void main()
{
int v;
clrscr();
printf("\n Enter the number of vertices:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
q[i]=0;
visited[i]=0;
}
D.RAGUL SINGH(1806037)
OUTPUT :
Enter the number of vertices: 2
Enter graph data in matrix form: 1 2 2 3
Enter the starting vertex: 1
The node which are reachable are: 1 2
D.RAGUL SINGH(1806037)
RESULT :
The program to perform Breadth-wise search has been successfully
implemented and the output is verified .