What is a minimum spanning tree (MST)?
Why Interviewers Ask This
Mid-level Data Structures & Algorithms roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
A Minimum Spanning Tree (MST) of a connected weighted undirected graph is a subset of edges that connects all vertices with the minimum possible total edge weight, forming a tree (no cycles, V-1 edges). Two classic MST algorithms: (1) Kruskal's algorithm: Greedy. Sort all edges by weight. Add an edge if it doesn't create a cycle (use Union-Find to check). Repeat until V-1 edges added. Time: O(E log E) for sorting + O(E α(V)) for Union-Find operations ≈ O(E log E). Best for sparse graphs (few edges); (2) Prim's algorithm: Greedy. Start from any vertex. Maintain a set of visited vertices. Repeatedly add the minimum weight edge that connects a visited vertex to an unvisited one. Use a priority queue. Time: O((V+E) log V) with binary heap, O(V²) with adjacency matrix (better for dense graphs). Applications: (1) Network design — minimum cost to connect all nodes (network cabling, pipeline, road construction); (2) Cluster analysis; (3) Image segmentation; (4) Approximation algorithms for NP-hard problems (TSP); (5) Borůvka's algorithm for parallel MST computation.
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Data Structures & Algorithms project.