Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
An undirected graph has edges (u–v: weight) A–B:3, A–C:21, A–D:19, A–E:17, D–F:13, D–B:29, C–B:27, C–E:2. What is the weight of its minimum spanning tree?
- A. 54
- B. 65
- C. 57
- D. 56
Correct answer: A. 54
Kruskal: sort edges and add the cheapest that does not form a cycle: CE(2), AB(3), DF(13), AE(17), AD(19) → 54. 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:1, B–C:8, C–D:10, A–E:11, C–F:11, A–C:5, E–F:6, F–B:6, what is the shortest-path distance from A to…
- An undirected graph has adjacency lists A:BCDEF B:AC C:AB D:AEG E:ADG F:A G:DE. Neighbours are always explored in alphabetical order…
- Keys 75, 97, 65, 30, 69, 78, 44, 25, 18 are inserted one by one into an empty binary search tree. What is the pre-order traversal?
- Keys 56, 66, 31, 58, 79, 72, 35, 77 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- Keys 17, 90, 39, 58, 63, 18, 37, 95 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is…
- An undirected graph has edges (u–v: weight) A–B:10, A–C:12, A–D:4, D–E:29, D–F:26, D–B:13. What is the weight of its minimum spanning tree?