Professional Documents
Culture Documents
Assignment 2 dfs
Assignment 2 dfs
ALGORITHM:
INPUT:- Entering the number of vertices in the graph,the adjacency matrix of the
graph and the starting vertex for the BFS traversal.
OUTPUT:- Getting the order of vertices visited during the BFS traversal.
PROCESS:-
Step 1: start.
Step 3: initialize the adjacency matrix graph[7][7] according to the input graph .
Visited[i]=1
Step 8.1: check if graph[i][j] is true and node j is not visited i.e,
[END OF IF ]
[END OF LOOP]
Step 12 : End
SOURCE CODE :
#include<stdio.h>
#include<stdlib.h>
int visited[7];
int graph[7][7]={
{0,1,1,1,0,0,0}
,{1,0,1,0,0,0,1}
,{1,1,0,1,0,1,0}
,{1,0,1,0,1,0,0}
,{0,0,0,1,0,0,0}
,{0,0,1,0,0,0,1}
,{0,1,0,0,0,1,0}
};
void DFS(int i)
printf("%d ",i);
visited[i]=1;
int j;
for(j=0;j<7;j++)
DFS(j);
}
}
int main()
int c;
scanf("%d",&c);
DFS(c);
return 0;
OUTPUT:
1. enter your starting node - 0
traversal result is :0 1 2 3 4 5 6