문제

If all edges had the same weight in a given graph, will Dijkstra's algorithm still find the shortest path between 2 vertices? Thanks!

도움이 되었습니까?

해결책

Yes dijkstra algorithm can find the shortest path even when all edges have the same weight. dijkstra has time complexity O((V+E)logV).Instead you should choose BFS algorithm to do the same thing,because BFS has time complexity O(V+E),so BFS is asymptotically faster than dijkstra.

다른 팁

Yes it would, But you might want to take a look at Breadth-first search, wich solves the case you are refering to. To find the path, you can make a recursive function that starts in the destiny node with flagged distance n, and moves to one of the neightbour nodes with flagged distance n-1

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top