前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kosaraju算法

Kosaraju算法

作者头像
Steve Wang
发布2019-05-28 17:43:18
7930
发布2019-05-28 17:43:18
举报
文章被收录于专栏:从流域到海域

SCC

SCC = strong connected component. 即强连通分量。

In the mathematical theory of directed graphs, a graph is said to be strongly connected or diconnected if every vertex is reachable from every other vertex the strongly connected components or diconnected components of an arbitrary directed graph form a partition into subgraphs that are themselves strongly connected. (wikipedia)

强连通分量是指有向图的一个子图,在该子图中所有的结点到其他结点都是可达的。

在这里插入图片描述
在这里插入图片描述

Kosaraju算法

Kosaraju‘s algorithm (also known as the Kosaraju–Sharir algorithm)

Is a linear time algorithm to find the strongly connected components of a directed graph.

It makes use of the fact that the transpose graph (the same graph with the direction of every edge reversed) has exactly the same strongly connected components as the original graph.

Main procedure:

Traverse edges in the backward direction to get the transpose graph.

DFS the transpose graph you get, store the visit sequence in a stack

DFS the original graph using the stack.

  1. 对原图所有边的方向取反得到原图的逆图。
  2. 对逆图进行深度优先遍历,访问结点的顺序存入一个栈中(即逆后序)。
  3. 按出栈的顺序对原图进行深度优先遍历。

O(V+E) if you are using the adjacent list.

Pseudo-code

  1. For each vertex u of the graph, mark u as unvisited. Let L be empty.
  2. For each vertex u of the graph do Visit(u), where Visit(u) is the recursive subroutine: If u is unvisited then: 1. Mark u as visited. 2. For each out-neighbour v of u, do Visit(v).
    1. Prepend u to L. Otherwise do nothing.
  3. For each element u of L in order, do Assign(u,u) where Assign(u,root) is the recursive subroutine: If u has not been assigned to a component then:
    1. Assign u as belonging to the component whose root is root.
    2. For each in-neighbour v of u, do Assign(v,root). Otherwise do nothing.

参考文献

https://www.cnblogs.com/nullzx/p/6437926.html 这篇文章里有实例分析。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年11月20日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SCC
  • Kosaraju算法
    • Main procedure:
    • Pseudo-code
    • 参考文献
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档