UGC NET CS 2020Data Structures and Algorithms › Graph AlgorithmsVerified
UGC NET CS 2020 PYQ: Consider the undirected graph below: Using Prim’s algorithm to construct a minimum spanning tree starting…
Consider the undirected graph below:

Using Prim’s algorithm to construct a minimum spanning tree starting with node $a$, which one of the following sequences of edges represents a possible order in which the edges would be added to construct the minimum spanning tree?
- A$(a,b), (a,h), (g,h), (f,g), (c,f), (c,i), (c,d), (d,e)$Correct answer
- B$(a,b), (b,h), (g,h), (g,i), (c,i), (c,f), (c,d), (d,e)$
- C$(a,b), (b,c), (c,i), (c,f), (f,g), (g,h), (c,d), (d,e)$
- D$(a,b), (g,h), (g,f), (c,f), (c,i), (f,e), (b,c), (d,e)$
Answer
(A) $(a,b), (a,h), (g,h), (f,g), (c,f), (c,i), (c,d), (d,e)$
Approach
From the figure the edges are: $a\!-\!b=4$, $a\!-\!h=8$, $b\!-\!c=8$, $b\!-\!h=11$, $c\!-\!i=2$, $c\!-\!f=4$, $c\!-\!d=7$, $d\!-\!f=14$, $d\!-\!e=9$, $i\!-\!h=7$, $i\!-\!g=6$, $h\!-\!g=1$, $g\!-\!f=2$, $f\!-\!e=10$. Prim starts at $a$: the only cut edges are 4 and 8, so the first edge must be $(a,b)$. After $\{a,b\}$ the min cut edge is 8, a tie between $(a,h)$ and $(b,c)$; choosing $(a,h)$ gives tree $\{a,b,h\}$. The lightest cut edge is now $(h,g)=1$, then $(g,f)=2$, then $(c,f)=4$, then $(c,i)=2$, then $(c,d)=7$, and finally $(d,e)=9$ (since $d\!-\!f=14$). This is exactly sequence A, and every step matches the minimum-weight cut edge, so it is a valid Prim order. Options B and D are impossible because they pick $(b,h)=11$ or $(g,h)=1$ before the tree is adjacent to those edges; $(b,h)$ is never the minimum cut edge after $(a,b)$. (Note: choosing $(b,c)$ instead also yields a valid MST order, namely option C, but only A is the answer keyed here.)
Reviewed by UGC IQ Editorial Team.