Find the lowest-weight cycle in a weighted, directed graph using Dijkstra's

不想你离开。 提交于 2020-06-29 04:31:20

问题


Hi I am struggling with this question. It is the following:

Devise an algorithm to find the lowest-weight cycle(i.e. of all cycles in the graph, the one with the smallest sum of edge weights), in a weighted, directed graph G = (V,E). Briefly justify the runtime and space complexity. Assume all edges are non-negative. It should run in O(|V||E|log|V|) time. Hint: Use multiple calls to Dijkstra's algorithm.

I have seen solutions that use Floyd-Warshall but I was wondering how we would do this using Dijkstra's and how to do it within the time constraint given.

I have a few points of confusion:

  • Firstly, how do we even know how many cycles are in the graph and how to check those?
  • Also, why is it |E||V|log|V|? By my understanding you should traverse through all the vertices therefore making it |V|log|V|.

This is for my personal learning so if anyone has an example they could use, it would greatly help me! I am not really looking for pseudo-code - just a general algorithm to understand how using the shortest path from one node to all nodes is going to help us solve this problem. Thank you!


回答1:


Call Dijkstra's algorithm from each vertex to find the shortest path to itself, if one exists. The shortest path from any vertex to itself is the smallest cycle. Dijkstra's algorithm takes O(|E| log |V|), so total time is O(|V||E| log |V|).

Note that this time can be worse than Floyd-Warshall, because there can be O(|V|^2) edges in the graph.




回答2:


Call Dijkstra's algorithm |V| times, using each vertex in V as the start vertex. Store the results in a matrix, where dist(u,v) is the shortest path length from u to v. For each pair of vertices (u,v), dist(u,v) is the shortest parth from u to v and dist(v,u) is the shortest path from v to u. Therefore, dist(u,v) + dist(v, u) is the length of the lowest weight cycle containing u and v. For each pair of vertices, computer this value and take the minimum. This is the lowest weigtht cycle.



来源:https://stackoverflow.com/questions/47491806/find-the-lowest-weight-cycle-in-a-weighted-directed-graph-using-dijkstras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!