06 - Depth-First Search and Its Applications

06 - Depth-First Search and Its Applications - Part II:...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Part II: Graph Algorithms Lecture 6: Depth-First Search and Its Applications Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms Intro to Part II: What are graphs? A graph is a pair G = ( V , E ), where V is the collection of vertices , and E is the collection of edges . V = { , 1 , 2 , . . . , 10 } E = { (0 , 1) , (1 , 0) , (1 , 2) , (2 , 1) , . . . , (10 , 5) , . . . } Directed graph : if ( u , v ) ∈ E , then ( v , u ) / ∈ E . Undirected graph : if ( u , v ) ∈ E , then ( v , u ) ∈ E . Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms Intro to Part II: Representations of graphs Adjacency list representation : Adj [ u ] — linked list of all v such that ( u , v ) ∈ E . Adj [0] = { 1 , 3 , 9 } ; Adj [1] = { , 9 , 2 } ; . . . Adjacency-matrix representation : A = [ a ij ], a ij = 1 if ( v i , v j ) ∈ E . Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms Intro to Part III:Why study graph algorithms Graphs are a pervasive data structure in Computer Science. Algorithms for working with graph are fundamental to Computer Science. Hundreds of interesting computational problems defined on graphs. We will sample a few basic ones. Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms Objective and Outline of Lecture 6 Objective : Discuss an elementary graph algorithm, i.e. depth-first search (DFS). Reference : Chapter 22 of CLRS Outline: The DFS Algorithm Analyzing the DFS algorithm Properties of DFS. Applications of DFS Articulation points. Bi-connected components Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms The DFS Algorithm What does DFS do? Traverse all vertices in graph, and thereby Reveal properties of the graph. Four arrays are used to keep information gathered during traversal 1 color [ u ] : the color of each vertex visited white: undiscovered gray: discovered but not finished processing black: finished processing 2 pred [ u ] : the predecessor pointer pointing back to the vertex from which u was discovered 3 d [ u ] : the discovery time a counter indicating when vertex u is discovered 4 f [ u ] : the finishing time a counter indicating when the processing of vertex u (and all its descendants) is finished Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms The DFS Algorithm How does DFS work? It starts from an initial vertex. After visiting a vertex, it recursively visits all of its neighbors. The strategy is to search “ deeper ” in the graph whenever possible Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms DFS Algorithm DFS(G) // Initialize foreach u in V do color[u] = white; pred[u] = NULL; end time= 0; foreach u in V do // start a new tree if color[u] = white then DFSVisit(u) end Lecture 6: Depth-First Search and Its Applications Part II: Graph Algorithms DFSVisit(u) color[u] = gray; // u is discovered d[u] = ++time; // u’s discovery time foreach...
View Full Document

This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.

Page1 / 36

06 - Depth-First Search and Its Applications - Part II:...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online