zoukankan      html  css  js  c++  java
  • Strongly Connected Components

    Decomposing a directed graph into its strongly connected components is a classic application of DFS. Two vertices of directed graph are in the same component if and only if they are reachable from each other. For example, consider the following directed graph

    Diagram

    The above directed graph has four strongly connected components, namely {abe}, {cd}, {fg} and {h}.

    From any vertex v, one can visit to any other vertex in the same component as v and then return back v; if one visits a vertex in a different component the return to v is impossible.

    The component graph for the above directed graph is

    Diagram

    The above directed graph has 4 strongly connected components: c1c2c3 and c4. If G has an edge from some vertex in ci to some vertex in cj where i ≠ j, then one can reach any vertex in cj from any vertex in ci but not return. In the example, one can reach any vertex in c3 from any vertex inc1 but cannot return to c1 from c3.

    If G = (V, E) is a directed graph, its transpose, GT = (V, ET) is the same as G with all arrows reversed.

    For example, given directed graph G = (V, E)

    Diagram

    The transpose of G = (V, E) is GT = (V, ET)

    Diagram

    From above example it is apparent that edge set ET contains edge (u, v) iff edge set E contains (u, v). This observation implies that GT has same strongly components as G and the strongly components of G are transposes of strongly components of GT.

    ALGORITHM

    A DFS(G) produces a forst of DFS-trees. Let C be any strongly connected component of G, let v be the first vertex on C discovered by the DFS and let T be the DFS-tree containing v when DFS-visit(v) is called all vertices in C are reachable from v along paths containing visible vertices; DFS-visit(v) will visit every vertex in C, add it to T as a descendant of v.

    STRONGLY-CONNECTED-COMPONENTS(G)

    1 Call DFS(G) to compute finishing time for each vertex.
    2 Compute transpose of G i.e., GT.
    3 Call DFS(GT) but this time consider the vertices in order of decreasing finish time.
    4 Out the vertices of each tree in DFS-forest.

    Example (CLR)   Consider a graph G = (V, E)

    1. Call DFS(G)

    2. Compute GT

    3. Call DFS(GT) but this time consider the vertices in order of decreasing finish time.

    First 16
    Start with 10
    Start with 7

    4. Output the vertices of each tree in the DFS-forest as a separate strongly connected component.

    {abe}, {cd}, {fg} and {h}

    The algorithm computes the strongly connected components of a directed graph G = (V, E) using two depth searches, one on G and one on GT. Thus, the total running time is linear i.e.,  (V + E).

    Before leaving strongly connected components, lets prove that component graph of G(V, E) is a directed acylic graph.

    Proof    (by contradiction)

    Suppose component graph of G = (V, E) was not a DAG and G comprised of a cycle c

    onsisting of vertices v1v2 , . . . , vn . Each vi corresponds to a strongly

    connected component (SCC) of component graph G. If v1v2 , . . . , vn

    themselves form a cycle then each vi ( i runs from 1 to n) should have been

    included in the SCC corresponding to vj ( j runs from 1 to n and i  j). But each of

    the vertices is a vertex from a difference SCC of G. Hence, we have a

    contradiction! Therefore, SCC of G is a directed acylic graph.

  • 相关阅读:
    自己常用网站记录
    css弹性布局指定显示行数多余文字去掉用省略号代替以及弹性布局中css 卡片阴影效果
    微信小程序页面传参被截取问题
    阴影效果 css3 为什么要加 -moz-box-shadow -webkit-box-shadow -o-box-shadow,直接用box-shadow不是都能识别吗?
    css常用清除浮动方式
    什么是微信小程序云开发 它的作用是什么
    JMeter压测“java.net.SocketException: Socket closed”解决方法
    Jmeter压力测试工具安装及使用教程
    OnActionExecuting和OnActionExecuted执行顺序
    C#循环下载多个文件(把多个文件压缩成一个文件可以一次性下载)
  • 原文地址:https://www.cnblogs.com/sachin/p/2691528.html
Copyright © 2011-2022 走看看