[英]Runtime of singe-source shortest paths in the directed acyclic graphs algorithm
Here is the Algorithm: 这是算法:
Topologically sort the Vertices of G
Initialize - Single - Source(G,s)
for each vertex u, taken in topologically sorted order
for each vertex v in G.Adjacent[u]
Relax(u,v,w)
For each vertex u , you only iterate through the edges that go out from u . 对于每一个顶点u,你只能通过从u走出边缘迭代。 Each distinct edge is visited only once, and that's why the algorithm takes O(V+E) time.
每个唯一的边缘仅被访问一次,这就是为什么该算法需要O(V + E)时间的原因。
This assumes you are using a graph representation (like adjacency lists, not a matrix) that allows quick access to every vertex's adjacent edges. 假设您使用的是图形表示形式(如邻接列表,而不是矩阵),该表示形式允许快速访问每个顶点的相邻边。 The topological sort also requires this.
拓扑排序也需要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.