GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Contract cheaper edges and count tied MST choices

5 questions solved the same way, newest first. Back to Algorithms

How these are solved

For a fixed weighted graph, include cheaper safe forest edges, contract their components, and count spanning choices among equal-weight links. All request the number or enumeration of MSTs.

2 marks · NAT
Report issue

Count MSTs after contracting forced light edges

Graph Algorithms

Question 59, GATE 2024: Undirected graph vertices a,b,c,d,e,f,g have weight-1 edges ab,af,cd,de; weight-2 edges ag,bg,fg,cg,dg,eg; weight-3 edges bc,fe; and no others. How many distinct minimum-weight spanning trees exist?
Tap to enlarge
Answer & solution

Official answer: 9

Step through it (11 steps)

Approach: Force uniquely lightest cut edges, contract them, then count independent minimum connections.

1. Derivation. Each weight 1 edge (ab, af, cd, de) is uniquely lightest across the cut isolating its noncentral endpoint b, f, c, e, respectively, so all four occur in every MST. Contracting them gives components L={a, b, f}, R={c, d, e}, and{g}. There are three weight 2 choices linking L to g and three linking R to g. A minimum tree uses one of each, giving 3×3=9 distinct MSTs, each weight 4+2+2=8. Weight3 links L–R cannot improve that value.

2. Explanation and checks. After contraction only three supervertices remain, requiring exactly two additional edges. Connecting g to the left component has three distinct original choices; connecting g to the right has another three. Each pair is acyclic and connects all seven original vertices once the four forced edges are restored. Choosing a weight-3 left–right link instead would require at least one further weight-2 edge and yield total at least nine rather than eight. Therefore it cannot contribute an alternative minimum tree.

Original paper, page 38 · Answer key

1 mark · NAT
Report issue

Graph Algorithms

Question 17, GATE 2021: Find the number of minimum-weight spanning trees in this undirected graph. Essential diagram: nine vertices in a 3×3 grid, named a,b,c (top row), d,e,f (middle), g,h,i (bottom). Edges and weights: ab=.1, bc=.1, de=.1, ef=.9, gh=.9, hi=.1, ad=.9, be=.9, cf=.9, dg=.1, eh=.1, fi=.1. There are no other edges.
Tap to enlarge
Answer & solution

Official answer: 3

Step through it (13 steps)

The seven weight 0.1 edges form a forest with two components: the top row of three vertices and the remaining six vertices. All seven cheap edges can be included without a cycle. Connecting these components requires one weight 0.9 edge; exactly the three vertical links between the top and middle rows do so. Each choice gives total weight 1.6, and any tree using fewer cheap edges is more expensive. Therefore exactly 3 MSTs.

A spanning tree on nine vertices needs eight edges. The seven cheap edges are acyclic and leave precisely two components, so Kruskal's algorithm accepts all seven before considering weight .9. Among the expensive edges only ad,be,cf cross that component cut; ef and gh stay within the lower component and create cycles. Thus each MST contains seven cheap edges and one of those three cross edges. This proves both attainability and exhaustiveness rather than merely counting three plausible trees.

Original paper, page 20 · Answer key

2 marks · NAT
Report issue

Graph Algorithms

Question 52, GATE 2014: How many distinct MSTs does the illustrated undirected weighted graph have? Textual equivalent: label left cluster vertices A top-left, B top-right, C middle-left, D center, E middle-right, F bottom-left; right triangle G bottom-left, H top, I bottom-right. Edges: AB=2, AC=2, AD=1, BD=2, BE=1, CD=2, CF=1, DE=2, DF=1, FG=2, GH=2, HI=1, GI=2. No other edges exist.
Tap to enlarge
Answer & solution

Official answer: 6

Step through it (15 steps)

1. Set up the reasoning. Run Kruskal by weight groups. Weight-one edges AD,BE,CF,DF,HI form a forest, so include them and contract each connected component before counting choices among weight-two edges.

2. Derive the result. The weight 1 edges form an acyclic forest and all are included before any weight 2 edge by Kruskal. In the left component, contraction leaves three parallel weight 2 choices joining its two weight 1 components. The long horizontal bridge of weight 2 is mandatory. In the right triangle, the weight 1 edge is mandatory and either of the two weight 2 edges connects the third vertex. Thus independent choices give 3·2=6 MSTs. The remaining left weight 2 edges internal to contracted components cannot be used.

3. Check the interpretation. After contraction, the left cluster has three parallel choices AB,BD,DE between its two components. FG is the only connection to the right cluster and is compulsory. On the right choose GH or GI. The independent choices yield 3×1×2 trees, each with eight edges and total weight 11.

Original paper, page 43 · Answer key

Descriptive
Report issue

Count distinct minimum spanning trees

Graph Algorithms

Question 15(b), GATE 2001: Undirected vertices n1,…,n6; edges (n1,n2,2),(n1,n3,8),(n1,n6,3),(n2,n4,4),(n2,n5,12),(n3,n4,7),(n4,n5,9),(n4,n6,4).
Question 15(b), GATE 2001: Undirected vertices n1,…,n6; edges (n1,n2,2),(n1,n3,8),(n1,n6,3),(n2,n4,4),(n2,n5,12),(n3,n4,7),(n4,n5,9),(n4,n6,4).
Question 15(b), GATE 2001: Undirected vertices n1,…,n6; edges (n1,n2,2),(n1,n3,8),(n1,n6,3),(n2,n4,4),(n2,n5,12),(n3,n4,7),(n4,n5,9),(n4,n6,4).
Tap to enlarge
Answer & solution

Answer: 2 (no official key was published)

Step through it (10 steps)

The unique cheapest edge crossing cut {n2} is n1–n2 (2), so every MST contains it. Similarly cut {n6} forces n1–n6 (3), cut {n3} forces n3–n4 (7), and cut {n5} forces n4–n5 (9). These four edges leave two components, {n1,n2,n6} and {n3,n4,n5}. Their cheapest connecting edges are n2–n4 and n6–n4, both weight 4. Either one completes a tree of weight 25; choosing both would create a cycle and require losing a forced edge. Hence there are exactly two MSTs.

Original paper, page 9

5 marks · Descriptive
Report issue

Enumerating all minimum spanning trees

Graph Algorithms

Question 22, GATE 1995: The weighted undirected graph has vertices A,B,C,D,E and edges AB=2, AE=3, BC=3, BD=4, CD=4, DE=5. Draw and count all minimum spanning trees. These are the edges visibly present in GFG p8. GateForum p15 omits the AB line while retaining a detached weight 2; also analyze that literal graph.
Tap to enlarge
Answer & solution

Answer: 2 minimum spanning trees, each of weight 12: {AB, AE, BC, BD} and {AB, AE, BC, CD} (no official key was published)

A spanning tree on five vertices has four edges. Graph, AB is the unique cheapest edge crossing the cut {A}, so it belongs to every MST. AE is the unique cheapest edge crossing {E}, and BC is the unique cheapest edge crossing {C}; these too are forced by the cut property. The three edges AB,AE,BC form a tree on A,B,C,E, with D still isolated. Connect D using either BD or CD, each of weight 4. Using DE of weight 5 instead would cost more. Thus the optimum total is 2+3+3+4=12 and there are exactly two choices.

Draw tree1 as E−(3)−A−(2)−B−(3)−C, with an additional B−(4)−D branch. Draw tree2 as the path E−(3)−A−(2)−B−(3)−C−(4)−D. The edge sets in the answer uniquely specify every diagram and show that both graphs are connected and acyclic. Forced edges plus the only two minimum connectors prove completeness, rather than merely exhibiting two examples.

If interpreted literally, A has only neighbor E, and {A,E} connects to the rest only through ED. Consequently AE=3 and ED=5 are forced. In the remaining BCD triangle, choose BC=3 and either BD=4 or CD=4. This gives exactly two spanning trees of minimum weight 15. The count happens to remain 2, but the trees and weights differ.

Original paper, page 8