SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
PRESENTED BY
D.ANANDHASILAMBARASAN
KIT - CBE
GRAPH TRAVERSALS IN DATA STRUCTURE
GRAPH TRAVERSALS
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.
There are two graph traversal techniques and they are as follows...
 BFS (breadth first search)
 DFS (depth first search)
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 becomes empty, then produce final spanning tree by removing
unused edges from the graph.
Graph traversals in Data Structures
Graph traversals in Data Structures
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 steps 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 to 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 steps 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.
Graph traversals in Data Structures
Graph traversals in Data Structures
Graph traversals in Data Structures

More Related Content

What's hot (20)

PPTX
Data structure - Graph
Madhu Bala
 
PPTX
Priority Queue in Data Structure
Meghaj Mallick
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PPTX
Doubly Linked List
Ninad Mankar
 
PPTX
DFS and BFS
satya parsana
 
PPT
1.1 binary tree
Krish_ver2
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
PPTX
Threaded Binary Tree
khabbab_h
 
PPTX
Circular link list.ppt
Tirthika Bandi
 
PPTX
Linked list
KalaivaniKS1
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPT
Lec 17 heap data structure
Sajid Marwat
 
PPTX
Terminology of tree
RacksaviR
 
PPTX
Dfs presentation
Alizay Khan
 
PPTX
linked list in data structure
shameen khan
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
PPTX
Linked list
akshat360
 
PPTX
Stack and Queue
Apurbo Datta
 
PPTX
Graph coloring using backtracking
shashidharPapishetty
 
Data structure - Graph
Madhu Bala
 
Priority Queue in Data Structure
Meghaj Mallick
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
Doubly Linked List
Ninad Mankar
 
DFS and BFS
satya parsana
 
1.1 binary tree
Krish_ver2
 
Binary Tree Traversal
Dhrumil Panchal
 
Threaded Binary Tree
khabbab_h
 
Circular link list.ppt
Tirthika Bandi
 
Linked list
KalaivaniKS1
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Lec 17 heap data structure
Sajid Marwat
 
Terminology of tree
RacksaviR
 
Dfs presentation
Alizay Khan
 
linked list in data structure
shameen khan
 
heap Sort Algorithm
Lemia Algmri
 
Linked list
akshat360
 
Stack and Queue
Apurbo Datta
 
Graph coloring using backtracking
shashidharPapishetty
 

Similar to Graph traversals in Data Structures (20)

PDF
graphtraversals.pdf
SeethaDinesh
 
PPTX
DFS_New.pptx
sandeep54552
 
PPTX
Graphs
KomalPaliwal3
 
PDF
Breadth First Search and Depth First Search Algorithm
YashpreetKalra
 
PPTX
Breadth First Search or BFS for a Graph traversal
jeevanasujitha
 
PPTX
breadth first search
DeepikaT13
 
PPTX
BFS & DFS in Data Structure
Meghaj Mallick
 
PPTX
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
PPTX
Breath first Search and Depth first search
Kirti Verma
 
PPTX
Data structure note
Muhammad Nawaz
 
PPTX
Understanding Graph Traversal Algorithms A Deep Dive into BFS and DFS
Mahmud Hasan Tanvir
 
PPTX
BFS and DFS transversal algorithmsanshdh
DivyanshGupta505488
 
PPTX
Data structure
lalithambiga kamaraj
 
PPTX
Bfs new
sandeep54552
 
PPTX
Bfs new
sandeep54552
 
PPTX
DS - Graph Traversal
MythiliMurugan3
 
PPTX
CS8391-Data Structures Unit 4
SIMONTHOMAS S
 
PPTX
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
PPTX
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
PPTX
Depth First Search (DFS) AI future ppt.pptx
anjanaelectronicspvt
 
graphtraversals.pdf
SeethaDinesh
 
DFS_New.pptx
sandeep54552
 
Breadth First Search and Depth First Search Algorithm
YashpreetKalra
 
Breadth First Search or BFS for a Graph traversal
jeevanasujitha
 
breadth first search
DeepikaT13
 
BFS & DFS in Data Structure
Meghaj Mallick
 
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Breath first Search and Depth first search
Kirti Verma
 
Data structure note
Muhammad Nawaz
 
Understanding Graph Traversal Algorithms A Deep Dive into BFS and DFS
Mahmud Hasan Tanvir
 
BFS and DFS transversal algorithmsanshdh
DivyanshGupta505488
 
Data structure
lalithambiga kamaraj
 
Bfs new
sandeep54552
 
Bfs new
sandeep54552
 
DS - Graph Traversal
MythiliMurugan3
 
CS8391-Data Structures Unit 4
SIMONTHOMAS S
 
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Depth First Search (DFS) AI future ppt.pptx
anjanaelectronicspvt
 
Ad

Recently uploaded (20)

PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Ad

Graph traversals in Data Structures

  • 1. PRESENTED BY D.ANANDHASILAMBARASAN KIT - CBE GRAPH TRAVERSALS IN DATA STRUCTURE
  • 2. GRAPH TRAVERSALS 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. There are two graph traversal techniques and they are as follows...  BFS (breadth first search)  DFS (depth first search)
  • 3. 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.
  • 4. 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 becomes empty, then produce final spanning tree by removing unused edges from the graph.
  • 7. 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 steps 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.
  • 8. 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 to 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 steps 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.