Back to the 2024 paper

Module 3: Graph and Tree Algorithms

20247m

Answer the following:
(i) Explain the concept of a Minimum Spanning Tree (MST) in a connected, weighted, undirected graph.
(ii) Compare and contrast Prim's and Kruskal's algorithms for finding the MST.
(iii) Analyze the time complexity of both algorithms and discuss their advantages and scenarios where one is preferred over the other.

Worked SolutionAI Assisted

MST Concepts, Prim vs Kruskal

(i) MST Concept

Connected, undirected, weighted G(V,E,w)G(V,E,w). Spanning tree TT has V−1V-1 edges, connects all vertices, acyclic. MST minimizes ∑e∈Tw(e)\sum_{e\in T} w(e); unique if weights distinct. Characterized by Cut Property (lightest edge crossing any cut in some MST) and Cycle Property (heaviest edge on any cycle not in MST). Applications: network design (least cable), clustering.

(ii) Compare Prim vs Kruskal

Feature Prim Kruskal
Growth Vertex-based: grows tree from start vertex, adds min edge crossing cut (inMST,rest)(inMST, rest). Edge-based: sorts all edges, adds min edge that doesn't form cycle (Union-Find).
Data structure Priority queue (heap) + key[]. Union-Find (Disjoint Set) + sorting.
Steps V−1V-1 iterations extract min vertex EE iterations over sorted edges
Complexity O(Elog⁡V)O(E\log V) heap, O(V2)O(V^2) array (dense), O(E+Vlog⁡V)O(E+V\log V) Fibonacci O(Elog⁡E)O(E\log E) sort dominates (≈O(Elog⁡V)\approx O(E\log V) as log⁡E≈log⁡V\log E ≈ \log V)
Graph type Good for dense (V2V^2 edges) Good for sparse (E≈VE≈V)
Requires Connected to get single tree; else spanning forest Works on forest naturally

Both greedy and optimal via cut property.

(iii) Time & Advantages / Preference

  • Prim: O(V2)O(V^2) without heap best for dense; O(Elog⁡V)O(E\log V) with heap. Advantage: single tree growing → early stop or distributed. Preferred when EE large, graph dense, or adjacency matrix.
  • Kruskal: O(Elog⁡E)O(E\log E) sort. Advantage: simple, sorts edges, handles disconnected, easy parallel sort. Preferred when EE small (sparse) or edges already sorted.

Overall both O(Elog⁡V)O(E\log V); choice depends on density: Prim for dense (E≫VE≫V), Kruskal for sparse (E≈VE≈V).

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.