Shortest sequence of nodes though an unweighted graph

会有一股神秘感。 提交于 2019-12-05 16:41:54

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.

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