SlideShare a Scribd company logo
1 of 16
JLD ENGINEERING AND MANAGEMENT
COLLEGE
Department of Computer Science & Engineering
TOPIC NAME
DEPTH FIRST SEARCH
PRESENTED BY:
NAME: RIYA BEPARI
UNIVERSITY ROLL: 34700122020
DEPARTMENT: COMPUTER SCIENCE & ENGINEERING
YEAR: 3rd
SEMESTER: 5th
SUBJECT: ARTIFICIAL INTELLIGENCE
SUJECT CODE: PEC-IT501B
 OVERVIEW
COMPLEXITY &
PSEUDOCODE
 INTRODUCTION
 ALGORITHM
 METHODS TO IMPLEMENT
 ADVANTAGES &
DISADVANTAGES
 SUMMARY
 REFERENCES
AGENDA
 APPLICATIONS
 CLASSIFICATION OF
EDGES
OVERVIEW
 DFS stands for Depth First Search. DFS is an algorithm for
traversing or searching a tree or graph data structures. It uses a
stack data structure for implementation. In DFS one starts at
the root and explores as far as possible along each branch
before backtracking. The algorithm starts at the root node
(selecting some arbitrary node as the root node in the case of a
graph) and explores as far as possible along each branch before
backtracking. Extra memory, usually a stack, is needed to keep
track of the nodes discovered so far along a specified branch
which helps in backtracking of the graph.
 Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures.
The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a
graph) and explores as far as possible along each branch before backtracking. It uses last in- first-out
strategy and hence it is implemented using a stack.
It entails conducting exhaustive searches of all nodes by moving forward if possible and
backtracking, if necessary. To visit the next node, pop the top node from the stack and push all of its
nearby nodes into a stack. Topological sorting, scheduling problems, graph cycle detection, and
solving puzzles with just one solution, such as a maze or a sudoku puzzle, all employ depth-first
search algorithms. Other applications include network analysis, such as determining if a graph is
bipartite.
INTRODUCTION
ALGORITHM
Step 1: SET STATUS = 1 (ready state) for each node in G
Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting state)
Step 3: Repeat Steps 4 and 5 until STACK is empty
Step 4: Pop the top node N. Process it and set its STATUS = 3 (processed state)
Step 5: Push on the stack all the neighbors of N that are in the ready state (whose STATUS = 1) and set their
STATUS = 2 (waiting state)
[END OF LOOP]
Step 6: EXIT
METHODS TO IMPLEMENT OF DFS ALGORITHM
The following two methods are typically employed to implement DFS
efficiently- recursive and iterative.
 Recursive Approach:
In the recursive approach, the algorithm starts at the source vertex and marks
it as visited. It recursively explores every unvisited neighbor of the source
vertex. When no more unvisited neighbors are left, the algorithm backtracks
to the previous vertex in the stack and repeats the process until all vertices in
the graph are visited.
 Iterative Approach:
In the iterative approach, the algorithm uses a stack to keep track of the
vertices that need to be visited next. It starts at the source vertex, marks it as
visited, and pushes it onto the stack. Then, it repeatedly pops the top vertex
from the stack, explores its unvisited neighbors, and makes them onto the
stack until all are visited.
APPLICATIONS OF DEPTH FIRST SEARCH
1. Detecting cycle in a graph: A graph has a cycle if and only if we see a back edge during DFS. So we can run DFS for
the graph and check for back edges.
2. Path Finding: We can specialize the DFS algorithm to find a path between two given vertices u and z.
3. Topological Sorting: Topological Sorting is mainly used for scheduling jobs from the given dependencies among
jobs. In computer science, applications of this type arise in instruction scheduling, ordering of formula cell evaluation
when recomputing formula values in spreadsheets, logic synthesis, determining the order of compilation tasks to
perform in make files, data serialization, and resolving symbol dependencies in linkers.
4. To test if a graph is bipartite: We can augment either BFS or DFS when we first discover a new vertex, color it
opposite its parents, and for each other edge, check it doesn’t link two vertices of the same color. The first vertex in any
connected component can be red or black.
5. Finding Strongly Connected Components of a graph: A directed graph is called strongly connected if there is a path
from each vertex in the graph to every other vertex. (See this for DFS-based algo for finding Strongly Connected
Components)
6. Solving puzzles with only one solution: such as mazes. (DFS can be adapted to find all solutions to a
maze by only including nodes on the current path in the visited set.).
7. Web crawlers: Depth-first search can be used in the implementation of web crawlers to explore the links
on a website.
8. Maze generation: Depth-first search can be used to generate random mazes.
9. Model checking: Depth-first search can be used in model checking, which is the process of checking that
a model of a system meets a certain set of properties.
10. Backtracking: Depth-first search can be used in backtracking algorithms.
CLASSIFICATION OF EDGES
 Tree edge: Edge (u,v) is a tree edge if v was first discovered by exploring edge (u,v). White color indicates
tree edge.
 Back edge: Edge (u,v) is a back edge if it connects a vertex u to a ancestor v in a depth first tree. Gray color
indicates back edge.
 Forward edge: Edge (u,v) is a forward edge if it is non-tree edge and it connects a vertex u to a descendant
v in a depth first tree. Black color indicates forward edge.
 Cross edge: rest all other edges are called the cross edge. Black color indicates forward edge.
 Initialization complexity is O(V)
 DFS_VISIT is called exactly once for each vertex
 And DFS VISIT scans all the edges which causes cost of O(E)
 Thus overall complexity is O(V + E)
Pseudocode:
DFS(G,v) ( v is the vertex where the search starts )
Stack S := {}; ( start with an empty stack )
for each vertex u, set visited[u] := false;
push S, v;
while (S is not empty) do
u := pop S;
if (not visited[u]) then
visited[u] := true;
for each unvisited neighbour w of uu
push S, w;
end if
end while
END DFS()
COMPLEXITY & PSEUDOCODE
ADVANTAGES & DISADVANTAGES
ADVANTAGES DISADVANTAGES
The time complexity of a depth-first Search to depth d
and branching factor b is O(bd) since it generates the
same set of nodes as breadth-first search, but simply in a
different order. Thus practically depth-first search is
time-limited rather than space-limited.
If depth-first search finds solution
without exploring much in a path then
the time and space it takes will be very
less.
DFS requires less memory since only the
nodes on the current path are stored. By
chance DFS may find a solution without
examining much of the search space at all.
The disadvantage of Depth-First Search is that
there is a possibility that it may down the left-
most path forever. Even a finite graph can
generate an infinite tree One solution to this
problem is to impose a cutoff depth on the search.
Depth-First Search is not guaranteed to
find the solution.
And there is no guarantee to find a
minimal solution, if more than one
solution.
SUMMARY
The Depth-First Search (DFS) algorithm is a simple yet powerful technique for graph
traversal. It starts from a starting node, explores as far as possible along each branch
before backtracking, and uses a stack to keep track of visited nodes. DFS is widely
used in various applications such as maze generation, topological sorting, and cycle
detection. However, it may not necessarily visit all nodes in a graph, especially if the
graph is disconnected. Despite its limitations, DFS is a fundamental computer science
algorithm widely used in numerous real-world applications.
REFERENCES
1. https://en.wikipedia.org/wiki/Depth-first_search
2. https://www.javatpoint.com/depth-first-search-algorithm
3. https://www.codingninjas.com/studio/library/dfs-depth-first-search-algorithm
4. https://www.geeksforgeeks.org/applications-of-depth-first-search/
THANK YOU

More Related Content

Similar to Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx

graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 

Similar to Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx (20)

Data structure note
Data structure noteData structure note
Data structure note
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
distributed depth-first search
distributed depth-first search distributed depth-first search
distributed depth-first search
 
Adsa u2 ver 1.0.
Adsa u2 ver 1.0.Adsa u2 ver 1.0.
Adsa u2 ver 1.0.
 
artificial intelligence
artificial intelligence artificial intelligence
artificial intelligence
 
ARTIFICIAL INTELLIGENCE UNIT 2(2)
ARTIFICIAL INTELLIGENCE UNIT 2(2)ARTIFICIAL INTELLIGENCE UNIT 2(2)
ARTIFICIAL INTELLIGENCE UNIT 2(2)
 
AI Lesson 04
AI Lesson 04AI Lesson 04
AI Lesson 04
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Ai1.pdf
Ai1.pdfAi1.pdf
Ai1.pdf
 
kumattt).pptx
kumattt).pptxkumattt).pptx
kumattt).pptx
 
Data structure
Data structureData structure
Data structure
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
Search algorithms for discrete optimization
Search algorithms for discrete optimizationSearch algorithms for discrete optimization
Search algorithms for discrete optimization
 
Chap11 slides
Chap11 slidesChap11 slides
Chap11 slides
 
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
 
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
 
Week 7.pdf
Week 7.pdfWeek 7.pdf
Week 7.pdf
 

More from RIYABEPARI

Riya Bepari_34700122020_Operating System_PCC-CS502.pptx
Riya Bepari_34700122020_Operating System_PCC-CS502.pptxRiya Bepari_34700122020_Operating System_PCC-CS502.pptx
Riya Bepari_34700122020_Operating System_PCC-CS502.pptx
RIYABEPARI
 
Riya Bepari_34700122020_Numerical Methods.pptx
Riya Bepari_34700122020_Numerical Methods.pptxRiya Bepari_34700122020_Numerical Methods.pptx
Riya Bepari_34700122020_Numerical Methods.pptx
RIYABEPARI
 
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptxArun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
RIYABEPARI
 
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
RIYABEPARI
 
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptxArun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
RIYABEPARI
 
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptxArun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
RIYABEPARI
 

More from RIYABEPARI (6)

Riya Bepari_34700122020_Operating System_PCC-CS502.pptx
Riya Bepari_34700122020_Operating System_PCC-CS502.pptxRiya Bepari_34700122020_Operating System_PCC-CS502.pptx
Riya Bepari_34700122020_Operating System_PCC-CS502.pptx
 
Riya Bepari_34700122020_Numerical Methods.pptx
Riya Bepari_34700122020_Numerical Methods.pptxRiya Bepari_34700122020_Numerical Methods.pptx
Riya Bepari_34700122020_Numerical Methods.pptx
 
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptxArun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Constitution_of_India[1] [Autosaved].pptx
 
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
Arun Gayen_CSE_34700122011_Introduction_to_Industrial_Management(Humanities-I...
 
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptxArun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
Arun Gayen_CSE_34700122011_Artificial_Intelligence[1] [Autosaved].pptx
 
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptxArun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
Arun Gayen_CSE_34700122011_Software_Engineering[1] (1) [Autosaved].pptx
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 

Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx

  • 1. JLD ENGINEERING AND MANAGEMENT COLLEGE Department of Computer Science & Engineering
  • 3. PRESENTED BY: NAME: RIYA BEPARI UNIVERSITY ROLL: 34700122020 DEPARTMENT: COMPUTER SCIENCE & ENGINEERING YEAR: 3rd SEMESTER: 5th SUBJECT: ARTIFICIAL INTELLIGENCE SUJECT CODE: PEC-IT501B
  • 4.  OVERVIEW COMPLEXITY & PSEUDOCODE  INTRODUCTION  ALGORITHM  METHODS TO IMPLEMENT  ADVANTAGES & DISADVANTAGES  SUMMARY  REFERENCES AGENDA  APPLICATIONS  CLASSIFICATION OF EDGES
  • 5. OVERVIEW  DFS stands for Depth First Search. DFS is an algorithm for traversing or searching a tree or graph data structures. It uses a stack data structure for implementation. In DFS one starts at the root and explores as far as possible along each branch before backtracking. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking. Extra memory, usually a stack, is needed to keep track of the nodes discovered so far along a specified branch which helps in backtracking of the graph.
  • 6.  Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking. It uses last in- first-out strategy and hence it is implemented using a stack. It entails conducting exhaustive searches of all nodes by moving forward if possible and backtracking, if necessary. To visit the next node, pop the top node from the stack and push all of its nearby nodes into a stack. Topological sorting, scheduling problems, graph cycle detection, and solving puzzles with just one solution, such as a maze or a sudoku puzzle, all employ depth-first search algorithms. Other applications include network analysis, such as determining if a graph is bipartite. INTRODUCTION
  • 7. ALGORITHM Step 1: SET STATUS = 1 (ready state) for each node in G Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting state) Step 3: Repeat Steps 4 and 5 until STACK is empty Step 4: Pop the top node N. Process it and set its STATUS = 3 (processed state) Step 5: Push on the stack all the neighbors of N that are in the ready state (whose STATUS = 1) and set their STATUS = 2 (waiting state) [END OF LOOP] Step 6: EXIT
  • 8. METHODS TO IMPLEMENT OF DFS ALGORITHM The following two methods are typically employed to implement DFS efficiently- recursive and iterative.  Recursive Approach: In the recursive approach, the algorithm starts at the source vertex and marks it as visited. It recursively explores every unvisited neighbor of the source vertex. When no more unvisited neighbors are left, the algorithm backtracks to the previous vertex in the stack and repeats the process until all vertices in the graph are visited.  Iterative Approach: In the iterative approach, the algorithm uses a stack to keep track of the vertices that need to be visited next. It starts at the source vertex, marks it as visited, and pushes it onto the stack. Then, it repeatedly pops the top vertex from the stack, explores its unvisited neighbors, and makes them onto the stack until all are visited.
  • 9. APPLICATIONS OF DEPTH FIRST SEARCH 1. Detecting cycle in a graph: A graph has a cycle if and only if we see a back edge during DFS. So we can run DFS for the graph and check for back edges. 2. Path Finding: We can specialize the DFS algorithm to find a path between two given vertices u and z. 3. Topological Sorting: Topological Sorting is mainly used for scheduling jobs from the given dependencies among jobs. In computer science, applications of this type arise in instruction scheduling, ordering of formula cell evaluation when recomputing formula values in spreadsheets, logic synthesis, determining the order of compilation tasks to perform in make files, data serialization, and resolving symbol dependencies in linkers. 4. To test if a graph is bipartite: We can augment either BFS or DFS when we first discover a new vertex, color it opposite its parents, and for each other edge, check it doesn’t link two vertices of the same color. The first vertex in any connected component can be red or black. 5. Finding Strongly Connected Components of a graph: A directed graph is called strongly connected if there is a path from each vertex in the graph to every other vertex. (See this for DFS-based algo for finding Strongly Connected Components)
  • 10. 6. Solving puzzles with only one solution: such as mazes. (DFS can be adapted to find all solutions to a maze by only including nodes on the current path in the visited set.). 7. Web crawlers: Depth-first search can be used in the implementation of web crawlers to explore the links on a website. 8. Maze generation: Depth-first search can be used to generate random mazes. 9. Model checking: Depth-first search can be used in model checking, which is the process of checking that a model of a system meets a certain set of properties. 10. Backtracking: Depth-first search can be used in backtracking algorithms.
  • 11. CLASSIFICATION OF EDGES  Tree edge: Edge (u,v) is a tree edge if v was first discovered by exploring edge (u,v). White color indicates tree edge.  Back edge: Edge (u,v) is a back edge if it connects a vertex u to a ancestor v in a depth first tree. Gray color indicates back edge.  Forward edge: Edge (u,v) is a forward edge if it is non-tree edge and it connects a vertex u to a descendant v in a depth first tree. Black color indicates forward edge.  Cross edge: rest all other edges are called the cross edge. Black color indicates forward edge.
  • 12.  Initialization complexity is O(V)  DFS_VISIT is called exactly once for each vertex  And DFS VISIT scans all the edges which causes cost of O(E)  Thus overall complexity is O(V + E) Pseudocode: DFS(G,v) ( v is the vertex where the search starts ) Stack S := {}; ( start with an empty stack ) for each vertex u, set visited[u] := false; push S, v; while (S is not empty) do u := pop S; if (not visited[u]) then visited[u] := true; for each unvisited neighbour w of uu push S, w; end if end while END DFS() COMPLEXITY & PSEUDOCODE
  • 13. ADVANTAGES & DISADVANTAGES ADVANTAGES DISADVANTAGES The time complexity of a depth-first Search to depth d and branching factor b is O(bd) since it generates the same set of nodes as breadth-first search, but simply in a different order. Thus practically depth-first search is time-limited rather than space-limited. If depth-first search finds solution without exploring much in a path then the time and space it takes will be very less. DFS requires less memory since only the nodes on the current path are stored. By chance DFS may find a solution without examining much of the search space at all. The disadvantage of Depth-First Search is that there is a possibility that it may down the left- most path forever. Even a finite graph can generate an infinite tree One solution to this problem is to impose a cutoff depth on the search. Depth-First Search is not guaranteed to find the solution. And there is no guarantee to find a minimal solution, if more than one solution.
  • 14. SUMMARY The Depth-First Search (DFS) algorithm is a simple yet powerful technique for graph traversal. It starts from a starting node, explores as far as possible along each branch before backtracking, and uses a stack to keep track of visited nodes. DFS is widely used in various applications such as maze generation, topological sorting, and cycle detection. However, it may not necessarily visit all nodes in a graph, especially if the graph is disconnected. Despite its limitations, DFS is a fundamental computer science algorithm widely used in numerous real-world applications.
  • 15. REFERENCES 1. https://en.wikipedia.org/wiki/Depth-first_search 2. https://www.javatpoint.com/depth-first-search-algorithm 3. https://www.codingninjas.com/studio/library/dfs-depth-first-search-algorithm 4. https://www.geeksforgeeks.org/applications-of-depth-first-search/