Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
An undirected graph has edges (u–v: weight) A–B:16, B–C:7, C–D:13, A–E:1, C–F:25, A–C:12, B–F:22, E–D:4. What is the weight of its minimum spanning tree?
- A. 23
- B. 55
- C. 46
- D. 44
Correct answer: C. 46
Kruskal: sort edges and add the cheapest that does not form a cycle: AE(1), ED(4), BC(7), AC(12), BF(22) → 46. Simply taking the 5 lightest edges may create a cycle.
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
- In the undirected graph with edges A–B:2, A–C:3, A–D:5, C–E:3, E–F:8, F–A:2, what is the shortest-path distance from A to B?
- An undirected graph has adjacency lists A:BCDF B:AC C:AB D:AE E:D F:A. Neighbours are always explored in alphabetical order. Which is the…
- Keys 37, 18, 57, 76, 72, 36, 64, 21 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…
- A max-heap is built by inserting 61, 86, 95, 83, 45, 47, 46 one by one. After a single extract-max (move last element to root, sift-down)…
- An undirected graph has edges (u–v: weight) A–B:30, A–C:9, A–D:11, D–E:14, A–E:25. What is the weight of its minimum spanning tree?
- Directed edges: A→B (6), A→C (6), C→B (-2), B→D (3). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…