[英]Minimum Weighted Path Tree of an Undirected Graph
Assume that we have an undirected graph G=(V,E) and we have two nodes S and X. 假设我们有一个无向图G =(V,E)并且我们有两个节点S和X.
I don't know if minimum spanning tree will solve it or not, but it's certainly solvable by making some modifications to Dijkstra's algorithm. 我不知道最小生成树是否可以解决它,但是通过对Dijkstra算法进行一些修改,它肯定可以解决。
Define the "length" of a path as the maximum edge in that path. 将路径的“长度”定义为该路径的最大边缘。 Now find the shortest path from S to X using Dijkstra's algorithm. 现在,使用Dijkstra算法找到从S到X的最短路径。 This is the path you are looking for. 这是您要寻找的路径。 Complexity is O((N+M)log N)
if you use a binary heap and O(N * log N + M)
with a Fibonacci heap. 如果使用二进制堆,则复杂度为O((N+M)log N)
O(N * log N + M)
,而对于Fibonacci堆,复杂度为O((N+M)log N)
O(N * log N + M)
。
Note that for this new definition of path length, if the length of a path is l
, then adding an edge to the end of the path will not decrease it's length, since the maximum edge in that path can only increase. 请注意,对于路径长度的这个新定义,如果路径的长度为l
,则在路径的末尾添加边缘不会减小其长度,因为该路径中的最大边缘只能增加。 This property is necessary for Dijkstra's algorithm to work correctly. 该属性对于Dijkstra的算法正常工作是必需的。
For instance, if you were looking for the path with the shortest edge, then Dijkstra's algorithm will fail just like it fails when there are negative edges in the graph. 例如,如果您正在寻找边缘最短的路径,则Dijkstra的算法将失败,就像图形中存在负边缘时失败一样。
You can use minimum spanning tree (Prim's algorithm) to solve this problem. 您可以使用最小生成树(Prim算法)来解决此问题。 You will start with vertex S
, then continue to build the tree using Prim's algorithm until you find X
. 您将从顶点S
开始,然后继续使用Prim的算法构建树,直到找到X
为止。 Complexity will be O((V+E)*logV). 复杂度将为O((V + E)* logV)。
It will work because in the prim's algorithm you always choose the edge with minimum weight first. 之所以会起作用,是因为在prim的算法中,您总是首先选择权重最小的边缘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.