Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
An undirected graph has edges (u–v: weight) A–C:16, B–C:30, C–D:17, A–D:2, A–B:3, B–D:12. What is the weight of its minimum spanning tree?
- A. 23
- B. 21
- C. 17
- D. 80
Correct answer: B. 21
Kruskal's algorithm sorts edges by weight and adds the cheapest one that does not form a cycle (checked with union-find) until all vertices are connected, giving a total MST weight of 21. Simply taking the 3 globally lightest edges without checking for cycles can give a different (and possibly disconnected or cyclic) total, 17.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Undirected graph edges: C–D, D–B, C–B, A–C, A–B, A–D. Using a BFS 2-colouring, is this graph bipartite?
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…
- Keys 5, 22, 60, 78, 66, 47, 79, 17, 35 are inserted in this order into an empty BST. Using the BST-specific LCA algorithm (walk down from…
- Keys 41, 51, 61 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…
- Build a binary min-heap in place from the array [50, 42, 62, 89, 76, 45, 3, 82] using bottom-up heapify (sift-down from the last internal…