开发者

Shortest sequence of nodes though an unweighted graph

开发者 https://www.devze.com 2023-02-01 17:33 出处:网络
I would like to know if there is an algorithm for find开发者_如何学运维ing the shortest sequence of nodes though a graph from its a head node to the tail node. The graph branches out from the head nod

I would like to know if there is an algorithm for find开发者_如何学运维ing the shortest sequence of nodes though a graph from its a head node to the tail node. The graph branches out from the head node and is arbitrarily complex and converges at the tail node. All connections between nodes are unweighted.

I'm considering tackling this problem taking exploratory steps from the head and tail nodes and until the nodes from either end of the graph touch etc, but I'd like to know if a "better wheel" exists before I (re)invent one.


Use breadth first search, which runs in O(E+V). It's the fastest you'll get on an unweighted graph.


This is one of the beautiful "standard" problems of computer science. Given your description of the graph, you should first look at Dijkstra's algorithm


BFS is the best for these types of problems, even if you want to find out single node shortest path you have traverse whole graph for finding if there any other possible path other than the already obtained shortest path.

You can also draw a BFS Tree which will tell you exactly the shortest route between source and any(also single) node.

0

精彩评论

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