Thursday, October 4, 2012

Lecture 8: DFS and Topological Sort

Lecture 8: DFS and Topological Sort CLRS 22.3, 22.4 Outline of this Lecture a0 Recalling Depth First Search. a0 The time-stamp structure. a0 Using the DFS for cycle detection. a0 Topological sort with the DFS. 1 What does DFS Do? Given a digraph a0 a1 a2a4a3a6a5a8a7 a9 , DFS traverses all vertices of a0 and a0 constructs a forest, together with a set of source vertices; and a0 outputs two time unit arrays, a10a12a11a14a13a16a15a18a17a20a19a21a11a22a13a23a15 . DFS Forest: DFS constructs

a forest a24 a1 a2a4a3a25a5a8a7 a26a27a9 , a collection of trees, where a7 a26 a1 a28a29a2a31a30a33a32a35a34 a10a12a11a14a13a16a15 a5 a13 a9a37a36 where DFS calls are made a38 2 A Depth First Search Example Example d e a f g c b ab c e f g d 1/10 7/8 6/9 12/1311/14root root Two source vertices a, d 3/4 2/5 original graph Question: What can we do with the returned data? 3 Classification of the Edges of a Digraph Tree edges: those on the DFS forest. The remaining edges fall in three categories: Forward edges: a2a1a0 a5 a13 a9 where a13 is a proper descen- dent of a0 in the tree. [a0 a2a1 a13 .] Back edges: a2a1a0 a5 a13 a9 , where vertex a13 is an ancestor of a0 in the tree. [a0 a1 a13 is allowed.] Cross edges: a2a1a0 a5 a13 a9 where a0 and a13 are not ances- tors or descendents of one another (in fact, the edges may go between different trees). 4 Example of the Classification of Edges d e a f g c b ab c e f g d 1/10 7/8 6/9 12/1311/14root root 3/4 2/5 F C B C CC C: cross, F: forward, B: back edge original graph Remark: Since the forest obtained with the DFS is not unique, the classification is not unique. 5 Time-Stamp Structure in DFS There is also a nice structure to the time stamps, which is referred to as Parenthesis Structure. Lemma 1 Given a digraph a0 a1 a2a4a3a6a5 a7 a9 , any DFS For- est for a0 , and any two vertices a0 a5 a13 a0 a3 , a0 a0 is a descendent of a13 in the DFS forest if and only if a11a14a10a12a11 a0 a15 a5 a19 a11 a0 a15 a15 is a subinterval of a11 a10a12a11a22a13a23a15 a5 a19 a11a14a13a16a15 a15 : a10a12a11a22a13a23a15a2a1 a10a12a11 a0 a15a3a1 a19 a11 a0 a15a3a1 a19 a11a14a13a16a15 a0 a0 is unrelated to a13 in the DFS forest if and only if a11a14a10a12a11 a0 a15 a5 a19 a11 a0 a15 a15 and a11a14a10a12a11a14a13a16a15 a5 a19 a11a14a13a16a15 a15 are disjoint intervals: a19 a11 a0 a15a3a1 a10a12a11a22a13a23a15 or a19 a11a14a13a16a15a3a1 a10a12a11 a0 a15 a0 a10a12a11 a0 a15a2a1 a10a12a11a14a13a16a15a3a1 a19 a11 a0 a15a3a1 a19 a11a14a13a16a15 and a10a12a11a22a13a23a15a2a1 a10a12a11 a0 a15a3a1 a19 a11a14a13a16a15a3a1 a19 a11 a0 a15 are not possible 6 Cycles in digraphs: Applications of DFS Claim: Given a digraph, DFS can be used to...

Website: www.cse.ust.hk | Filesize: -
No of Page(s): 15
Download Lecture 8: DFS and Topological Sort - COW.pdf

No comments:

Post a Comment