GATE Computer Science · Programming, Data Structures, and Algorithms · medium

A connected undirected weighted graph G has 8 vertices and 15 edges with distinct positive edge weights. How many edges are in the Minimum Spanning Tree (MST) of G, and how do Prim's and Kruskal's algorithms compare on G?

Published · Last updated · checked before publication — how we verify questions

Options

  • A8 edges, and Kruskal's algorithm produces a lighter spanning tree than Prim's
  • B7 edges, and Prim's and Kruskal's produce different trees when weights are distinct
  • C7 edges, and both algorithms produce the same unique Minimum Spanning TreeCorrect answer
  • D14 edges, retaining the graph edges except the single heaviest edge in G

Answer: C. 7 edges, and both algorithms produce the same unique Minimum Spanning Tree

A spanning tree of a connected graph with n vertices always has exactly n - 1 edges, so with 8 vertices the MST has 7 edges, regardless of the 15 edges in the graph. The number of edges in G is a distractor. The second part depends on uniqueness: when all edge weights are distinct, no two spanning trees can tie for minimum weight, so the MST is unique. This follows from the cut and cycle properties, since for every cut the lightest crossing edge is unique and must belong to the MST. Prim's and Kruskal's are both correct MST algorithms, so each must output this single tree, though they add edges in different orders (Prim grows one component from a start vertex, Kruskal merges components in global weight order). The common trap is thinking that different construction orders imply different results. Different results can occur only when ties in weight allow several MSTs.

Why the other options are wrong

  • A. 8 edges, and Kruskal's algorithm produces a lighter spanning tree than Prim's — A tree on 8 vertices has 7 edges, not 8, since an 8-edge subgraph on 8 vertices must contain a cycle. Also, both algorithms return a minimum weight tree, so neither can be lighter than the other.
  • B. 7 edges, and Prim's and Kruskal's produce different trees when weights are distinct — This gets the edge count right but the comparison wrong. Distinct weights make the MST unique, so Prim's and Kruskal's must return the same tree. Different trees are possible only when equal weights create ties.
  • D. 14 edges, retaining the graph edges except the single heaviest edge in G — Deleting only the heaviest edge leaves 14 edges on 8 vertices, which still has many cycles and is not a tree. An MST must have exactly n - 1 = 7 edges, and the heaviest edge need not be the only one removed or even removed at all.

All Programming, Data Structures, and Algorithms questions and the topic overview →

GATE is a mark of the Indian Institute of Science and the Indian Institutes of Technology. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by the GATE Committee.