Kruskal’s Algorithm Elaicca Ronna Ordoña
A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum length of cable needed? Avonford Fingley Brinleigh Cornwell Donster Edan Example
A F B C D E
The steps are: 1. Sort all the the weight of the edges in ascending order. 2. Pick the smallest edge. Check if it forms a cycle with the spanning tree formed so far. If cycle is not formed, include this edge. Else, discard it. 3. Repeat step#2 until there are (V-1) edges in the spanning tree.
A F B C D E List the edges in order of size: ED 2 AB 3 AE 4 CD 4 BC 5 EF 5 CF 6 AF 7 BF 8 CF 8 Kruskal’s Algorithm
Select the shortest edge in the network ED 2 Kruskal’s Algorithm A F B C D E
Select the next shortest edge which does not create a cycle ED 2 AB 3 Kruskal’s Algorithm A F B C D E
Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 (or AE 4) Kruskal’s Algorithm A F B C D E
Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 AE 4 Kruskal’s Algorithm A F B C D E
Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 AE 4 BC 5 – forms a cycle EF 5 Kruskal’s Algorithm A F B C D E
All vertices have been connected. The solution is ED 2 AB 3 CD 4 AE 4 EF 5 MST: 18 Kruskal’s Algorithm A F B C D E
A BC D E F G H I J Complete Graph
A BC D E F G H I J AABD BB B CD JC C E F D DH JEG FFGI GGIJ HJJI
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Sort Edges
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Cycle Don’t Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Cycle Don’t Add Edge
A BC D E F G H I J B B D J C C E F D DH J EG F F G I G G I J HJ JI 1 AD 4 BC 4 AB Add Edge
A BC D E F G H I J A BC D E F G H I J Minimum Spanning TreeComplete Graph