Difference between Prim's and Dijkstra's algorithms?

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

    Dijkstras algorithm is used only to find shortest path.

    In Minimum Spanning tree(Prim's or Kruskal's algorithm) you get minimum egdes with minimum edge value.

    For example:- Consider a situation where you wan't to create a huge network for which u will be requiring a large number of wires so these counting of wire can be done using Minimum Spanning Tree(Prim's or Kruskal's algorithm) (i.e it will give you minimum number of wires to create huge wired network connection with minimum cost).

    Whereas "Dijkstras algorithm" will be used to get the shortest path between two nodes while connecting any nodes with each other.

提交回复
热议问题