简体   繁体   English

无向加权图中2个顶点之间的最短路径

[英]shortest path between 2 vertices in undirected weighted graph

I am trying to find shortest path between 2 vertices in undirected weighted graph. 我试图在无向加权图中找到两个顶点之间的最短路径。 It is also known that weights are integers less than log(log|V|), where |V| 还已知权重是小于log(log | V |)的整数,其中| V | is amount of vertices. 是顶点数量。 It is easy to solve using Bellman-Ford or Dijkstra algorithms, but is there any algorithm which can do it faster? 使用Bellman-Ford或Dijkstra算法很容易解决,但是有没有算法可以更快地完成呢?

So far, I have been thinking of using BFS and dividing edges with weight greater than 1 into couple of them with weight 1, but it is not really good idea if |V| 到目前为止,我一直在考虑使用BFS将权重大于1的边分成权重为1的边,但是| V |并不是一个好主意。 is large number. 数量很多。 No, it is not my homework, I am just wondering. 不,这不是我的作业,我只是想知道。

One way to think of this question is to improve the running time of using Dijkstra's algorithm to find the shortest path between two vertices in the undirected weighted graph. 思考此问题的一种方法是,使用Dijkstra算法查找无向加权图中两个顶点之间的最短路径,可以缩短运行时间。 So in this case, you can use a binary heap as the data structure. 因此,在这种情况下,您可以使用二进制堆作为数据结构。 A heap is a complete binary tree with the heap property that every parent node is smaller (greater) than its children nodes in the tree in a min heap (a max heap). 堆是一个完整的二叉树,具有heap属性,在最小堆(最大堆)中,每个父节点都比树中的子节点小(更大)。 Here you can use the min heap to store the cost to each node from the starting node. 在这里,您可以使用最小堆将成本从起始节点存储到每个节点。

More information about heap can be found here: https://courses.csail.mit.edu/6.006/fall10/handouts/recitation10-8.pdf 有关堆的更多信息可以在这里找到: https : //courses.csail.mit.edu/6.006/fall10/handouts/recitation10-8.pdf

With a heap, the running time of Dijkstra's algorithm can be reduced from O(V^2) to O(E log E), because selecting the minimum distance from the heap takes O(log V) (removing the minimum distance is O(1) and fixing the heap takes O(log V)) and updating distances to vertices takes O(E log V) in total (fixing heap takes O(log V) and it takes E times to examine neighbors and change costs). 对于堆,Dijkstra算法的运行时间可以从O(V ^ 2)减少到O(E log E),因为选择距堆的最小距离为O(log V)(删除最小距离为O( 1)固定堆需要O(log V)),更新顶点的距离总共需要O(E log V)(固定堆需要O(log V),检查邻居和更改成本需要E倍)。

Hope this help. 希望对您有所帮助。

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

相关问题 如何计算具有加权顶点的图的最短路径? - How to calculate the shortest path for a graph with weighted vertices? 在访问某些顶点时在加权图中找到最短路径 - Finding the shortest path in weighted graph while visiting certain vertices 最多使用 k 个顶点的有向加权图中的最短路径 - Shortest path in a directed weighted graph that uses at most k vertices 在有向完整加权图中访问所有顶点的最短路径 - Shortest path that visits all vertices in a directed complete weighted graph 加权无向图上的最长路径 - Longest path on weighted undirected graph 查找树中两个顶点之间的简单路径(无向简单图) - Finding simple path between two vertices in a tree (undirected simple graph) 无向图中给定两个顶点之间的最长简单路径 - Longest simple path between given two vertices in an undirected graph 在有向加权图中找到最短的顶点序列 - Finding shortest sequence of vertices in directed weighted graph 对于通过实加权无向图的单对最短路径,最简单的算法/解决方案是什么? - What's the simplest algorithm/solution for a single pair shortest path through a real-weighted undirected graph? 如何找到最短路径覆盖加权无向图中的一组特定边? - How to find the shortest path cover a specific set of edges in a weighted undirected graph?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM