ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Difference between MST and DIJKSTRA

2022-06-22 00:04:58  阅读:225  来源: 互联网

标签:graph MST tree DIJKSTRA minimum path spanning Difference shortest


MST -- Minumum Spinning Tree

https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/?ref=leftbar-rightbar

简化一个图, 在保证所有节点连接的前提下,最小化连接代价。

What is a Spanning Tree?

A Spanning tree is a subset to a connected graph G, where all the edges are connected, i.e, we can traverse to any edge from a particular edge with or without intermediates. Also, a spanning tree must not have any cycle in it. Thus we can say that if there are n edges in a connected graph then the maximum no. of edges that a spanning tree may have is n-1.

What is Minimum Spanning Tree? 
Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together. A single graph can have many different spanning trees. A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected, undirected graph is a spanning tree with a weight less than or equal to the weight of every other spanning tree. The weight of a spanning tree is the sum of weights given to each edge of the spanning tree.

 

例如 修路问题。

https://www.geeksforgeeks.org/minimum-cost-connect-cities/?ref=lbp

 

例如 广播的最小路由代价

https://bradfieldcs.com/algos/graphs/prims-spanning-tree-algorithm/

 

算法 --- Prims and Kruskals

https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/?ref=leftbar-rightbar

https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/?ref=rp

 

Dijkstra

https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/?ref=leftbar-rightbar

给定一个起点, 计算起点到所有节点的最短路径。

 

Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph.
Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning tree. Like Prim’s MST, we generate a SPT (shortest path tree) with a given source as a root. We maintain two sets, one set contains vertices included in the shortest-path tree, other set includes vertices not yet included in the shortest-path tree. At every step of the algorithm, we find a vertex that is in the other set (set of not yet included) and has a minimum distance from the source.
Below are the detailed steps used in Dijkstra’s algorithm to find the shortest path from a single source vertex to all other vertices in the given graph.

 

 

Difference

https://www.geeksforgeeks.org/difference-between-minimum-spanning-tree-and-shortest-path/

MST 并不能满足 最短路要求。

The followings are the difference between the Minimum spanning tree(MST) and the Shortest path:

 

Minimum spanning tree(MST) The Shortest path
In MST there is no source and no destination, but it is the subset (tree) of the graph(G) which connects all the vertices of the graph G without any cycles and the minimum possible total edge weight. There is a source and destination, and one need to find out the shortest path between them
Graph (G) should be connected, undirected, edge-weighted, labeled. It is not necessary for the Graph (G) to be connected, undirected, edge-weighted, labeled.

Here relaxation of edges is not performed but here the minimum edge weight is chosen one by one from the set of all edge weights (sorted according to min weight) and the tree is formed by them (i.e. there should not be any cycle).

Here the relaxation of edges is performed.

  • Here d(U) means the distance of source vertex S to vertex where C(U, V) is the distance between U and V.
  • If d(U) > d(V) + C(U, V) then d(U) = d(V) + C(U, V).
  • For example, 20>10+5, d(U) = 15, is the minimum distance from source vertex S to vertex U.
  • Therefore, relaxation is performed.
In this case, a minimum spanning tree can be formed but negative weights edge cycles are not generally used. Using the cycle property of MST, the minimum edge weight among all the edge weights in the negative edge cycle can be selected. If the graph is connected, and if a negative weight edge cycle present in the graph. Then the shortest path can not be computed, but the negative edge cycle can be detected using the Bellman-Ford algorithm.
In the case of a disconnected graph, the minimum spanning tree can not be formed but many spanning-tree forests can be formed. In the case of a disconnected graph, the distance between two vertices present in two different components is infinity.

Here the Greedy approach is used for finding MST for a graph, For example, Prim’s algorithm and Kruskal’s algorithm.

If there are N vertices are present inside graph G then the minimum spanning tree of the graph will contain N-1 edges and N vertices. If there are N vertices present inside graph G, then in the shortest path between two vertices there can be at most N-1 edges, and at most N vertices can be present in the shortest path.
It is used in network design (computer networks, telecommunication networks, water supply networks) and in circuit design applications, and many more. It is used to find out direction between physical locations like in Google Maps.

 

https://tousu.in/qa/?qa=841755/graph-difference-between-prims-and-dijkstras-algorithms

MST 连接所有节点,并保证总体的连接代价最小。 无源节点。

Djikstra 连接所有节点, 保证从源节点到任意节点的代价都是最小的。 有源节点。

 

Djistra 总体代价 大于 MST的总体代价。

 

Prim's algorithm constructs a minimum spanning tree for the graph, which is a tree that connects all nodes in the graph and has the least total cost among all trees that connect all the nodes. However, the length of a path between any two nodes in the MST might not be the shortest path between those two nodes in the original graph. MSTs are useful, for example, if you wanted to physically wire up the nodes in the graph to provide electricity to them at the least total cost. It doesn't matter that the path length between two nodes might not be optimal, since all you care about is the fact that they're connected.

Dijkstra's algorithm constructs a shortest path tree starting from some source node. A shortest path tree is a tree that connects all nodes in the graph back to the source node and has the property that the length of any path from the source node to any other node in the graph is minimized. This is useful, for example, if you wanted to build a road network that made it as efficient as possible for everyone to get to some major important landmark. However, the shortest path tree is not guaranteed to be a minimum spanning tree, and the sum of the costs on the edges of a shortest-path tree can be much larger than the cost of an MST.

Another important difference concerns what types of graphs the algorithms work on. Prim's algorithm works on undirected graphs only, since the concept of an MST assumes that graphs are inherently undirected. (There is something called a "minimum spanning arborescence" for directed graphs, but algorithms to find them are much more complicated). Dijkstra's algorithm will work fine on directed graphs, since shortest path trees can indeed be directed. Additionally, Dijkstra's algorithm does not necessarily yield the correct solution in graphs containing negative edge weights, while Prim's algorithm can handle this.

Hope this helps!

 

标签:graph,MST,tree,DIJKSTRA,minimum,path,spanning,Difference,shortest
来源: https://www.cnblogs.com/lightsong/p/16398843.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有