Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

Applying Kruskal’s algorithm to the GigaFibre scenario

In step 1 of Kruskal's algorithm each of the edges are listed in the graph ordered by the number associated with each edge.

Now you have looked at the algorithm, it’s time to apply it!

In this step you will apply Kruskal’s algorithm to the GigaFibre scenario, working through it step by step. We have set it out just like an algorithm, hence its repetitive nature.

Follow it through below and see if it gets you to the same answer as you did in a previous activity.

Applying Kruskal’s algorithm: step 1

In step 1 of Kruskal’s algorithm each of the edges are listed in the graph ordered by the number associated with each edge. The table below lists the edges in ascending order starting from the smallest number at the top:

Source Destination Distance
Manchester Leeds 57
Glasgow Edinburgh 67
Lancaster Manchester 73
Lancaster Leeds 86
Grantham Birmingham 96
Newcastle Leeds 98
Manchester Birmingham 112
Grantham Leeds 115
Birmingham Bristol 124
Newcastle Lancaster 127
Cardiff Birmingham 142
Newcastle Edinburgh 147
Grantham London 161
Birmingham London 163
Bristol London 170
Newcastle Glasgow 194

Applying Kruskal’s algorithm: step 2

Moving on to Step 2 of Kruskal’s algorithm, add the first edge in the list. (As there are no edges at the moment the inclusion of the edge won’t create a cycle.) Consequently, the edge between Manchester and Leeds is added.

The figure below illustrates this. The thicker line indicates the inclusion of the edge into GigaFibre’s network.

Applying Kruskal’s algorithm: step 3

Step 3 of Kruskal’s algorithm repeats step 2 as there are still edges in the list which are not crossed off. In step 2 of Krukal’s algorithm the next edge in the list is added, from the top (so long as it doesn’t make a cycle). This next edge is Glasgow to Edinburgh. The inclusion of the edge does not create a cycle, so it is included in GigaFibre’s network.

The figure below illustrates which edges have now been included:

Graph showing the edges included so far, with the addition of the edge between Glasgow and Edinburgh.

Next, we repeat step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Lancaster to Manchester. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates which edges have now been included:

Graph showing the edges included so far, with the addition of the edge between Lancaster and Manchester.

Next, we go back again to step 2 of Kruskal’s algorithm, of course, because there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Lancaster to Leeds. Now, the inclusion of the edge introduces a cycle between Leeds, Manchester and Lancaster. So we do not add this edge into GigaFibre’s network.

(Why would adding the edge to the network not make a minimum cost network? To connect 3 cities together we only need 2 edges, the third would just be a waste.)

Next, we repeat step 2 of Kruskal’s algorithm as there are still edges in our list which are not crossed off. In step 2 we add the next edge in the list, from the top, so long as it doesn’t make a cycle. The next edge is Grantham to Birmingham. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network. The figure below illustrates what edges have so far been included in this exercise:

Graph showing the edges included so far, with the addition of the edge between Grantham and Birmingham.

Moving on again (do you notice the algorithm in these steps?)we go back to step 2 of Kruskal’s algorithm as there are still edges in our list which are not crossed off. In step 2 we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Newcastle to Leeds. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates what edges have now been included:

Graph showing the edges included so far, with the addition of the edge between Newcastle and Leeds.

Moving on, we go back to step 2 of Kruskal’s algorithm as there are still edges in our list which are not crossed off. In step 2, we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Manchester to Birmingham. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates what edges have been included so far in this exercise:

Graph showing the edges included so far, with the addition of the edge between Manchester and Birmingham.

Once again, we go back to step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Grantham to Leeds. The inclusion of the edge introduces a cycle between Leeds, Manchester, Birmingham and Grantham, so we do not add this edge into GigaFibre’s network.

And here we are again, moving on an repeating step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Birmingham to Bristol. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates what edges have been included so far:

Graph showing the edges included so far, with the addition of the edge between Birmingham and Bristol.

Once again, we repeat step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Newcastle to Lancaster. The inclusion of the edge introduces a cycle between Leeds, Manchester, Lancaster and Newcastle, so we do not add this edge into GigaFibre’s network.

Moving onwards again, we repeat step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Cardiff to Birmingham. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates what edges have been included now:

Graph showing the edges included so far, with the addition of the edge between Cardiff and Birmingham.

And again, we repeat step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Newcastle to Edinburgh. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network.

The figure below illustrates what edges have been included so far in this exercise:

Graph showing the edges included so far, with the addition of the edge between Newcastle and Edinburgh.

Moving on to step 3 of Kruskal’s algorithm, we go back to Step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top, so long as it doesn’t make a cycle. The next edge is Grantham to London. The inclusion of the edge does not create a cycle, so we include it in to GigaFibre’s network. The figure below illustrates what edges have been included.

Graph showing the edges included so far, with the addition of the edge between Grantham and London.

Moving on again, we go back to step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Birmingham to London. The inclusion of the edge introduces a cycle between Birmingham, Grantham and London. We do not add this edge into GigaFibre’s network.

And we move on again, back to step 2 as there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). Are you thinking lik an algorithm yet? The next edge is Bristol to London. The inclusion of the edge introduces a cycle between Birmingham, Grantham, London and Bristol, so we do not add this edge into GigaFibre’s network.

Continuing on, we repeat step 2 because there are still edges in our list which are not crossed off. In step 2 of Kruskal’s algorithm we add the next edge in the list, from the top (so long as it doesn’t make a cycle). The next edge is Newcaste to Glasgow. The inclusion of the edge introduces a cycle between Glasgow, Edinburgh and Newcastle. We do not add this edge into GigaFibre’s network.

Finally!

Finally, we observe that there are no more edges to consider so the algorithm terminates and we have completed the planning of GigaFibre’s network.

How did you find thinking like an algorithm?

This article is from the free online

Introduction to Technology-Assisted Decision-Making

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now