Introduction to Prim's Algorithm
What is Prim's algorithm?
- Prim's algorithm is another method of finding a minimum spanning tree in a network
- It can be used when the information for a network is given as a graph or in a matrix
Start at any vertex and choose the edge of least weight that is connected to it
If there is a choice of edges of equal weight, either can be selected
Repeat STEP 2 until all of the vertices are added to the tree
Consider the network, G, below.
Using Prim’s algorithm, find a minimum spanning tree for G.
Edges added in the order: AB (15), BC (13), CE (12), BD (17)
State the total weight of the minimum spanning tree.
Add up the weight of the edges in the minimum spanning tree
15 + 13 + 12 + 17 = 57
The adjacency matrix of a network, is shown below.
A | B | C | D | E | |
A | - | 15 | 22 | 18 | 25 |
B | 15 | - | 13 | 17 | 24 |
C | 22 | 13 | - | 30 | 12 |
D | 18 | 17 | 30 | - | 21 |
E | 25 | 24 | 12 | 21 | - |
AB (15)
AB (15), BC (13)
AB (15), BC (13), CE (12)
AB (15), BC (13), CE (12), BD (17)
All vertices have been selected
You should have a list of the order in which the edges were selected
Edges added in the order: AB (15), BC (13), CE (12), BD (17)
Did this page help you?