CSCE 411 Lecture 19

From Notes
Jump to navigation Jump to search
Lecture Slides

« previous | Wednesday, October 10, 2012 | next »


Strongly Connected Components

A directed graph is strongly connected iff you can go from any node to any other node

A strongly connected component (SCC) is a maximal set of nodes with a directed path between every pair of nodes.

For example: Packaging software modules

  • Construct directed graph of which modules call which other modules
  • SCC is a set of mutually interacting modules
  • Put those modules in the same SCC

Algorithm

DFS tells us which nodes are reachable from roots of individual trees, but we need information about the "other direction": is the root reachable from its descendants? (reverse direction of edges)

  1. Call DFS() to compute finishing times ()
  2. Compute (transpose of adjacency matrix graph; reverse direction of all edges) (; assuming adjacency list)
  3. Call DFS(), considering nodes in decreasing order of finishing times ()
  4. Each tree from (3) is a separate SCC of


Total running time:

Example

CSCE 411 Strongly Connected Components.png

Finish times for step 1:

1 2 3     4 5     6 7 8     9 10 11 12 13    14 15 16
| | '--c--' '--d--' | '--e--'  |  |  |  '--h--'  |  |
| '--------b--------'          |  |  '-----g-----'  |
'---------------a--------------'  '--------f--------'

Thus order of nodes for step 3 is: f, g, h, a, e, b, d, c

Finish times for step 2:

1 2 3     4 5 6 7 8     9 10 11 12    13 14 15    16
| | '--g--' | | | '--e--'  |  |  '--c--'  |  '--d--'
| '----h----' | '----a-----'  '-----b-----'
'------f------'

Thus {f, h, g}, {a,e}, {b,c}, and {d} are SCCs


Correctness

Let represent a strongly connected component in

Draw a graph using 's as vertices, and edges from to iff has an edge from a vertex in to a vertex in .

The resulting graph does not have any cycles.

Proof

Let be the earliest discovery time of any node in , and likewise let be the latest finishing time in .

We claim that if there is an edge in from component to

Case 1: . Suppose is the first node discovered in . DFS would take all nodes in and as descendents of , so is the last node in to finish and finishes after all nodes in . Thus

Case 2: . Suppose is the first node discovered in . DFS would accept all nodes in as descendents of , so is the last node to finish. Since , no node in is reachable from , so finishes before any node in is discovered. Thus

Induction on number of trees in step 3 (Calling DFS on ): The first trees found constitute SCCs of .

Basis: , no work to do.

Induction: Assume the first trees constructed in step 3 correspond to SCCs. Consider the st tree: (let be the root of the st tree) is part of SCC , and by inductive hypothesis, is one of SCCs already found, and all nodes in are unvisited when is discovered.

Q.E.D.