ds10
ds10
EXPERIMENT ASSESSMENT
Roll Number: 19
Date of Submission:18/10/2024
Evaluation
Performance Indicator Max. Marks Marks Obtained
Performance 5
Understanding 5
Journal work and timely submission. 10
Total 20
Performance Indicator Exceed Expectations (EE) Meet Expectations (ME) Below Expectations (BE)
Performance 5 3 2
Understanding 5 3 2
Journal work and timely
10 8 4
submission.
Checked by
Experiment No. 10: Depth First Search and Breath First Search
Aim : Implementation of DFS and BFS traversal of graph.
Objective:
1. Understand the Graph data structure and its basic operations.
2. Understand the method of representing a graph.
3. Understand the method of constructing the Graph ADT and defining its operations
Theory:
A graph is a collection of nodes or vertices, connected in pairs by lines referred to as
edges. A graph can be directed or undirected.
One method of traversing through nodes is depth first search. Here we traverse from
the starting node and proceed from top to bottom. At a moment we reach a dead end from
where the further movement is not possible and we backtrack and then proceed according to
left right order. A stack is used to keep track of a visited node which helps in backtracking.
DFS Traversal –0 1 2 3 4
Algorithm
Algorithm: DFS_LL(V)
Input: V is a starting vertex
Output : A list VISIT giving order of visited vertices during traversal.
Description: linked structure of graph with gptr as pointer
1. if gptr = NULL then
print “Graph is empty” exit
2. u=v
3. OPEN.PUSH(u)
4. while OPEN.TOP !=NULL do
u=OPEN.POP()
if search(VISIT,u) = FALSE then
Vidyavardhini’s College of Engineering & Technology
K.T. MARG, VASAI ROAD (WEST)
Department of Computer Science and Engineering(Data Science)
INSERT_END(VISIT,u)
Ptr = gptr(u)
While ptr.LINK != NULL do
Vptr = ptr.LINK
OPEN.PUSH(vptr.LABEL)
End while
End if
End while
5. Return VISIT
6. Stop
BFS Traversal
BFS Traversal – 0 1 4 2 3
Algorithm
Algorithm: DFS()
i=0
count=1
visited[i]=1
print("Visited vertex i")
push(j)
}
i=pop()
print("Visited vertex i")
visited[i]=1
count++
Algorithm: BFS()
i=0
count=1
visited[i]=1
print("Visited vertex i")
i=dequeue()
print("Visited vertex i")
visited[i]=1
count++
Code:
#include <stdio.h>
#define MAX 10
Vidyavardhini’s College of Engineering & Technology
K.T. MARG, VASAI ROAD (WEST)
Department of Computer Science and Engineering(Data Science)
int main() {
int adj[MAX][MAX], i, j;
Vidyavardhini’s College of Engineering & Technology
K.T. MARG, VASAI ROAD (WEST)
Department of Computer Science and Engineering(Data Science)
scanf("%d", &adj[i][j]);
return 0;
Output:
Vidyavardhini’s College of Engineering & Technology
K.T. MARG, VASAI ROAD (WEST)
Department of Computer Science and Engineering(Data Science)
Conclusion:
Write the graph representation used by your program and explain why you choose that.
Write the applications of BFS and DFS other than finding connected nodes and explain how
it is attained?
Vidyavardhini’s College of Engineering & Technology
K.T. MARG, VASAI ROAD (WEST)
Department of Computer Science and Engineering(Data Science)