MST Prim Worksheet
MST Prim Worksheet
Instructor: Prof. Ahmad Sharieh, Prof. Mohammad Abbadi, Dr Mohammed Khader, Mr. Abdullah
Abdalghafer 7
2
6
Apply the Prim’s algorithm on graph G from starting 9 4
from 1 , showing the priority queue Q (min-heap), the 5
arrays key[], and p[] at each step. Show the final MST and 2 3
the total cost. 8 5 8 3
Hint: use 7
-1 instead of Nill 1 4
99 instead of ∞
Initial Step: 1 2 3 4 5 6
Key 0 99 99 99 99 99
P -1 -1 -1 -1 -1 -1
Q
Step 2: u= 1 2 3 4 5 6
Key
P
Q
Step 3: u= 1 2 3 4 5 6
Key
P
Q
Step 4: u= 1 2 3 4 5 6
Key
P
Q
Step 5: u= 1 2 3 4 5 6
key
P
Q
Step 6: u= 1 2 3 4 5 6
Key
P
Q