0% found this document useful (0 votes)
21 views9 pages

Ad. Algo

Uploaded by

h2bjprzcfs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

Ad. Algo

Uploaded by

h2bjprzcfs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Global Institute of Management &

Technology (GIMT)

Topic : GRAPH TRAVERSAL ALGORITHMS


BY ARPITA BISWAS
DEPT : CSE, YEAR : 3rd, SEMESTER : 6th
REG NO. : 2590100110002 OF 2020-21
ROLL. NO. : 25900120014
SUBJECT : ADVANCED ALGORITHM
SUB CODE : PEC-IT601A
CONTENTS :
 INTRODUCTION

 GRAPH TRAVERSAL

 BFS(BREADTH FIRST SEARCH )

 DFS(DEPTH FIRST SEARCH)

 COMPARISON BETWEEN TWO METHODS OF GRAPH TRAVERSAL


INTRODUCTION :
Graph : A graph is a non-linear data structure, which is represented by
vertices(nodes) and edges. Every pair of vertices is connected with one edge
between them. Graph has many real-life applications, which we can see in our
day-to-day life. For example, graphs are used widely in networking area, like
social media networks, telephone networks, etc., where a single user can be
represented as a node and the relationship between the users can be
represented as edges.
Types of Graph :
Graphs can be classified into two types:
 Undirected Graph: A graph in which the edges do not have any directions
associated with them, is known as an undirected graph.
 Directed Graph: A graph in which the edges have a particular direction
associated with them, is known as a directed graph.
In simple words, traversal means the process of visiting every node in the
graph. Graph traversal is technique used for searching a vertex in a graph. The
graph traversal is also used to decide the order of vertices to be visit in the search
process.

A graph traversal finds the edges to be used in the search process without creating
loops that means using graph traversal we visit all vertices of graph without getting
into looping path.

Graph Traversal : There are 2 standard methods of graph traversal Breadth-First Search and Depth
First Search .
 Breadth First Search(BFS) :
Breadth-First Search (BFS) is a graph traversal algorithm, where we start from a
selected(source) node and traverse the graph level by level, by exploring the
neighbor nodes at each level.
 Depth First Search(DFS) :
Depth First Search (DFS) is a graph traversal algorithm, where we start from a
selected(source) node and go into the depth of this node by recursively calling
the DFS function until no children are encountered. When the dead-end is reached,
this algorithm backtracks and starts visiting the other children of the current node.
BFS(Breadth First Search ) :
 BFS traversal of a graph, produces a spanning tree as final result.
 Spanning tree is a graph without any loops.
 We use queue data structure with maximum size of total number of vertices in the graph to
implement BFS traversal of a graph.

We use the following steps to implement BFS traversal……….


Step 1 : Define a queue of size total number of vertices in the graph
Step 2 : Select any vertex as starting point for traversal. Visit that vertex and insert it into the
queue.
Step 3 : Visit all the adjacent vertices of the vertex which is at front of the queue which is not
visited and insert them into the queue.
Step 4 : When there is no new vertex to be visit from the vertex at front of the queue then delete
that vertex from the queue.
Step 5 : Repeat step 3 and 4 until queue becomes empty.
Step 6 : When queue become empty, then produce final spanning tree by removing unused edges
from the graph.
DFS(Depth First Search) :
DFS traversal of a graph, produces a spanning tree as final result. Spanning Tree is a graph without any loops.
We use stack data structure with maximum size of total number of vertices in the graph to implement DFS traversal of
a graph.

We use the following step to implement DFS traversal……………


Step 1: Define a stack of size total number of vertices in the graph .
Step 2 : Select any vertex as starting point for traversal. Visit that vertex and push it on to the stack.
Step 3 : Visit any one of the adjacent vertex of the vertex which is at top of the stack which is not visited and push it
on the stack.
Step 4 : Repeat step 3 until there are no new vertex to be visit from the vertex on top of the stack.
Step 5 : When there is no new vertex to be visit then use back tracking and pop one vertex from the stack
Step 6 : Repeat step 3,4 and 5 until stack becomes empty.
Step 7 : When Stack becomes empty , then produce final spanning tree by removing unused – edges from the graph.
Back Tracking is coming back to the vertex from which we came to current vertex.
Comparison between two methods of Graph Traversal :
Breadth First Search(BFS) Depth First Search(DFS)
1. https://www.tutorialspoint.com/graphs-and-its
-traversal-algorithms
2. https://opendsa-server.cs.vt.edu/ODSA/Books/
CS3/html/GraphTraversal.html
3. https://www.geeksforgeeks.org/graph-data-str
ucture-and-algorithms/
4. https://www.geeksforgeeks.org/depth-first-sea
rch-or-dfs-for-a-graph/

Reference : 5. https://www.scaler.com/topics/graph-traversal
-in-data-structures/
6. https://en.wikipedia.org/wiki/Graph_traversal
7. https://www.javatpoint.com/breadth-first-sear
ch-algorithm
8. https://www.javatpoint.com/graph-algorithms
9. http://www.btechsmartclass.com/data_structu
res/graph-traversal-bfs.html
10. https://images.app.goo.gl/1eaXpRPryZ7z6Evf9
11. https://images.app.goo.gl/8WL2XaZyMY47fgpb
7
THANK YOU

You might also like