SlideShare a Scribd company logo
WEEK 13
Graphs V
Depth-First Search, Depth-First
Spanning Tree, Biconnectivity
CE222 – Data Structures & Algorithms II
Chapter 9.6.1, 9.6.2
(based on the book by M. A. Weiss, Data Structures and Algorithm Analysis in C++, 3rd edition, 2006)
2012-2013 Spring
Depth First Search
• Depth-first search is a generalization of preorder traversal.
• Starting at some vertex, v, we process v and then recursively
traverse all vertices adjacent to v.
• If this process is performed on a tree, then all tree vertices
are systematically visited in a total of O(|E|) time
• Preorder traversal :
– Visit Root
– Visit Left Subtree
– Visit Right Subtree
2
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Depth First Search
• If we perform this process on an arbitrary
graph, we need to be careful to avoid cycles.
• To do this, when we visit a vertex v, we mark
it visited, since now we have been there, and
recursively call depth-first search on all
adjacent vertices that are not already marked.
3
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Depth First Search Algorithm
void dfs( vertex v )
{
visited[v] = TRUE;
for each w adjacent to v
if( !visited[w] )
dfs( w );
}
4
Because this
strategy guarantees
that each edge is
encountered only
once, the total time
to perform the
traversal is O(|E| + |
V|), as long as
adjacency lists are
used.
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Depth First Spanning Tree
The root of the tree is A, the first vertex visited. Each edge
(v, w) in the graph is present in the tree:
•If, when we process (v, w), we find that w is unmarked, or
if, when we process (w, v), we find that v is unmarked, we
indicate this with a tree edge.
•If, when we process (v, w), we find that w is already
marked, and when processing (w, v), we find that v is
already marked, we draw a dashed line, which we will call a
back edge, to indicate that this "edge" is not really part of
the tree.
5
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Undirected graph and Depth First Spanning Tree
6
A preorder numbering of the tree (using only tree edges) will tell
us the order in which vertices are marked. Preorder traversal, in
this case, is:
Visit Root, Visit Children.
If the tree is not connected then processing all nodes requires
several calls to dfs  depth first spanning forest
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
• A connected undirected graph is biconnected if
there are no vertices whose removal disconnects the
rest of the graph.
Example :
If the nodes are computers and the edges are links,
then if any computer goes down, network mail is
unaffected, except, of course, at the down
computer.
Biconnectivity
7
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity
• If a graph is not biconnected, the vertices
whose removal would disconnect the graph
are known as articulation points. These nodes
are critical in many applications.
8
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity
• The graph below is not biconnected: C and D
are articulation points. The removal of C
would disconnect G, and the removal of D
would disconnect E and F, from the rest of the
graph
9
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity
• Depth-first search provides a linear-time
algorithm to find all articulation points in a
connected graph.
1. Starting at any vertex, perform a depth-first search
and number the nodes as they are visited: num(v).
2. For every vertex v in the depth-first spanning tree,
compute the lowest-numbered vertex called low(v),
that is reachable from v by taking zero or more tree
edges and then possibly one back edge (in that
order).
10
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity
• The depth-first spanning tree shows the
preorder number first, and then the
lowest-numbered vertex reachable
• (For each node num/low is given in the tree)
11
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity
• The lowest-numbered vertex , low(v), can be efficiently
computed by performing a postorder traversal of the
depth-first spanning tree, and it is the minimum of
1) num(v)
2) the lowest num(w) among all back edges (v, w)
3) the lowest low(w) among all tree edges (v, w)
12
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
Biconnectivity: How to decide
Articulation Points
• The root is an articulation point if and only if it has more
than one child (because if it has two children, removing
the root disconnects nodes in different subtrees, and if it
has only one child, removing the root merely disconnects
the root.)
• Any other vertex v is an articulation point if and only if v
has some child w such that low(w) ≥ num(v).
Example:
Vertex D is an articulation point
 low(E)= 4 ≥ num(D)=4
Vertex C is an articulation point
 low(G)= 7 ≥ num(C)=3
13
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
1) Computing num(v)
• A preorder
traversal to
compute
num(v).
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
14
2) Computing low(v)
• A postorder
traversal to
compute
low(v).
• To save a third
traversal for
finding
articulation
points, it is also
incorporated
into the second
pass.
CE 222-Data Structures & Algorithms II,
Izmir University of Economics
15
Articulation point algorithm
(All phases combined)
16
Do not forget to study Figures 9.65, 9.66, and 9.67! (assigning
num(v) and low(v) and finding articulation points)
CE 222-Data Structures & Algorithms II,
Izmir University of Economics

More Related Content

What's hot

DATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptxDATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptx
ShivamKrPathak
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
sana younas
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahniHitesh Wagle
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
Amit Kumar Rathi
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
Syed Maniruzzaman Pabel
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
Subid Biswas
 
Graph Algorithms
Graph AlgorithmsGraph Algorithms
Graph Algorithms
Ashwin Shiv
 
Data structures using c
Data structures using cData structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
ArijitDhali
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
Tanmay Baranwal
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
Rezwan Siam
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
oneous
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
Ikhlas Rahman
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
mansab MIRZA
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
Bhavik Vashi
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 

What's hot (20)

DATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptxDATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptx
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Graph Algorithms
Graph AlgorithmsGraph Algorithms
Graph Algorithms
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 

Viewers also liked

2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
Krish_ver2
 
BFS
BFSBFS
1.5 weka an intoduction
1.5 weka an intoduction1.5 weka an intoduction
1.5 weka an intoduction
Krish_ver2
 
5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
Krish_ver2
 
2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s 2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s
Krish_ver2
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
Krish_ver2
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classification
Krish_ver2
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
Krish_ver2
 
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
 
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
Amrinder Arora
 

Viewers also liked (15)

2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
BFS
BFSBFS
BFS
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
1.5 weka an intoduction
1.5 weka an intoduction1.5 weka an intoduction
1.5 weka an intoduction
 
5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
 
2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s 2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classification
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in 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
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 

Similar to 2.5 graph dfs

Graphs
GraphsGraphs
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
Balaji Ganesan
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
king779879
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
Savit Chandra
 
Unit 4.2(graphs)
Unit 4.2(graphs)Unit 4.2(graphs)
Unit 4.2(graphs)
DurgaDeviCbit
 
Graph Traversals
Graph TraversalsGraph Traversals
Graph Traversals
MaryJacob24
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
LakshyaBaliyan2
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
ae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.pptae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.ppt
Sushilkumar Jogdankar
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
AyeshaTakreem1
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
Graph
GraphGraph
Ppt 1
Ppt 1Ppt 1
Topological Sort
Topological SortTopological Sort
Topological Sort
Dr Sandeep Kumar Poonia
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsAakash deep Singhal
 
Graphs
GraphsGraphs
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti
 

Similar to 2.5 graph dfs (20)

Graphs
GraphsGraphs
Graphs
 
ALG5.1.ppt
ALG5.1.pptALG5.1.ppt
ALG5.1.ppt
 
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
8150.graphs
8150.graphs8150.graphs
8150.graphs
 
Unit 4.2(graphs)
Unit 4.2(graphs)Unit 4.2(graphs)
Unit 4.2(graphs)
 
Graph Traversals
Graph TraversalsGraph Traversals
Graph Traversals
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
ae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.pptae_722_unstructured_meshes.ppt
ae_722_unstructured_meshes.ppt
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Graph
GraphGraph
Graph
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
Topological Sort
Topological SortTopological Sort
Topological Sort
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Graphs
GraphsGraphs
Graphs
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 

More from Krish_ver2

5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
Krish_ver2
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
Krish_ver2
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
Krish_ver2
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
Krish_ver2
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
Krish_ver2
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
Krish_ver2
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
Krish_ver2
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
Krish_ver2
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
Krish_ver2
 
4.2 bst 02
4.2 bst 024.2 bst 02
4.2 bst 02
Krish_ver2
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
Krish_ver2
 

More from Krish_ver2 (20)

5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
 
4.2 bst 02
4.2 bst 024.2 bst 02
4.2 bst 02
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

2.5 graph dfs

  • 1. WEEK 13 Graphs V Depth-First Search, Depth-First Spanning Tree, Biconnectivity CE222 – Data Structures & Algorithms II Chapter 9.6.1, 9.6.2 (based on the book by M. A. Weiss, Data Structures and Algorithm Analysis in C++, 3rd edition, 2006) 2012-2013 Spring
  • 2. Depth First Search • Depth-first search is a generalization of preorder traversal. • Starting at some vertex, v, we process v and then recursively traverse all vertices adjacent to v. • If this process is performed on a tree, then all tree vertices are systematically visited in a total of O(|E|) time • Preorder traversal : – Visit Root – Visit Left Subtree – Visit Right Subtree 2 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 3. Depth First Search • If we perform this process on an arbitrary graph, we need to be careful to avoid cycles. • To do this, when we visit a vertex v, we mark it visited, since now we have been there, and recursively call depth-first search on all adjacent vertices that are not already marked. 3 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 4. Depth First Search Algorithm void dfs( vertex v ) { visited[v] = TRUE; for each w adjacent to v if( !visited[w] ) dfs( w ); } 4 Because this strategy guarantees that each edge is encountered only once, the total time to perform the traversal is O(|E| + | V|), as long as adjacency lists are used. CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 5. Depth First Spanning Tree The root of the tree is A, the first vertex visited. Each edge (v, w) in the graph is present in the tree: •If, when we process (v, w), we find that w is unmarked, or if, when we process (w, v), we find that v is unmarked, we indicate this with a tree edge. •If, when we process (v, w), we find that w is already marked, and when processing (w, v), we find that v is already marked, we draw a dashed line, which we will call a back edge, to indicate that this "edge" is not really part of the tree. 5 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 6. Undirected graph and Depth First Spanning Tree 6 A preorder numbering of the tree (using only tree edges) will tell us the order in which vertices are marked. Preorder traversal, in this case, is: Visit Root, Visit Children. If the tree is not connected then processing all nodes requires several calls to dfs  depth first spanning forest CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 7. • A connected undirected graph is biconnected if there are no vertices whose removal disconnects the rest of the graph. Example : If the nodes are computers and the edges are links, then if any computer goes down, network mail is unaffected, except, of course, at the down computer. Biconnectivity 7 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 8. Biconnectivity • If a graph is not biconnected, the vertices whose removal would disconnect the graph are known as articulation points. These nodes are critical in many applications. 8 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 9. Biconnectivity • The graph below is not biconnected: C and D are articulation points. The removal of C would disconnect G, and the removal of D would disconnect E and F, from the rest of the graph 9 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 10. Biconnectivity • Depth-first search provides a linear-time algorithm to find all articulation points in a connected graph. 1. Starting at any vertex, perform a depth-first search and number the nodes as they are visited: num(v). 2. For every vertex v in the depth-first spanning tree, compute the lowest-numbered vertex called low(v), that is reachable from v by taking zero or more tree edges and then possibly one back edge (in that order). 10 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 11. Biconnectivity • The depth-first spanning tree shows the preorder number first, and then the lowest-numbered vertex reachable • (For each node num/low is given in the tree) 11 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 12. Biconnectivity • The lowest-numbered vertex , low(v), can be efficiently computed by performing a postorder traversal of the depth-first spanning tree, and it is the minimum of 1) num(v) 2) the lowest num(w) among all back edges (v, w) 3) the lowest low(w) among all tree edges (v, w) 12 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 13. Biconnectivity: How to decide Articulation Points • The root is an articulation point if and only if it has more than one child (because if it has two children, removing the root disconnects nodes in different subtrees, and if it has only one child, removing the root merely disconnects the root.) • Any other vertex v is an articulation point if and only if v has some child w such that low(w) ≥ num(v). Example: Vertex D is an articulation point  low(E)= 4 ≥ num(D)=4 Vertex C is an articulation point  low(G)= 7 ≥ num(C)=3 13 CE 222-Data Structures & Algorithms II, Izmir University of Economics
  • 14. 1) Computing num(v) • A preorder traversal to compute num(v). CE 222-Data Structures & Algorithms II, Izmir University of Economics 14
  • 15. 2) Computing low(v) • A postorder traversal to compute low(v). • To save a third traversal for finding articulation points, it is also incorporated into the second pass. CE 222-Data Structures & Algorithms II, Izmir University of Economics 15
  • 16. Articulation point algorithm (All phases combined) 16 Do not forget to study Figures 9.65, 9.66, and 9.67! (assigning num(v) and low(v) and finding articulation points) CE 222-Data Structures & Algorithms II, Izmir University of Economics