finding strongly connected components directed acyclic
play

Finding Strongly Connected Components Directed Acyclic Graphs - PowerPoint PPT Presentation

Finding Strongly Connected Components Directed Acyclic Graphs Directed Acyclic Graphs Directed Acyclic Graphs (DAG) A directed acyclic graph (or DAG for short) is a directed graph that contains no cycles. Note that the direction of edges is


  1. Finding Strongly Connected Components

  2. Directed Acyclic Graphs

  3. Directed Acyclic Graphs Directed Acyclic Graphs (DAG) A directed acyclic graph (or DAG for short) is a directed graph that contains no cycles. Note that the direction of edges is important. Cycles + DFS ◮ A graph contains a cycle if and only if a DFS produces a back edge. ◮ Thus, if a graph is acyclic, a DFS on this graph produces no back edges. Partial orders ◮ Relation which is transitive, reflexive, and antisymmetric. ◮ For each partial order there is a corresponding DAG and vice versa. 3 / 13

  4. Sources and Sinks Source and Sink In a DAG, a source is a vertex without incoming edges; a sink is a vertex without outgoing edges. Lemma Each DAG contains at least one source and one sink. Observation ◮ After removing a source or a sink from a DAG, the resulting graph is still a DAG. ◮ If a vertex is the only source/sink removing it creates a new source/sink. 4 / 13

  5. Topological Order Topological Order For a directed graph, a topological order is an order v 1 , v 2 , . . . , v n ( v i � = v j ↔ i � = j ) of its vertices such that ( v i , v j ) ∈ E implies i < j . Lemma Each DAG has a topological order. Finding a topological order ◮ A post-order on a DFS-tree gives a topological order. 5 / 13

  6. Strongly Connected Components

  7. Strongly Connected Component Strongly Connected Component A directed graph is strongly connected if every vertex is reachable from every other vertex. A strongly connected component is a maximal subgraph which is strongly connected. A graph with three strongly connected components. 7 / 13

  8. SCC-Graph S ( G ) SCC-Graph S ( G ) ◮ Assume, G has SCCs S 1 , S 2 , . . . , S k . ◮ For each SCC S i in G , create a vertex v i in S ( G ) . ◮ Add an edge ( v i , v j ) to S ( G ) , if there are two vertices u i and u j in G with u i ∈ S i , u j ∈ S j and ( u i , u j ) ∈ E . S ( G ) G 8 / 13

  9. SCC-Graph S ( G ) Lemma For a directed graph G , S ( G ) is acyclic. Lemma All vertices in an SCC S are descendants of its first vertex in a DFS-tree. If v is the first vertex of a SCC S in a DFS-tree, we will call v the root of S . Conclusion ◮ SCCs have topological order ◮ Post-order of roots in DFS-tree (of G ) gives topological order of SCCs 9 / 13

  10. Sink-SCC Assume, SCC S is a sink in S ( G ) and has root v . Let D [ v ] be the descendants of v (including v ). Observations ◮ There are no edges from S to another SCC. ◮ For each u ∈ D [ v ] ( u � = v ), there is a path back to v . Theorem A vertex v is the root of a sink S in S ( G ) if and only if, for all u ∈ D [ v ] , ( i ) ( u , w ) ∈ E implies w ∈ D [ v ] , and ( ii ) if u � = v , there is an x ∈ D [ u ] with ( x , y ) ∈ E and y / ∈ D [ u ] . 10 / 13

  11. Proof of Theorem ( → ) ◮ S is sink, i. e., for all ( u , w ) ∈ E , u ∈ S implies w ∈ S and u ∈ D [ v ] . ◮ If u � = v , then there is a path back to v . Thus, u has descendant x with ( x , y ) ∈ E , y / ∈ D [ u ] . ( ← ) (1) Assume, v is not root. ◮ There is a path P from v to an ancestor r . ◮ Thus, there is an edge ( u , w ) where u is descendant and w is not. (2) Assume S is not sink. ◮ There is another SCC reachable from v which is sink and has a root r . ◮ Because of ( i ) and ( → ) , r ∈ D [ v ] and, for all x ∈ D [ r ] , ( x , y ) ∈ E implies y ∈ D [ r ] . (Contradiction with ( ii ) ) 11 / 13

  12. Algorithm – Identify a Root of a Sink Assume there is a u ∈ D [ v ] with ( u , w ) ∈ E and w / ∈ D [ v ] ◮ ( u , w ) is cross or back edge. ◮ Therefore, w was visited in DFS before v . Lowpoint low ( v ) ◮ The lowest pre-order index pre ( w ) of a vertex w which is in the (outgoing) neighbourhood of any descendant of v (including v ). ◮ low ( v ) := min � � pre ( v ) , min { pre ( w ) | ( u , w ) ∈ E , u ∈ D [ v ] } ◮ Computable with post-order traversal. Theorem A vertex v is the root of a sink S in S ( G ) if and only if ( i ) pre ( v ) ≤ low ( v ) and ( ii ) pre ( u ) > low ( u ) for all u ∈ D [ v ] with u � = v . 12 / 13

  13. Algorithm – Identify Remaining Roots Naive strategy ◮ Identify roots of sinks. Descendant of v (including v ) are corresponding SCCs. ◮ Remove corresponding SCCs from graph. ◮ Repeat. Observation ◮ We identify roots by post-order. ◮ In a DAG, the first vertex in post-order is last vertex in topological order. ◮ Therefore, we process a root of a sink before all other roots. New strategy ◮ After identifying first root, “remove” † corresponding sink before continuing with DFS. † Flagging as removed an ignore later is sufficient. 13 / 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend