D1, L5 1 Kruskal's and Prim's Algorithms
D1, L5 1 Kruskal's and Prim's Algorithms
1.
2.
3.
Prims algorithm
1.
2.
3.
4.
Example
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?
Brinleigh
Cornwell
Avonford
7
4
Fingley
5
2
Edan
Donster
2
E
Kruskals Algorithm
7
5
2
E
ED
AB
AE
CD
BC
EF
CF
AF
BF
DF
2
3
4
4
5
5
6
7
8
8
Kruskals Algorithm
ED 2
7
5
2
E
Kruskals Algorithm
ED 2
AB 3
7
5
2
E
Kruskals Algorithm
ED 2
AB 3
CD 4 (or AE 4)
7
5
2
E
Kruskals Algorithm
ED
AB
CD
AE
7
5
2
E
2
3
4
4
Kruskals Algorithm
7
5
2
E
ED
AB
CD
AE
BC
EF
2
3
4
4
5 forms a cycle
5
Kruskals Algorithm
The solution is
7
5
2
E
ED
AB
CD
AE
EF
2
3
4
4
5
Prims Algorithm
Select any vertex
7
5
2
E
AB 3
Prims Algorithm
3
6
AE 4
4
8
7
5
2
E
Prims Algorithm
3
6
ED 2
4
8
7
5
2
E
Prims Algorithm
3
6
DC 4
4
8
7
5
2
E
Prims Algorithm
3
6
CB 5 forms a cycle
EF 5
7
5
2
E
Prims Algorithm
The solution is
7
5
2
E
ED
AB
CD
AE
EF
2
3
4
4
5