SlideShare a Scribd company logo
z
DFS Algorithm
IN Bangla
z
2
Depth-First Search: The Code
Data: color[V], time, prev[V],d[V],
f[V]
DFS(G) // where prog starts
{
for each vertex u  V
{
color[u] = WHITE;
prev[u]=NIL;
f[u]=inf; d[u]=inf;
}
time = 0;
for each vertex u  V
if (color[u] == WHITE)
DFS_Visit(u);
}
DFS_Visit(u)
{
color[u] = GREY;
time = time+1;
d[u] = time;
for each v  Adj[u]
{
if(color[v] == WHITE){
prev[v]=u;
DFS_Visit(v);}
}
color[u] = BLACK;
time = time+1;
f[u] = time;
}
Initialize
z
DFS Example
3
source
vertex
S
A
B C
D
E
F
G
z
DFS Example
4
1 | | |
|||
| |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
5
1 | | |
|||
2 | |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
6
1 | | |
||3 |
2 | |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
7
1 | | |
||3 | 4
2 | |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
8
1 | | |
|5 |3 | 4
2 | |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
9
1 | | |
|5 | 63 | 4
2 | |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
10
1 | | |
|5 | 63 | 4
2 | 7 |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
11
1 | 8 | |
|5 | 63 | 4
2 | 7 |
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
12
1 | 8 | |
|5 | 63 | 4
2 | 7 9 |
source
vertex
d f
What is the structure of the grey vertices?
What do they represent?
S
A
B C
D
E
F
G
z
DFS Example
13
1 | 8 | |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
14
1 | 8 |11 |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
15
1 |12 8 |11 |
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
16
1 |12 8 |11 13|
|5 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
17
1 |12 8 |11 13|
14|5 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
18
1 |12 8 |11 13|
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
DFS Example
19
1 |12 8 |11 13|16
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d fS
A
B C
D
E
F
G
z
20
DFS: Kinds of edges
 DFS introduces an important distinction among edges in the original graph:
 Tree edge: encounter new (white) vertex
 Back edge: from descendent to ancestor
 Forward edge: from ancestor to descendent
 Cross edge: between a tree or subtrees
 From a grey node to a black node
z
21
DFS Example
1 |12 8 |11 13|16
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d f
Tree edges Back edges Forward edges Cross edges
z
22
DFS Example
1 |12 8 |11 13|16
14|155 | 63 | 4
2 | 7 9 |10
source
vertex
d f
Tree edges Back edges Forward edges Cross edges

More Related Content

What's hot

Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
Umme habiba
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)
Ishucs
 
Depth First Search ( DFS )
Depth First Search ( DFS )Depth First Search ( DFS )
Depth First Search ( DFS )
Sazzad Hossain
 
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
Hossain Md Shakhawat
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
Sazzad Hossain
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
BFS
BFSBFS
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
Md. Shafiuzzaman Hira
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
Nisha Soms
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
Md. Shafiuzzaman Hira
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
Krish_ver2
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
Ketaki_Pattani
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
Rajandeep Gill
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal Algorithm
MSA Technosoft
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint paths
Sujith Jay Nair
 

What's hot (20)

Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)
 
Depth First Search ( DFS )
Depth First Search ( DFS )Depth First Search ( DFS )
Depth First Search ( DFS )
 
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
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
BFS
BFSBFS
BFS
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
chapter22.ppt
chapter22.pptchapter22.ppt
chapter22.ppt
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal Algorithm
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint paths
 

More from Amit Kundu

Covid Guide Line Bangladesh
Covid Guide Line BangladeshCovid Guide Line Bangladesh
Covid Guide Line Bangladesh
Amit Kundu
 
Blockchain
BlockchainBlockchain
Blockchain
Amit Kundu
 
Smart Home Automation And security System
Smart Home Automation And security SystemSmart Home Automation And security System
Smart Home Automation And security System
Amit Kundu
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
Amit Kundu
 
Automated Tools For System Analysis and Design
Automated Tools For System Analysis and DesignAutomated Tools For System Analysis and Design
Automated Tools For System Analysis and Design
Amit Kundu
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
Amit Kundu
 
Database project IDEA
Database project IDEADatabase project IDEA
Database project IDEA
Amit Kundu
 
Ipv4 & ipv6
Ipv4 & ipv6Ipv4 & ipv6
Ipv4 & ipv6
Amit Kundu
 
Unguided Media
Unguided  MediaUnguided  Media
Unguided Media
Amit Kundu
 
Innovative Business Idea
Innovative Business IdeaInnovative Business Idea
Innovative Business Idea
Amit Kundu
 
Intel core i7
Intel core i7Intel core i7
Intel core i7
Amit Kundu
 
Laplace transform
Laplace transformLaplace transform
Laplace transform
Amit Kundu
 
Presentation on Rectifier
Presentation on RectifierPresentation on Rectifier
Presentation on Rectifier
Amit Kundu
 
Presentation on Heap Sort
Presentation on Heap Sort Presentation on Heap Sort
Presentation on Heap Sort
Amit Kundu
 
Bfs algorithm & its application
Bfs algorithm & its applicationBfs algorithm & its application
Bfs algorithm & its application
Amit Kundu
 
Presentation on chikunguny
Presentation on chikungunyPresentation on chikunguny
Presentation on chikunguny
Amit Kundu
 
A presentation on social networking sites
A presentation on social networking sitesA presentation on social networking sites
A presentation on social networking sites
Amit Kundu
 

More from Amit Kundu (17)

Covid Guide Line Bangladesh
Covid Guide Line BangladeshCovid Guide Line Bangladesh
Covid Guide Line Bangladesh
 
Blockchain
BlockchainBlockchain
Blockchain
 
Smart Home Automation And security System
Smart Home Automation And security SystemSmart Home Automation And security System
Smart Home Automation And security System
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
Automated Tools For System Analysis and Design
Automated Tools For System Analysis and DesignAutomated Tools For System Analysis and Design
Automated Tools For System Analysis and Design
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
 
Database project IDEA
Database project IDEADatabase project IDEA
Database project IDEA
 
Ipv4 & ipv6
Ipv4 & ipv6Ipv4 & ipv6
Ipv4 & ipv6
 
Unguided Media
Unguided  MediaUnguided  Media
Unguided Media
 
Innovative Business Idea
Innovative Business IdeaInnovative Business Idea
Innovative Business Idea
 
Intel core i7
Intel core i7Intel core i7
Intel core i7
 
Laplace transform
Laplace transformLaplace transform
Laplace transform
 
Presentation on Rectifier
Presentation on RectifierPresentation on Rectifier
Presentation on Rectifier
 
Presentation on Heap Sort
Presentation on Heap Sort Presentation on Heap Sort
Presentation on Heap Sort
 
Bfs algorithm & its application
Bfs algorithm & its applicationBfs algorithm & its application
Bfs algorithm & its application
 
Presentation on chikunguny
Presentation on chikungunyPresentation on chikunguny
Presentation on chikunguny
 
A presentation on social networking sites
A presentation on social networking sitesA presentation on social networking sites
A presentation on social networking sites
 

Recently uploaded

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
RicletoEspinosa1
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
nikitacareer3
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 

Recently uploaded (20)

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 

DFS algorithm

  • 2. z 2 Depth-First Search: The Code Data: color[V], time, prev[V],d[V], f[V] DFS(G) // where prog starts { for each vertex u  V { color[u] = WHITE; prev[u]=NIL; f[u]=inf; d[u]=inf; } time = 0; for each vertex u  V if (color[u] == WHITE) DFS_Visit(u); } DFS_Visit(u) { color[u] = GREY; time = time+1; d[u] = time; for each v  Adj[u] { if(color[v] == WHITE){ prev[v]=u; DFS_Visit(v);} } color[u] = BLACK; time = time+1; f[u] = time; } Initialize
  • 4. z DFS Example 4 1 | | | ||| | | source vertex d fS A B C D E F G
  • 5. z DFS Example 5 1 | | | ||| 2 | | source vertex d fS A B C D E F G
  • 6. z DFS Example 6 1 | | | ||3 | 2 | | source vertex d fS A B C D E F G
  • 7. z DFS Example 7 1 | | | ||3 | 4 2 | | source vertex d fS A B C D E F G
  • 8. z DFS Example 8 1 | | | |5 |3 | 4 2 | | source vertex d fS A B C D E F G
  • 9. z DFS Example 9 1 | | | |5 | 63 | 4 2 | | source vertex d fS A B C D E F G
  • 10. z DFS Example 10 1 | | | |5 | 63 | 4 2 | 7 | source vertex d fS A B C D E F G
  • 11. z DFS Example 11 1 | 8 | | |5 | 63 | 4 2 | 7 | source vertex d fS A B C D E F G
  • 12. z DFS Example 12 1 | 8 | | |5 | 63 | 4 2 | 7 9 | source vertex d f What is the structure of the grey vertices? What do they represent? S A B C D E F G
  • 13. z DFS Example 13 1 | 8 | | |5 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 14. z DFS Example 14 1 | 8 |11 | |5 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 15. z DFS Example 15 1 |12 8 |11 | |5 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 16. z DFS Example 16 1 |12 8 |11 13| |5 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 17. z DFS Example 17 1 |12 8 |11 13| 14|5 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 18. z DFS Example 18 1 |12 8 |11 13| 14|155 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 19. z DFS Example 19 1 |12 8 |11 13|16 14|155 | 63 | 4 2 | 7 9 |10 source vertex d fS A B C D E F G
  • 20. z 20 DFS: Kinds of edges  DFS introduces an important distinction among edges in the original graph:  Tree edge: encounter new (white) vertex  Back edge: from descendent to ancestor  Forward edge: from ancestor to descendent  Cross edge: between a tree or subtrees  From a grey node to a black node
  • 21. z 21 DFS Example 1 |12 8 |11 13|16 14|155 | 63 | 4 2 | 7 9 |10 source vertex d f Tree edges Back edges Forward edges Cross edges
  • 22. z 22 DFS Example 1 |12 8 |11 13|16 14|155 | 63 | 4 2 | 7 9 |10 source vertex d f Tree edges Back edges Forward edges Cross edges