开发者

Dijkstra's algorithm without "previous" vector

开发者 https://www.devze.com 2023-02-06 01:47 出处:网络
I am interested abo开发者_Python百科ut finding the minimum distance between any node in a graph and the root/source.All links have weight.I don\'t think I need to use previous[], indicated in the Wiki

I am interested abo开发者_Python百科ut finding the minimum distance between any node in a graph and the root/source. All links have weight. I don't think I need to use previous[], indicated in the Wikipedia article, since I don't need to know the parent of each node. Is that correct? Additionally, if the weights are all equal to one I guess I could just run a BFS?


It is entirely possible to implement Dijkstra's algorithm without back pointers; I know this because I've done it myself. :-) The result is that you won't be able to recover the shortest paths once you're done, but if all you need are the path lengths that should be perfectly fine.

As for your second question, yes, you can just use a BFS in a direct with unit weights. Dijkstra's algorithm visits nodes in the order that they would be encountered in a BFS if all the edges have the same positive cost.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号