Data Structures & AlgorithmsVery hardProduct-company placement
The weighted undirected graph A–E (19), A–F (20), B–F (2), C–D (25), C–E (10), C–F (7), D–E (18), D–F (8) has a unique MST. What is the weight of the SECOND-best spanning tree (the lightest spanning tree different from the MST)?
- A. 46
- B. 64
- C. 47
- D. 54
Correct answer: C. 47
The MST weighs 46. A second-best tree swaps exactly one MST edge for one non-tree edge that closes a cycle through it; the best swap adds 1, giving 47. Adding the lightest non-tree edge without removing the heaviest edge on its cycle is the trap.
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
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 91 nodes. How many leaves…
- What is the minimum number of edges m such that EVERY simple undirected graph with 13 vertices and m edges is guaranteed to be connected?
- Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- In how many different ways can 'aaaaaa' be split into a sequence of words from the dictionary {a, aa, aaa} (every character used, order…
- 0/1 knapsack with capacity 14: items (weight, value) = (7, 23), (4, 12), (5, 8), (4, 12), (6, 34). What is the maximum total value?
- The POSTORDER traversal of a BST with distinct keys is 10, 12, 25, 49, 53, 92, 88, 93, 76, 32. What are the height of the tree (edges on…