Data Structures & AlgorithmsHardIBM · Deloitte pattern
An undirected graph has edges (u–v: weight) A–B:4, B–D:7, A–D:15, A–C:29, B–C:28, C–D:29. What is the weight of its minimum spanning tree?
- A. 54
- B. 112
- C. 26
- D. 39
Correct answer: D. 39
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 39. Simply taking the 3 globally lightest edges without checking for cycles can give a different (and possibly disconnected or cyclic) total, 26.
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
- Keys 27, 96, 68, 47, 51, 92, 12 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree (edges on…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [G]; B: [C]; C: [B, D]; D: [C, F, G]; E: [F]; F: [D…
- Keys 35, 45, 55 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 60, 70, 80 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A binary tree has preorder traversal [90, 31, 36, 77, 58, 43, 83] and inorder traversal [31, 36, 43, 58, 77, 83, 90]. Reconstructing the…
- Undirected graph edges: A–D, D–C, B–C, C–A. Using a BFS 2-colouring, is this graph bipartite?