(Latest Revision: Nov 13, 2022)

MST Problems


An Example of An MST Problem:

G1=(V,E) is a connected undirected graph whose vertex set V is equal to {01,02,03,04,05,06,07,08,09,10,11,12}. The edges and weights of G1 are as follows, sorted by increasing weight.
edge  weight

{02,03}  01
{02,09}  02
{04,06}  03
{07,08}  04
{09,10}  05
{03,12}  06
{10,12}  07
{11,12}  08
{10,11}  09
{01,02}  10
{01,03}  11
{01,11}  12
{05,06}  13
{04,05}  14
{05,12}  15
{01,04}  16
{06,10}  17
{03,07}  18
{04,07}  19
{08,11}  20
{05,08}  21
{08,09}  22
{07,09}  23
{02,06}  24
First Part of The MST Problem: Using Kruskal's Algorithm

We can use Kruskal's algorithm to determine the edges of a minimum cost spanning tree of G1. The first phase of the algorithm is to sort all the edges by weight. However in this particular case, we don't need to do that, because the edges above are already sorted. The second phase is to go through the list in order, accepting or rejecting each edge as we go along, until the number of accepted edges is the number of vertices (nodes) minus one. We keep track of the sets of vertices that have been connected with the accepted edges. The next edge is accepted if the two ends are not already in the same set, otherwise the edge is rejected.

The work of Kruskal's Algorithm looks like this:
------------------------------------------------------
WORK SET ONE - Kruskal List (Solution to The First Part of The Problem) 
------------------------------------------------------
Using Kruskal's Algorithm to find the edges of a minimum cost spanning tree.

Initial singleton sets {01} {02} {03} {04} {05} {06} {07} {08} {09} {10} {11} {12} 

{02,03}  01 accept {01} {02,03} {04} {05} {06} {07} {08} {09} {10} {11} {12}     1 edge
{02,09}  02 accept {01} {04} {05} {06} {07} {08} {02,03,09} {10} {11} {12}       2 edges
{04,06}  03 accept {01} {05} {04,06} {07} {08} {02,03,09} {10} {11} {12}         3 edges
{07,08}  04 accept {01} {05} {04,06} {07,08} {02,03,09} {10} {11} {12}           4 edges
{09,10}  05 accept {01} {05} {04,06} {07,08} {02,03,09,10} {11} {12}             5 edges
{03,12}  06 accept {01} {05} {04,06} {07,08} {11} {02,03,09,10,12}               6 edges
{10,12}  07 reject {01} {05} {04,06} {07,08} {11} {02,03,09,10,12}
{11,12}  08 accept {01} {05} {04,06} {07,08} {02,03,09,10,11,12}                 7 edges
{10,11}  09 reject {01} {05} {04,06} {07,08} {02,03,09,10,11,12}
{01,02}  10 accept {05} {04,06} {07,08} {01,02,03,09,10,11,12}                   8 edges
{01,03}  11 reject {05} {04,06} {07,08} {01,02,03,09,10,11,12}
{01,11}  12 reject {05} {04,06} {07,08} {01,02,03,09,10,11,12}
{05,06}  13 accept {04,05,06} {07,08} {01,02,03,09,10,11,12}                     9 edges
{04,05}  14 reject {04,05,06} {07,08} {01,02,03,09,10,11,12}
{05,12}  15 accept {07,08} {01,02,03,04,05,06,09,10,11,12}                      10 edges
{01,04}  16 reject {07,08} {01,02,03,04,05,06,09,10,11,12}
{06,10}  17 reject {07,08} {01,02,03,04,05,06,09,10,11,12}
{03,07}  18 accept {01,02,03,04,05,06,07,08,09,10,11,12}                        11 edges
{04,07}  19
{08,11}  20
{05,08}  21
{08,09}  22
{07,09}  23
{02,06}  24

Sum of the weights is 1+2+3+4+5+6+8+10+13+15+18=85
------------------------------------------------------
Note that the execution of the algorithm stopped when the number of accepted edges was 11, which is the number of nodes, minus one.

Second Part of The MST Problem: Using Prim's Algorithm

We can use the list of edges ordered by weight, plus a version of Prim's algorithm to determine the edges in a minimum cost spanning tree of G1. Assume that node 01 is the start node. Recall that Prim's algorithm works by maintaining a single tree, to which it adds one edge at a time. To add a new edge to the current subtree T, we pick a cheapest edge that leaves T. We start with just node 01, and use the list to find the cheapest edge that "leaves 01," which clearly must be the first edge in the list that has 01 as one of its ends. So that tells us that {01,02} is the first edge chosen by Prim's algorithm. Below we show the list with the first edge labeled, and we also show the set S of nodes currently connected by the tree that Prim's algorithm builds.
{02,03}  01
{02,09}  02
{04,06}  03
{07,08}  04
{09,10}  05
{03,12}  06
{10,12}  07
{11,12}  08
{10,11}  09
{01,02}  10 Prim #1 (cheapest edge leaving S={01}) Now S={01,02} C={03,04,05,06,07,08,09,10,11,12}
{01,03}  11
{01,11}  12
{05,06}  13
{04,05}  14
{05,12}  15
{01,04}  16
{06,10}  17
{03,07}  18
{04,07}  19
{08,11}  20
{05,08}  21
{08,09}  22
{07,09}  23
{02,06}  24
The next edge that Prim's algorithm will choose is a cheapest edge that has one end in S={01,02} and one end not in S={01,02}. We can find that edge by just going down the list, starting from the top, and selecting the first edge that has one end in S={01,02} and one end not in S={01,02}. In this case, we find the edge right away: {02,03}. Below we show the list with the first two edges labeled, and we also show the set S of nodes currently connected by the tree.
{02,03}  01 Prim #2 (cheapest edge leaving S={01,02}) Now S={01,02,03} C={04,05,06,07,08,09,10,11,12}
{02,09}  02
{04,06}  03
{07,08}  04
{09,10}  05
{03,12}  06
{10,12}  07
{11,12}  08
{10,11}  09
{01,02}  10 Prim #1 (cheapest edge leaving S={01}) Now S={01,02} C={03,04,05,06,07,08,09,10,11,12}
{01,03}  11
{01,11}  12
{05,06}  13
{04,05}  14
{05,12}  15
{01,04}  16
{06,10}  17
{03,07}  18
{04,07}  19
{08,11}  20
{05,08}  21
{08,09}  22
{07,09}  23
{02,06}  24
Going on in the same way until we have connected all the nodes, the work we perform looks like this:
------------------------------------------------------
WORK SET TWO - Prim List(Solution to The Second Part of The Problem) 
------------------------------------------------------
Using the weight-ordered edge list of the graph to find the order in which 
Prim's Algorithm would select the edges of a minimum cost spanning tree.

{02,03}  01 Prim #2 (cheapest edge leaving S={01,02}) Now S={01,02,03} C={04,05,06,07,08,09,10,11,12}
{02,09}  02 Prim #3 (cheapest edge leaving S={01,02,03}) Now S={01,02,03,09} C={04,05,06,07,08,10,11,12}
{04,06}  03 Prim #9 (cheapest edge leaving S={01,02,03,05,06,09,10,11,12}) Now S={01,02,03,04,05,06,09,10,11,12} C={07,08}
{07,08}  04 Prim #11 (cheapest edge leaving S={01,02,03,04,05,06,07,09,10,11,12}) Now S={01,02,03,04,05,06,07,08,09,10,11,12} C={}
{09,10}  05 Prim #4 (cheapest edge leaving S={01,02,03,09}) Now S={01,02,03,09,10} C={04,05,06,07,08,11,12}
{03,12}  06 Prim #5 (cheapest edge leaving S={01,02,03,09,10}) Now S={01,02,03,09,10,12} C={04,05,06,07,08,11}
{10,12}  07
{11,12}  08 Prim #6 (cheapest edge leaving S={01,02,03,09,10,12}) Now S={01,02,03,09,10,11,12} C={04,05,06,07,08}
{10,11}  09
{01,02}  10 Prim #1 (cheapest edge leaving S={01}) Now S={01,02} C={03,04,05,06,07,08,09,10,11,12}
{01,03}  11
{01,11}  12
{05,06}  13 Prim #8 (cheapest edge leaving S={01,02,03,05,09,10,11,12}) Now S={01,02,03,05,06,09,10,11,12} C={04,07,08}
{04,05}  14
{05,12}  15 Prim #7 (cheapest edge leaving S={01,02,03,09,10,11,12}) Now S={01,02,03,05,09,10,11,12} C={04,06,07,08}
{01,04}  16
{06,10}  17
{03,07}  18 Prim #10 (cheapest edge leaving S={01,02,03,04,05,06,09,10,11,12}) Now S={01,02,03,04,05,06,07,09,10,11,12} C={08}
{04,07}  19
{08,11}  20
{05,08}  21
{08,09}  22
{07,09}  23
{02,06}  24

Sum of the weights is 1+2+3+4+5+6+8+10+13+15+18=85
------------------------------------------------------
Your Homework Problem:

G2=(V,E) is a connected undirected graph whose vertex set V is equal to {01,02,03,04,05,06,07,08,09,10,11,12}. The edges of G2 are as follows, sorted by increasing weight.
 edge   weight

{07,12}  01  
{01,08}  02  
{07,08}  03  
{01,12}  04  
{08,12}  05  
{03,10}  06  
{05,10}  07  
{03,05}  08  
{05,07}  09  
{01,05}  10  
{05,08}  11  
{03,08}  12  
{06,09}  13  
{04,11}  14  
{01,07}  15  
{02,09}  16  
{02,06}  17  
{08,09}  18  
{08,10}  19  
{06,11}  20  
{09,07}  21
{04,07}  22
{04,06}  23
{06,12}  24
Your assignment is to find the edges of a minimum cost spanning tree of G2, and the sum of their weights, in exactly the same two ways that are illustrated by the examples above. When you do that, using Kruskal's Algorithm and Prim's Algorithm, you will create versions of "WORK SET ONE" and "WORK SET TWO" corresponding to G2. You will turn in those two work sets as your solution to the homework problem.

Directions For Submitting Solution: