Difference between Prim's and Dijkstra's algorithms?

前端 未结 15 1856
既然无缘
既然无缘 2020-12-07 06:53

What is the exact difference between Dijkstra\'s and Prim\'s algorithms? I know Prim\'s will give a MST but the tree generated by Dijkstra will also be a MST. Then what is

15条回答
  •  佛祖请我去吃肉
    2020-12-07 07:29

    Dijkstra's algorithm doesn't create a MST, it finds the shortest path.

    Consider this graph

           5     5
      s *-----*-----* t
         \         /
           -------
             9
    

    The shortest path is 9, while the MST is a different 'path' at 10.

提交回复
热议问题