简体   繁体   English

设计一个在时间O(k(| V | + | E |))运行的单源最短路径问题的算法

[英]Design an algorithm for the single source shortest path problem that runs in time O(k(|V|+|E|))

Suppose we are given a directed graph G = (V, E) with potentially positive and negative edge lengths, but no negative cycles. 假设我们给出了有向图G = (V, E)具有潜在的正和负边长,但没有负循环。 Let s ∈ V be a given source vertex. s ∈ V是给定的源顶点。 How to design an algorithm for the single-source shortest path problem that runs in time O(k(|V | + |E|)) if the shortest paths from s to any other vertex takes at most k edges ? 如果从s到任何其他顶点的最短路径最多需要k edges如何设计一个在时间O(k(|V | + |E|))中运行的单源最短路径问题的算法?

Here`s O(k(|V | + |E|)) approach: 这里是O(k(| V | + | E |))方法:

  1. We can use Bellman-Ford algorithm with some modifications 我们可以使用Bellman-Ford算法进行一些修改
  2. Create array D[] to store shortest path from node s to some node u 创建数组D []以存储从节点s到某个节点u的最短路径
  3. initially D[s]=0, and all other D[i]=+oo (infinity) 最初D [s] = 0,所有其他D [i] = + oo(无穷大)
  4. Now after we iterate throught all edges k times and relax them, D[u] holds shortest path value from node s to u after <=k edges 现在,在我们遍历所有边缘k次并放松它们之后,D [u]在<= k edge之后保持从节点s到u的最短路径值
  5. Because any su shortest path is atmost k edges, we can end algorithm after k iterations over edges 因为任何su最短路径最多是k个边缘,所以我们可以在边缘上的k次迭代之后结束算法

    Pseudocode: 伪代码:

    for each vertex v in vertices: 对于顶点中的每个顶点v:
    D[v] := +oo D [v]:= + oo

    D[s] = 0 D [s] = 0

    repeat k times: 重复k次:
    for each edge (u, v) with weight w in edges: 对于边缘重量为w的每条边(u,v):
    if D[u] + w < D[v]: 如果D [u] + w <D [v]:
    D[v] = D[u] + w D [v] = D [u] + w

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 O(V + E) 时间内在加权无向图中找到从源到目标的最短路径 - Find the shortest path from source to target in a weighted-undirected graph in O(V + E) time Dijkstra算法在O((V + E)log W)时间内计算给定源顶点的最短路径 - Dijkstra’s algorithm to compute the shortest paths from a given source vertex s in O ((V+E) log W) time 对于给定的图 G=(V,E) 和边 e∈E,设计一个 O(n+m) 时间的算法来寻找(如果存在)包含 e 的最短循环 - For a given graph G=(V,E) and an edge e∈E, design an O(n+m)-time algorithm to find, if it exists, the shortest cycle that contains e K个负边-单一来源最短路径 - K negative edges - single source shortest path 单源最短路径问题的算法 - algorithm for singe source shortest path problem 最短路径算法设计 - Shortest path algorithm design 为什么要进行拓扑排序以找到最短路径O(V + E) - Why is Topological Sorting to find the shortest path O(V+E) 设计一个O(| V | + | E |)时间算法,该算法可找到有向图的根顶点(或报告不存在) - Design a O(|V | + |E|) time algorithm that finds a root vertex (or reports that none exists) of a directed graph 编程竞赛的最佳单源最短路径算法是什么? - What is the best single-source shortest path algorithm for programming contests? 单源最短算法 - single-source shortest algorithm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM