生成树:无向图(G)的生成树(T)是一个子图,它是一种包含图(G)的所有顶点和连接图(G)所需的最少边数的树。它是一个已知的最大边集,没有循环。
特性:
- 如果图(G)没有连通,那么它不包含生成树(即它有许多生成树森林)。
- 如果图(G)有V个顶点,则该图G的生成树有V-1 条边。
- 在完全( K n )无向、标记和未加权图的情况下,可以通过使用凯莱公式找出可能的生成树的数量: K n = n n-2 。
- 对于K 3 图(即 3 个顶点的完整图)可能的生成树的数量是3 3-2 = 3 1 = 3。
- 完全图以外的图的最小生成树数可以通过基尔霍夫定理求出。
最短路径:
- 图中任意两个顶点之间(比如A和E之间)的最短路径,使得路径中存在的边的权重总和(即ABDE )在 A和E之间的所有可能路径中最小。
- 最短路径可以找出有向图、无向图或混合图。
- 寻找最短路径的问题可以归类为
- 单源最短路径:在这种情况下,最短路径是从源顶点到图中存在的所有其他顶点计算的。
- Single-destination the shortest path:在此,最短路径是从有向图中的所有顶点到单个目标顶点计算的。通过反转有向图的边,可以将其转换为具有最短路径问题的一对。
- 所有配对最短路径:在此,最短路径是在每对顶点之间计算的。
以下是最小生成树(MST)和最短路径的区别:
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.
|
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. |