SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
DEPTH FIRST
SEARCH [DFS]
PRESENTED BY : ANKIT KUMAR
BRANCH : ECE
UNI. ROLL : 12500319018
INTRODUCTION
 A depth-first search (DFS) explores a path all the
way to a leaf before backtracking and exploring
another path.
 For example, after searching A, then B, then D, the
search backtracks and tries another path from B.
 Node are explored in the order A B D E H L M N I O
P C F G J K Q. L M N O P N will be found before
J.
INTRO….
 To keep track of progress DFS colors each vertex
white, gray or black. Initially all the vertices are
colored white. Then they are colored gray when
discovered. Finally colored black when finished.
 Besides creating depth first forest DFS also
timestamps each vertex. Each vertex goes through
two time stamps:
 Discover time d[u]: when u is first discovered
Finish time f[u]: when backtrack from u or finished
u
f[u] > d[u]
DFS: ALGORITHM
DFS: Algorithm
DFS(G)
1. for each vertex u in G
2. color[u]=white
3. ᴨ[u]=NIL
4. time=0
5. for each vertex u in G
6. if (color[u]==white)
7. DFS-VISIT(G,u)
ALGO(CONT…)
DFS-VISIT(u)
1. time = time + 1
2. d[u] = time
3. color[u]=gray
4. for each v €
Adj(u) in G do
5.if (color[v] = =white)
6. ᴨ[v] = u;
7. DFS-VISIT(G,v);
8. color[u] = black
9. time = time + 1;
10. f[u]= time;
DFS: COMPLEXITY ANALYSIS
 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)
DFS: APPLICATION
 Topological Sort
 Strongly Connected Component
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.
EXAMPLE OF EDGES
THEOREM DERIVED FROM DFS
 Theorem 1: In a depth first search of an undirected
graph G, every edge of G is either a tree edge or
back edge.
 Theorem 2: A directed graph G is acyclic if and
only if a depth-first search of G yields no back
edges.
DFS ppt.pdf

Mais conteúdo relacionado

Mais procurados

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 searchingKawsar Hamid Sumon
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Traian Rebedea
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02Krish_ver2
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithmhansa khan
 
Sorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmSorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmJanki Shah
 

Mais procurados (20)

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
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
A* algorithm
A* algorithmA* algorithm
A* algorithm
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8
 
BFS
BFSBFS
BFS
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Application of dfs
Application of dfsApplication of dfs
Application of dfs
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Iterative deepening search
Iterative deepening searchIterative deepening search
Iterative deepening search
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithm
 
Sorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmSorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of Algorithm
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 

Semelhante a DFS ppt.pdf

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 3Deepak John
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)Ishucs
 
ada-191015145338.pdf
ada-191015145338.pdfada-191015145338.pdf
ada-191015145338.pdfAshwin180668
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)Dhrumil Panchal
 
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 TraversalAmrinder Arora
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in indiaEdhole.com
 
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.docxwhittemorelucilla
 
lecture 19
lecture 19lecture 19
lecture 19sajinsc
 
Elementary Graph Algo.ppt
Elementary Graph Algo.pptElementary Graph Algo.ppt
Elementary Graph Algo.pptSazidHossain9
 
lecture 18
lecture 18lecture 18
lecture 18sajinsc
 
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
 

Semelhante a DFS ppt.pdf (19)

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
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
kumattt).pptx
kumattt).pptxkumattt).pptx
kumattt).pptx
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)
 
ada-191015145338.pdf
ada-191015145338.pdfada-191015145338.pdf
ada-191015145338.pdf
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
 
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
 
Chapter 23 aoa
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
 
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
 
lecture 19
lecture 19lecture 19
lecture 19
 
19-graph1 (1).ppt
19-graph1 (1).ppt19-graph1 (1).ppt
19-graph1 (1).ppt
 
Graph 02
Graph 02Graph 02
Graph 02
 
chapter22.ppt
chapter22.pptchapter22.ppt
chapter22.ppt
 
Elementary Graph Algo.ppt
Elementary Graph Algo.pptElementary Graph Algo.ppt
Elementary Graph Algo.ppt
 
lecture 18
lecture 18lecture 18
lecture 18
 
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
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 

Último

Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1bengalurutug
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptxFurkanTasci3
 
The market for cross-border mortgages in Europe
The market for cross-border mortgages in EuropeThe market for cross-border mortgages in Europe
The market for cross-border mortgages in Europe321k
 
Paul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfPaul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfdcphostmaster
 
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Neo4j
 
Enabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge GraphsEnabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge GraphsNeo4j
 
Stochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxStochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxjkmrshll88
 
PPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggPPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggbhadratanusenapati1
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptxFurkanTasci3
 
Data Collection from Social Media Platforms
Data Collection from Social Media PlatformsData Collection from Social Media Platforms
Data Collection from Social Media PlatformsMahmoud Yasser
 
How to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentHow to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentAggregage
 
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...ferisulianta.com
 
Empowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsEmpowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsGain Insights
 
Data Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxData Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxEmmanuel Dauda
 
Air Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfAir Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfJasonBoboKyaw
 
Unleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMUnleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMMarco Wobben
 
Microeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfMicroeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfmxlos0
 
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j
 

Último (20)

Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
 
The market for cross-border mortgages in Europe
The market for cross-border mortgages in EuropeThe market for cross-border mortgages in Europe
The market for cross-border mortgages in Europe
 
Paul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfPaul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdf
 
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
 
Enabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge GraphsEnabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge Graphs
 
Stochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxStochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptx
 
PPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggPPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfgggg
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
 
Data Collection from Social Media Platforms
Data Collection from Social Media PlatformsData Collection from Social Media Platforms
Data Collection from Social Media Platforms
 
How to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentHow to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product Development
 
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
 
Empowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsEmpowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded Analytics
 
Data Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxData Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potx
 
Air Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfAir Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdf
 
Unleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMUnleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IM
 
Target_Company_Data_breach_2013_110million
Target_Company_Data_breach_2013_110millionTarget_Company_Data_breach_2013_110million
Target_Company_Data_breach_2013_110million
 
Microeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfMicroeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdf
 
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
 

DFS ppt.pdf

  • 1. DEPTH FIRST SEARCH [DFS] PRESENTED BY : ANKIT KUMAR BRANCH : ECE UNI. ROLL : 12500319018
  • 2. INTRODUCTION  A depth-first search (DFS) explores a path all the way to a leaf before backtracking and exploring another path.  For example, after searching A, then B, then D, the search backtracks and tries another path from B.  Node are explored in the order A B D E H L M N I O P C F G J K Q. L M N O P N will be found before J.
  • 3. INTRO….  To keep track of progress DFS colors each vertex white, gray or black. Initially all the vertices are colored white. Then they are colored gray when discovered. Finally colored black when finished.  Besides creating depth first forest DFS also timestamps each vertex. Each vertex goes through two time stamps:  Discover time d[u]: when u is first discovered Finish time f[u]: when backtrack from u or finished u f[u] > d[u]
  • 4. DFS: ALGORITHM DFS: Algorithm DFS(G) 1. for each vertex u in G 2. color[u]=white 3. ᴨ[u]=NIL 4. time=0 5. for each vertex u in G 6. if (color[u]==white) 7. DFS-VISIT(G,u)
  • 5. ALGO(CONT…) DFS-VISIT(u) 1. time = time + 1 2. d[u] = time 3. color[u]=gray 4. for each v € Adj(u) in G do 5.if (color[v] = =white) 6. ᴨ[v] = u; 7. DFS-VISIT(G,v); 8. color[u] = black 9. time = time + 1; 10. f[u]= time;
  • 6. DFS: COMPLEXITY ANALYSIS  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)
  • 7. DFS: APPLICATION  Topological Sort  Strongly Connected Component
  • 8. 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.
  • 10. THEOREM DERIVED FROM DFS  Theorem 1: In a depth first search of an undirected graph G, every edge of G is either a tree edge or back edge.  Theorem 2: A directed graph G is acyclic if and only if a depth-first search of G yields no back edges.