Difference between Prim's and Dijkstra's algorithms?

前端 未结 15 1861
既然无缘
既然无缘 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:33

    Directly from Dijkstra's Algorithm's wikipedia article:

    The process that underlies Dijkstra's algorithm is similar to the greedy process used in Prim's algorithm. Prim's purpose is to find a minimum spanning tree that connects all nodes in the graph; Dijkstra is concerned with only two nodes. Prim's does not evaluate the total weight of the path from the starting node, only the individual path.

提交回复
热议问题