Professional Documents
Culture Documents
ASSIGNMENT - 4
Spanning Tree
DONE BY :
K. R. VIKRAM - CS21B1020
3RD YEAR CSE – NIT PY
Input and Output
GIVEN GRAPH
Let ‘A’ be the source vertex
Iteration 1:
• For each vertex v in S (which is just A for now),
find the edge with the minimum weight from v
to a vertex in V-S.
• In this case, the minimum weighted edge is 2,
from A to B.
Iteration 2:
• For each vertex v in S (which are A and B now),
find the edge with the minimum weight from v
to a vertex in V-S.
• The minimum weighted edges are 3 (from B to
C) and 6 (from A to D). We choose the edge
with weight 3.
Iteration 3:
• For each vertex v in S (which are A, B, and C
now), find the edge with the minimum weight
from v to a vertex in V-S.
• The minimum weighted edge is 5 (from B to
E).
Iteration 4:
• For each vertex v in S (which are A, B, C and E
now), find the edge with the minimum
weight from v to a vertex in V-S.
• The minimum weighted edge is 6 (from A to
D).
Complexities
The time complexity for the given algorithm will be - O(E log V)
Here,
E → the number of Edges and
V → the number of Vertices
It uses heap sort to find the minimum weighted edge, so the space complexity
of the priority queue is O(V)
THANK YOU