Professional Documents
Culture Documents
MST Kruskals Prims
MST Kruskals Prims
Brinleigh 5 Cornwell
3
4
8 6
8
Avonford Fingley Donster
7
5
4 2
Edan
We model the situation as a network, then the problem
is to find the minimum connector for the network
B 5 C
3
4
8 6
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
List the edges in
order of size:
B 5
C ED 2
AB 3
3 AE 4
4
8 6 CD 4
BC 5
8 EF 5
A D CF 6
7 F
AF 7
5 BF 8
4 CF 8
2
E
Kruskal’s Algorithm
8
A D
7 F
5
4
2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 create a cycle
C
ED 2
3 AB 3
4
8 6
8
A D
7 F
5
4
2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 create a cycle
C
ED 2
3 AB 3
4
8 6 CD 4 (or AE 4)
8
A D
7 F
5
4
2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 create a cycle
C
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8
A D
7 F
5
4
2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 create a cycle
C
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8 BC 5 – forms a cycle
A D EF 5
7 F
5
4
2
E
Kruskal’s Algorithm
All vertices have been
connected.
B 5
C The solution is
3 ED 2
4
8 6 AB 3
CD 4
8 AE 4
A D EF 5
7 F
5
4 Total weight of tree: 18
2
E
Prim’s Algorithm
Select any vertex
B 5 A
C
Select the shortest
3 edge connected to
4
8 6 that vertex
8 AB 3
A D
7 F
5
4
2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 any vertex already
C connected.
3 AE 4
4
8 6
8
A D
7 F
5
4
2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 any vertex already
C connected.
3 ED 2
4
8 6
8
A D
7 F
5
4
2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 any vertex already
C connected.
3 DC 4
4
8 6
8
A D
7 F
5
4
2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 any vertex already
C connected.
3 EF 5
4
8 6
8
A D
7 F
5
4
2
E
Prim’s Algorithm
All vertices have been
connected.
B 5
C The solution is
3 AB 3
4
8 6 AE 4
ED 2
8 DC 4
A D EF 5
7 F
5
4 Total weight of tree: 18
2
E
Some points to note