SlideShare a Scribd company logo
BY:
Kirti Verma
AP, CSE
LNCTE
 Introduction
 Types of graph Traversal
 Depth-First Search
 Breadth-First Search
 Application of BFS and DFS
Graph traversal is also known as graph search
refers to the process of visiting each vertex in a graph.
Such traversals are classified by the order in which
the vertices are visited. Tree traversal is a special
case of graph traversal.
• Depth-first search (DFS) is an algorithm for traversing
or searching tree or graph data structures.
• DFS uses stack.
• If at any vertex, it encounters that all the adjacent
vertices are visited, then it backtracks until it finds the
first vertex having an adjacent vertex that has not
been traversed before.
• Then, it traverses that vertex, continues with its
adjacent vertices until it traverses all visited vertices
and has to backtrack again.
The concept is to visit all the neighbor vertices of a neighbor
vertex before visiting the other neighbor vertices.
 Initialize status of all nodes as “Ready”
 Put source vertex in a stack and change its status to “Waiting”
 Repeat the following two steps until stack is empty −
◦ Pop the top vertex from the stack and mark it as “Visited”
◦ Push onto the top of the stack all neighbors of the removed
vertex whose status is “Ready”. Mark their status as
“Waiting”.
 Initialize status of all vertices to “Ready”.
 Push a in stack and change its status to “Waiting”.
 Pop a and mark it as “Visited”.
 Push a’s neighbors in “Ready” state e, d and b to top of stack and
mark them as “Waiting”.
 Pop b from stack, mark it as “Visited”, push its “Ready”
neighbor c onto stack.
 Pop c from stack and mark it as “Visited”. It has no “Ready”
neighbor.
 Pop d from stack and mark it as “Visited”. It has no “Ready”
neighbor.
 Pop e from stack and mark it as “Visited”. It has no “Ready”
neighbor.
 Stack is empty. So stop.
 The alternate orders of traversal are −
 a → e → b → c → d
 Or, a → b → e → c → d
 Or, a → d → e → b → c
 Or, a → d → c → e → b
 Or, a → d → c → b → e
// recursive, preorder
void dfs (Node v) {
if (v == null)
return;
if (v not yet visited)
visit&mark(v); // visit node before adjacent nodes
for (each w adjacent to v)
if (w has not yet been visited)
dfs(w);
} // dfs
0
7
1
5
4
3
2
6
Policy: Visit adjacent nodes in increasing index order
0
7
1
5
4
3
2
6
5 1 0 3 2 7 6 4
0
7
1
5
4
3
2
6
5
Push 5
0
7
1
5
4
3
2
6
Pop/Visit/Mark5
5
0
7
1
5
4
3
2
6
1
2
5
Push 2, Push 1
0
7
1
5
4
3
2
6
2
Pop/Visit/Mark1
5 1
0
7
1
5
4
3
2
6
0
4
2
5 1
Push 4, Push 0
0
7
1
5
4
3
2
6
4
2
5 1 0
Pop/Visit/Mark0
0
7
1
5
4
3
2
6
3
7
4
2
Push 7, Push 3
5 1 0
0
7
1
5
4
3
2
6
7
4
2
5 1 0 3
Pop/Visit/Mark3
0
7
1
5
4
3
2
6
7
4
2
5 1 0 3
2 is already instack
0
7
1
5
4
3
2
6
7
4
2
Pop/Mark/Visit7
5 1 0 3 7
0
7
1
5
4
3
2
6
6
4
2
5 1 0 3 7
Push 6
0
7
1
5
4
3
2
6
4
2
5 1 0 3 7 6
Pop/Mark/Visit6
0
7
1
5
4
3
2
6
2
Pop/Mark/Visit4
5 1 0 3 7 6 4
0
7
1
5
4
3
2
6
Pop/Mark/Visit2
5 1 0 3 7 6 4 2
0
7
1
5
4
3
2
6
Done
5 1 0 3 7 6 4 2
Breadth-first search (BFS) is an algorithm for
traversing or searching tree or graph data structures.
It uses queue.
 The concept is to visit all the neighbor vertices
before visiting other neighbor vertices of
neighbor vertices.
 Initialize status of all nodes as “Ready”.
 Put source vertex in a queue and change its
status to “Waiting”.
 Repeat the following two steps until queue is
empty −
◦ Remove the first vertex from the queue and mark it as
“Visited”.
◦ Add to the rear of queue all neighbors of the removed
vertex whose status is “Ready”. Mark their status as
“Waiting”.
 Initialize status of all vertices to “Ready”.
 Put a in queue and change its status to “Waiting”.
 Remove a from queue, mark it as “Visited”.
 Add a’s neighbors in “Ready” state b, d and e to end of queue and mark
them as “Waiting”.
 Remove b from queue, mark it as “Visited”, put its “Ready”
neighbor c at end of queue and mark c as “Waiting”.
 Remove d from queue and mark it as “Visited”. It has no neighbor in
“Ready” state.
 Remove e from queue and mark it as “Visited”. It has no neighbor in
“Ready” state.
 Remove c from queue and mark it as “Visited”. It has no neighbor in
“Ready” state.
 Queue is empty so stop.
So the traversal order is −
 a → b → d → e → c
 The alternate orders of traversal are −
 a → b → e → d → c
 Or, a → d → b → e → c
 Or, a → e → b → d → c
 Or, a → b → e → d → c
 Or, a → d → e → b → c
 // non-recursive, preorder, breadth-first search
void bfs (Node v) {
 if (v == null)
return;
 enqueue(v);
 while (queue is not empty) {
dequeue(v);
 if (v has not yet been visited)
mark&visit(v);
 for (each w adjacent to v)
 if (w has not yet been visited && has not been queued)
enqueue(w);
 } // while
 } // bfs
7
1
5
4
3
2
6
0
7
1
5
4
3
2
6
0
5
7
1
5
4
3
2
6
0
5
5 1 2
7
1
5
4
3
2
6
0
5 1
0
5 1 2 4
7
1
5
4
3
2
6
0
5 1 2
0
5 1 2 4
7
1
5
4
3
2
6
0
5 1 2 0
0
5 1 2 4 3 7
7
1
5
4
3
2
6
0
5 1 2 0 4
0
5 1 2 4 3 7
7
1
5
4
3
2
6
0
5 1 2 0 4 3
5 1 2 0 4 3 7
7
1
5
4
3
2
6
0
5 1 2 0 4 3 7
5 1 2 0 4 3 7 6
7
1
5
4
3
2
6
0
5 1 2 0 4 3 7 6
5 1 2 0 4 3 7 6
7
1
5
4
3
2
6
5 1 2 0 4 3 7 6
0
•
•
•
Computing Distances
Checking for cycles in a graph
Reachability: Given a graph G and vertices x and y, determine if there
exists a path from x to y.
• Checking for Biconnected Graph: A graph is biconnected if removal of
any vertex does not affect connectivity of the other vertices. Used to
test if network is robust to failure of certain nodes. A single DFS
traversal algorithm.

More Related Content

Similar to Breath first Search and Depth first search

Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
Umme habiba
 
Lecture 16 graphs traversal
Lecture 16 graphs traversalLecture 16 graphs traversal
Lecture 16 graphs traversal
Abirami A
 
Graphs
GraphsGraphs
Graph Traversals
Graph TraversalsGraph Traversals
Graph Traversals
MaryJacob24
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
satya parsana
 
Unit 4.2(graphs)
Unit 4.2(graphs)Unit 4.2(graphs)
Unit 4.2(graphs)
DurgaDeviCbit
 
Algorithm
AlgorithmAlgorithm
Algorithm
Shakil Ahmed
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
SigSegVSquad
 
Lec7
Lec7Lec7
Lec7
Lec7Lec7
articulation points in graph
articulation points in grapharticulation points in graph
articulation points in graph
Savit Chandra
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
zukun
 
Graphs
GraphsGraphs
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
bhuvaneshwariA5
 
Analysis and design of algorithms part 3
Analysis and design of algorithms part 3Analysis and design of algorithms part 3
Analysis and design of algorithms part 3
Deepak John
 
kumattt).pptx
kumattt).pptxkumattt).pptx
kumattt).pptx
gurukhade1
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
Ketaki_Pattani
 
2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
Krish_ver2
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
Dakshitha Dissanayaka
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
almario1988
 

Similar to Breath first Search and Depth first search (20)

Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
 
Lecture 16 graphs traversal
Lecture 16 graphs traversalLecture 16 graphs traversal
Lecture 16 graphs traversal
 
Graphs
GraphsGraphs
Graphs
 
Graph Traversals
Graph TraversalsGraph Traversals
Graph Traversals
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Unit 4.2(graphs)
Unit 4.2(graphs)Unit 4.2(graphs)
Unit 4.2(graphs)
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
Lec7
Lec7Lec7
Lec7
 
Lec7
Lec7Lec7
Lec7
 
articulation points in graph
articulation points in grapharticulation points in graph
articulation points in graph
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
 
Graphs
GraphsGraphs
Graphs
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
 
Analysis and design of algorithms part 3
Analysis and design of algorithms part 3Analysis and design of algorithms part 3
Analysis and design of algorithms part 3
 
kumattt).pptx
kumattt).pptxkumattt).pptx
kumattt).pptx
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
 
2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 

More from Kirti Verma

L-5 BCEProcess management.ppt
L-5 BCEProcess management.pptL-5 BCEProcess management.ppt
L-5 BCEProcess management.ppt
Kirti Verma
 
L-3 BCE OS FINAL.ppt
L-3 BCE OS FINAL.pptL-3 BCE OS FINAL.ppt
L-3 BCE OS FINAL.ppt
Kirti Verma
 
L-4 BCE Generations of Computers final.ppt
L-4 BCE Generations of Computers final.pptL-4 BCE Generations of Computers final.ppt
L-4 BCE Generations of Computers final.ppt
Kirti Verma
 
L-1 BCE computer fundamentals final kirti.ppt
L-1 BCE computer fundamentals final kirti.pptL-1 BCE computer fundamentals final kirti.ppt
L-1 BCE computer fundamentals final kirti.ppt
Kirti Verma
 
BCE L-4 Data Type In C++.ppt
BCE L-4 Data Type In C++.pptBCE L-4 Data Type In C++.ppt
BCE L-4 Data Type In C++.ppt
Kirti Verma
 
BCE L-3 overview of C++.ppt
BCE L-3 overview of C++.pptBCE L-3 overview of C++.ppt
BCE L-3 overview of C++.ppt
Kirti Verma
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Kirti Verma
 
BCE L-1 Programmimg languages.pptx
BCE L-1  Programmimg languages.pptxBCE L-1  Programmimg languages.pptx
BCE L-1 Programmimg languages.pptx
Kirti Verma
 
BCE L-1 networking fundamentals 111.pptx
BCE L-1  networking fundamentals 111.pptxBCE L-1  networking fundamentals 111.pptx
BCE L-1 networking fundamentals 111.pptx
Kirti Verma
 
BCE L-2 e commerce.pptx
BCE L-2 e commerce.pptxBCE L-2 e commerce.pptx
BCE L-2 e commerce.pptx
Kirti Verma
 
BCE L-3omputer security Basics.pptx
BCE L-3omputer security Basics.pptxBCE L-3omputer security Basics.pptx
BCE L-3omputer security Basics.pptx
Kirti Verma
 
L 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxL 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptx
Kirti Verma
 
L 2 Introduction to Data science final kirti.pptx
L 2 Introduction to Data science final kirti.pptxL 2 Introduction to Data science final kirti.pptx
L 2 Introduction to Data science final kirti.pptx
Kirti Verma
 
Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
Kirti Verma
 
L 8 introduction to machine learning final kirti.pptx
L 8 introduction to machine learning final kirti.pptxL 8 introduction to machine learning final kirti.pptx
L 8 introduction to machine learning final kirti.pptx
Kirti Verma
 
L 6.1 complete scikit libraray.pptx
L 6.1 complete scikit libraray.pptxL 6.1 complete scikit libraray.pptx
L 6.1 complete scikit libraray.pptx
Kirti Verma
 
L 7Complete Machine learning.pptx
L 7Complete Machine learning.pptxL 7Complete Machine learning.pptx
L 7Complete Machine learning.pptx
Kirti Verma
 
Introduction to python history and platforms
Introduction to python history and platformsIntroduction to python history and platforms
Introduction to python history and platforms
Kirti Verma
 
Informed Search Techniques new kirti L 8.pptx
Informed Search Techniques new kirti L 8.pptxInformed Search Techniques new kirti L 8.pptx
Informed Search Techniques new kirti L 8.pptx
Kirti Verma
 
Production System l 10.pptx
Production System l 10.pptxProduction System l 10.pptx
Production System l 10.pptx
Kirti Verma
 

More from Kirti Verma (20)

L-5 BCEProcess management.ppt
L-5 BCEProcess management.pptL-5 BCEProcess management.ppt
L-5 BCEProcess management.ppt
 
L-3 BCE OS FINAL.ppt
L-3 BCE OS FINAL.pptL-3 BCE OS FINAL.ppt
L-3 BCE OS FINAL.ppt
 
L-4 BCE Generations of Computers final.ppt
L-4 BCE Generations of Computers final.pptL-4 BCE Generations of Computers final.ppt
L-4 BCE Generations of Computers final.ppt
 
L-1 BCE computer fundamentals final kirti.ppt
L-1 BCE computer fundamentals final kirti.pptL-1 BCE computer fundamentals final kirti.ppt
L-1 BCE computer fundamentals final kirti.ppt
 
BCE L-4 Data Type In C++.ppt
BCE L-4 Data Type In C++.pptBCE L-4 Data Type In C++.ppt
BCE L-4 Data Type In C++.ppt
 
BCE L-3 overview of C++.ppt
BCE L-3 overview of C++.pptBCE L-3 overview of C++.ppt
BCE L-3 overview of C++.ppt
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
 
BCE L-1 Programmimg languages.pptx
BCE L-1  Programmimg languages.pptxBCE L-1  Programmimg languages.pptx
BCE L-1 Programmimg languages.pptx
 
BCE L-1 networking fundamentals 111.pptx
BCE L-1  networking fundamentals 111.pptxBCE L-1  networking fundamentals 111.pptx
BCE L-1 networking fundamentals 111.pptx
 
BCE L-2 e commerce.pptx
BCE L-2 e commerce.pptxBCE L-2 e commerce.pptx
BCE L-2 e commerce.pptx
 
BCE L-3omputer security Basics.pptx
BCE L-3omputer security Basics.pptxBCE L-3omputer security Basics.pptx
BCE L-3omputer security Basics.pptx
 
L 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxL 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptx
 
L 2 Introduction to Data science final kirti.pptx
L 2 Introduction to Data science final kirti.pptxL 2 Introduction to Data science final kirti.pptx
L 2 Introduction to Data science final kirti.pptx
 
Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
 
L 8 introduction to machine learning final kirti.pptx
L 8 introduction to machine learning final kirti.pptxL 8 introduction to machine learning final kirti.pptx
L 8 introduction to machine learning final kirti.pptx
 
L 6.1 complete scikit libraray.pptx
L 6.1 complete scikit libraray.pptxL 6.1 complete scikit libraray.pptx
L 6.1 complete scikit libraray.pptx
 
L 7Complete Machine learning.pptx
L 7Complete Machine learning.pptxL 7Complete Machine learning.pptx
L 7Complete Machine learning.pptx
 
Introduction to python history and platforms
Introduction to python history and platformsIntroduction to python history and platforms
Introduction to python history and platforms
 
Informed Search Techniques new kirti L 8.pptx
Informed Search Techniques new kirti L 8.pptxInformed Search Techniques new kirti L 8.pptx
Informed Search Techniques new kirti L 8.pptx
 
Production System l 10.pptx
Production System l 10.pptxProduction System l 10.pptx
Production System l 10.pptx
 

Recently uploaded

Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 

Recently uploaded (20)

Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 

Breath first Search and Depth first search

  • 2.  Introduction  Types of graph Traversal  Depth-First Search  Breadth-First Search  Application of BFS and DFS
  • 3. Graph traversal is also known as graph search refers to the process of visiting each vertex in a graph. Such traversals are classified by the order in which the vertices are visited. Tree traversal is a special case of graph traversal.
  • 4. • Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. • DFS uses stack. • If at any vertex, it encounters that all the adjacent vertices are visited, then it backtracks until it finds the first vertex having an adjacent vertex that has not been traversed before. • Then, it traverses that vertex, continues with its adjacent vertices until it traverses all visited vertices and has to backtrack again.
  • 5. The concept is to visit all the neighbor vertices of a neighbor vertex before visiting the other neighbor vertices.  Initialize status of all nodes as “Ready”  Put source vertex in a stack and change its status to “Waiting”  Repeat the following two steps until stack is empty − ◦ Pop the top vertex from the stack and mark it as “Visited” ◦ Push onto the top of the stack all neighbors of the removed vertex whose status is “Ready”. Mark their status as “Waiting”.
  • 6.
  • 7.  Initialize status of all vertices to “Ready”.  Push a in stack and change its status to “Waiting”.  Pop a and mark it as “Visited”.  Push a’s neighbors in “Ready” state e, d and b to top of stack and mark them as “Waiting”.  Pop b from stack, mark it as “Visited”, push its “Ready” neighbor c onto stack.  Pop c from stack and mark it as “Visited”. It has no “Ready” neighbor.  Pop d from stack and mark it as “Visited”. It has no “Ready” neighbor.  Pop e from stack and mark it as “Visited”. It has no “Ready” neighbor.  Stack is empty. So stop.
  • 8.  The alternate orders of traversal are −  a → e → b → c → d  Or, a → b → e → c → d  Or, a → d → e → b → c  Or, a → d → c → e → b  Or, a → d → c → b → e
  • 9. // recursive, preorder void dfs (Node v) { if (v == null) return; if (v not yet visited) visit&mark(v); // visit node before adjacent nodes for (each w adjacent to v) if (w has not yet been visited) dfs(w); } // dfs
  • 10. 0 7 1 5 4 3 2 6 Policy: Visit adjacent nodes in increasing index order
  • 19. 0 7 1 5 4 3 2 6 7 4 2 5 1 0 3 Pop/Visit/Mark3
  • 20. 0 7 1 5 4 3 2 6 7 4 2 5 1 0 3 2 is already instack
  • 23. 0 7 1 5 4 3 2 6 4 2 5 1 0 3 7 6 Pop/Mark/Visit6
  • 27. Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It uses queue.
  • 28.  The concept is to visit all the neighbor vertices before visiting other neighbor vertices of neighbor vertices.  Initialize status of all nodes as “Ready”.  Put source vertex in a queue and change its status to “Waiting”.  Repeat the following two steps until queue is empty − ◦ Remove the first vertex from the queue and mark it as “Visited”. ◦ Add to the rear of queue all neighbors of the removed vertex whose status is “Ready”. Mark their status as “Waiting”.
  • 29.
  • 30.  Initialize status of all vertices to “Ready”.  Put a in queue and change its status to “Waiting”.  Remove a from queue, mark it as “Visited”.  Add a’s neighbors in “Ready” state b, d and e to end of queue and mark them as “Waiting”.  Remove b from queue, mark it as “Visited”, put its “Ready” neighbor c at end of queue and mark c as “Waiting”.  Remove d from queue and mark it as “Visited”. It has no neighbor in “Ready” state.  Remove e from queue and mark it as “Visited”. It has no neighbor in “Ready” state.  Remove c from queue and mark it as “Visited”. It has no neighbor in “Ready” state.  Queue is empty so stop. So the traversal order is −  a → b → d → e → c
  • 31.  The alternate orders of traversal are −  a → b → e → d → c  Or, a → d → b → e → c  Or, a → e → b → d → c  Or, a → b → e → d → c  Or, a → d → e → b → c
  • 32.  // non-recursive, preorder, breadth-first search void bfs (Node v) {  if (v == null) return;  enqueue(v);  while (queue is not empty) { dequeue(v);  if (v has not yet been visited) mark&visit(v);  for (each w adjacent to v)  if (w has not yet been visited && has not been queued) enqueue(w);  } // while  } // bfs
  • 38. 7 1 5 4 3 2 6 0 5 1 2 0 0 5 1 2 4 3 7
  • 39. 7 1 5 4 3 2 6 0 5 1 2 0 4 0 5 1 2 4 3 7
  • 40. 7 1 5 4 3 2 6 0 5 1 2 0 4 3 5 1 2 0 4 3 7
  • 41. 7 1 5 4 3 2 6 0 5 1 2 0 4 3 7 5 1 2 0 4 3 7 6
  • 42. 7 1 5 4 3 2 6 0 5 1 2 0 4 3 7 6 5 1 2 0 4 3 7 6
  • 43. 7 1 5 4 3 2 6 5 1 2 0 4 3 7 6 0
  • 44. • • • Computing Distances Checking for cycles in a graph Reachability: Given a graph G and vertices x and y, determine if there exists a path from x to y.
  • 45. • Checking for Biconnected Graph: A graph is biconnected if removal of any vertex does not affect connectivity of the other vertices. Used to test if network is robust to failure of certain nodes. A single DFS traversal algorithm.