SlideShare a Scribd company logo
1 of 33
Welcome To Our Presentation
Group Name : Quantative
 Depth First Search (DFS)
 Breadth First Search (BFS)
Topics
What is a graph?
1.Directed/Undirected
2.Weighted/Unweighted
3.Cyclic/Acyclic
A set of vertices and edges
 Breadth First Search (BFS)
Start several paths at a time, and advance in each one step at a time
The breadth-first search uses a FIFO queue.
 Depth First Search (DFS)
Once a possible path is found, continue the search until the end of the path
The Depth-first search uses a LIFO Stack.
Graph Traversal
How It Works?
1.Pick a source vertex S to start.
2.Discover the vertices that are adjacent to S.
Depth-first:
visit all neighbors of
a neighbor before
visiting your other
neighbors
Breadth First:
Pick each child of
S in turn and
discover their
vertices adjacent
to that child.
Done when all
children have been
discovered and
examined.
For a Graph G=(V, E) and n = |V| and m=|E|
When Adjacency List is used Complexity is O(m + n)
When Adjacency Matrix is used Scanning each row for
checking the connectivity of a Vertex is in order O(n).
So, Complexity is O(n2 )
DFS uses space O(|V|) in the worst case to store the
stack of vertices on the current search path as well as
the set of already-visited vertices.
Analysis of DFS
Example:
Depth-first search: Directed
graphs
 The algorithm is essentially the same as for undirected
graphs, the difference residing in the interpretation of the
word "adjacent".
 In a directed graph, node w is adjacent to node v if the
directed edge (v, w) exists.
 If (v, w) exists but (w, v) does not, then w is adjacent to v
but v is not adjacent to w.
 With this change of interpretation the procedures dfs and
search apply equally well in the case of a directed graph.
DFS Example
Data Structure and Algorithm
source
vertex
DFS Example
Data Structure and Algorithm
1 | | |
|||
| |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
|||
2 | |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
||3 |
2 | |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
||3 | 4
2 | |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
|5 |3 | 4
2 | |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
|5 | 63 | 4
2 | |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | | |
|5 | 63 | 4
2 | 7 |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | 8 | |
|5 | 63 | 4
2 | 7 |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | 8 | |
|5 | 63 | 4
2 | 7 9 |
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | 8 | |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 | 8 |11 |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 |12 8 |11 |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 |12 8 |11 13|
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 |12 8 |11 13|
14|5 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 |12 8 |11 13|
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d f
DFS Example
Data Structure and Algorithm
1 |12 8 |11 13|16
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d f
Algorithm steps
Step:1
Push the root node in stack.
Step:2
Loop until stack is empty.
Step:3
Peek the node of the stack.
Step:4
If the node has unvisited child nodes get the
unvisited child node mark it has travers and push it
on stack.
Data
Structure
and
Algorithm
DFS: Algorithm
DFS(G)
 for each vertex u in V,
 color[u]=white; p[u]=NIL
 time=0;
 for each vertex u in V
 if (color[u]=white)
 DFS-VISIT(u)
Data
Structure
and
Algorithm
DFS-VISIT(u)
 color[u]=gray;
 time = time + 1;
 d[u] = time;
 for each v in Adj(u) do
 if (color[v] = white)
 p[v] = u;
 DFS-VISIT(v);
 color[u] = black;
 time = time + 1; f[u]= time;
DFS: Algorithm (Cont.)
source
vertex
BFS:
*Testing a graph for bipartitions
*To find the shortest path from a vertex s to
a vertex v in an un weighted graph
*To find the length of such a path
*To find out if a graph contains cycles
*To construct a BSF tree/forest from a graph
*Copying garbage collection
Applications
Applications
DFS:
* Finding connected components.
*Topological sorting.
*Finding the bridges of a graph.
*cycle Detecting
*Finding strongly connected components.
*Finding biconnectivity in graphs.
Bfs and Dfs
Bfs and Dfs

More Related Content

What's hot (20)

Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Graph representation
Graph representationGraph representation
Graph representation
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Dfs
DfsDfs
Dfs
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 

Viewers also liked

Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionMohamed Gad
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure Ankit Kumar Singh
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesKumar Avinash
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Shanawaz Ahamed
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms masterHossam Hassan
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchchandsek666
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Searchbutest
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and GraphsIntro C# Book
 

Viewers also liked (14)

Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introduction
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
Application of dfs
Application of dfsApplication of dfs
Application of dfs
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) search
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 

Similar to Bfs and Dfs

Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRIYABEPARI
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptsandeep54552
 
lecture 19
lecture 19lecture 19
lecture 19sajinsc
 
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxionutionescuionut
 
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm EData Structures and Algorithm AnalysisSpring 2020 Post Midterm E
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm Ejeniihykdevara
 
Data Structures and Algorithm Analysis1. How much memory w.docx
Data Structures and Algorithm Analysis1. How much memory w.docxData Structures and Algorithm Analysis1. How much memory w.docx
Data Structures and Algorithm Analysis1. How much memory w.docxrandyburney60861
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithmhansa khan
 
AI - Backtracking vs Depth-First Search (DFS)
AI - Backtracking vs Depth-First Search (DFS)AI - Backtracking vs Depth-First Search (DFS)
AI - Backtracking vs Depth-First Search (DFS)Johnnatan Messias
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Traian Rebedea
 
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptx
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptxAI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptx
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptxAsst.prof M.Gokilavani
 
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdfSeethaDinesh
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdfamitbhachne
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02Krish_ver2
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmMeghaj Mallick
 
lecture 18
lecture 18lecture 18
lecture 18sajinsc
 
Search Algorithms in AI.pptx
Search Algorithms in AI.pptxSearch Algorithms in AI.pptx
Search Algorithms in AI.pptxDr.Shweta
 

Similar to Bfs and Dfs (20)

kumattt).pptx
kumattt).pptxkumattt).pptx
kumattt).pptx
 
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
 
lecture 19
lecture 19lecture 19
lecture 19
 
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptx
 
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm EData Structures and Algorithm AnalysisSpring 2020 Post Midterm E
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E
 
Data Structures and Algorithm Analysis1. How much memory w.docx
Data Structures and Algorithm Analysis1. How much memory w.docxData Structures and Algorithm Analysis1. How much memory w.docx
Data Structures and Algorithm Analysis1. How much memory w.docx
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithm
 
AI - Backtracking vs Depth-First Search (DFS)
AI - Backtracking vs Depth-First Search (DFS)AI - Backtracking vs Depth-First Search (DFS)
AI - Backtracking vs Depth-First Search (DFS)
 
Graph
GraphGraph
Graph
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7
 
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptx
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptxAI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptx
AI3391 ARTIFICIAL INTELLIGENCE Session 7 Uniformed search strategies.pptx
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdf
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
dfs.pptx
dfs.pptxdfs.pptx
dfs.pptx
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
lecture 18
lecture 18lecture 18
lecture 18
 
Search Algorithms in AI.pptx
Search Algorithms in AI.pptxSearch Algorithms in AI.pptx
Search Algorithms in AI.pptx
 

More from Masud Parvaze

More from Masud Parvaze (6)

Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Higher order math
Higher order mathHigher order math
Higher order math
 
The end of something11
The end of something11The end of something11
The end of something11
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Mechanism of-a-capacitor
Mechanism of-a-capacitorMechanism of-a-capacitor
Mechanism of-a-capacitor
 
Galvanmometer
Galvanmometer Galvanmometer
Galvanmometer
 

Recently uploaded

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringJuanCarlosMorales19600
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxsomshekarkn64
 

Recently uploaded (20)

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineering
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptx
 

Bfs and Dfs

  • 1. Welcome To Our Presentation
  • 2. Group Name : Quantative
  • 3.  Depth First Search (DFS)  Breadth First Search (BFS) Topics
  • 4. What is a graph? 1.Directed/Undirected 2.Weighted/Unweighted 3.Cyclic/Acyclic A set of vertices and edges
  • 5.  Breadth First Search (BFS) Start several paths at a time, and advance in each one step at a time The breadth-first search uses a FIFO queue.  Depth First Search (DFS) Once a possible path is found, continue the search until the end of the path The Depth-first search uses a LIFO Stack. Graph Traversal
  • 6. How It Works? 1.Pick a source vertex S to start. 2.Discover the vertices that are adjacent to S. Depth-first: visit all neighbors of a neighbor before visiting your other neighbors Breadth First: Pick each child of S in turn and discover their vertices adjacent to that child. Done when all children have been discovered and examined.
  • 7. For a Graph G=(V, E) and n = |V| and m=|E| When Adjacency List is used Complexity is O(m + n) When Adjacency Matrix is used Scanning each row for checking the connectivity of a Vertex is in order O(n). So, Complexity is O(n2 ) DFS uses space O(|V|) in the worst case to store the stack of vertices on the current search path as well as the set of already-visited vertices. Analysis of DFS
  • 9. Depth-first search: Directed graphs  The algorithm is essentially the same as for undirected graphs, the difference residing in the interpretation of the word "adjacent".  In a directed graph, node w is adjacent to node v if the directed edge (v, w) exists.  If (v, w) exists but (w, v) does not, then w is adjacent to v but v is not adjacent to w.  With this change of interpretation the procedures dfs and search apply equally well in the case of a directed graph.
  • 10. DFS Example Data Structure and Algorithm source vertex
  • 11. DFS Example Data Structure and Algorithm 1 | | | ||| | | source vertex d f
  • 12. DFS Example Data Structure and Algorithm 1 | | | ||| 2 | | source vertex d f
  • 13. DFS Example Data Structure and Algorithm 1 | | | ||3 | 2 | | source vertex d f
  • 14. DFS Example Data Structure and Algorithm 1 | | | ||3 | 4 2 | | source vertex d f
  • 15. DFS Example Data Structure and Algorithm 1 | | | |5 |3 | 4 2 | | source vertex d f
  • 16. DFS Example Data Structure and Algorithm 1 | | | |5 | 63 | 4 2 | | source vertex d f
  • 17. DFS Example Data Structure and Algorithm 1 | | | |5 | 63 | 4 2 | 7 | source vertex d f
  • 18. DFS Example Data Structure and Algorithm 1 | 8 | | |5 | 63 | 4 2 | 7 | source vertex d f
  • 19. DFS Example Data Structure and Algorithm 1 | 8 | | |5 | 63 | 4 2 | 7 9 | source vertex d f
  • 20. DFS Example Data Structure and Algorithm 1 | 8 | | |5 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 21. DFS Example Data Structure and Algorithm 1 | 8 |11 | |5 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 22. DFS Example Data Structure and Algorithm 1 |12 8 |11 | |5 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 23. DFS Example Data Structure and Algorithm 1 |12 8 |11 13| |5 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 24. DFS Example Data Structure and Algorithm 1 |12 8 |11 13| 14|5 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 25. DFS Example Data Structure and Algorithm 1 |12 8 |11 13| 14|155 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 26. DFS Example Data Structure and Algorithm 1 |12 8 |11 13|16 14|155 | 63 | 4 2 | 7 9 |10 source vertex d f
  • 27. Algorithm steps Step:1 Push the root node in stack. Step:2 Loop until stack is empty. Step:3 Peek the node of the stack. Step:4 If the node has unvisited child nodes get the unvisited child node mark it has travers and push it on stack.
  • 28. Data Structure and Algorithm DFS: Algorithm DFS(G)  for each vertex u in V,  color[u]=white; p[u]=NIL  time=0;  for each vertex u in V  if (color[u]=white)  DFS-VISIT(u)
  • 29. Data Structure and Algorithm DFS-VISIT(u)  color[u]=gray;  time = time + 1;  d[u] = time;  for each v in Adj(u) do  if (color[v] = white)  p[v] = u;  DFS-VISIT(v);  color[u] = black;  time = time + 1; f[u]= time; DFS: Algorithm (Cont.) source vertex
  • 30. BFS: *Testing a graph for bipartitions *To find the shortest path from a vertex s to a vertex v in an un weighted graph *To find the length of such a path *To find out if a graph contains cycles *To construct a BSF tree/forest from a graph *Copying garbage collection Applications
  • 31. Applications DFS: * Finding connected components. *Topological sorting. *Finding the bridges of a graph. *cycle Detecting *Finding strongly connected components. *Finding biconnectivity in graphs.