Skip to content
Related Articles

Related Articles

Difference between Minimum Spanning Tree and Shortest Path

View Discussion
Improve Article
Save Article
  • Last Updated : 01 Jul, 2021
View Discussion
Improve Article
Save Article

Spanning tree: A spanning tree (T) of an undirected graph(G) is a subgraph which is a tree that includes all the vertices of a graph (G) and the minimum number of edges required to connect the graph (G). And it is a known maximal set of edges with no cycles.


  • If a graph(G) is not connected then it does not contain a spanning tree (i.e. it has many spanning-tree forests).
  • If a graph(G) has V vertices then the spanning tree of that graph G has V-1 edges.
  • In the case of a complete (Kn) undirected, labeled, and unweighted graph, the number of possible spanning trees can be found out By using Cayley’s formula: Kn = nn-2.
  • For the K3 graph (i.e. complete graph of 3 vertices) the number of possible spanning trees is 33-2 = 31= 3.

Possible spanning trees in K3 graph

  • The number of minimum spanning trees of a graph other than a complete graph can find out by using the Kirchhoff theorem.

The Shortest path:

Shortest path(A, B, D, E) between vertices A and E in the weighted directed graph

  • The shortest path between any two vertices (say between A and E) in a graph such that the sum of weights of edges that are present in the path (i.e. ABDE) is minimum among all possible paths between A and E.
  • The shortest path can find out for graphs which are directed, undirected or mixed.
  • The problem for finding the shortest path can be categorized as
    • Single-source the shortest path: In this, the shortest path is calculated from a source vertex to all other vertices present inside the graph.
    • Single-destination the shortest path: In this, the shortest path is calculated from all vertices in the directed graph to a single destination vertex. This can be converted into a single pair with the shortest path problem by reversing the edges of the directed graph.
    • All pairs the shortest path: In this, the shortest path is calculated between every pair of vertices.

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.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!