Why use Dijkstra's Algorithm if Breadth First Search (BFS) can do the same thing faster?

后端 未结 4 1183
南笙
南笙 2020-11-30 18:47

Both can be used to find the shortest path from single source. BFS runs in O(E+V), while Dijkstra\'s runs in O((V+E)*log(V)).

Also, I\'ve s

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 19:00

    From implementation perspective, the Dijkstra's algorithm could be implemented exactly like a BFS by swapping the queue with a priority queue.

    Source

提交回复
热议问题