Data Structures & AlgorithmsVery hardProduct-company placement
The weighted undirected graph A–B (1), A–D (6), A–E (4), B–C (6), B–D (4), C–D (1), C–E (4) has repeated weights. How many different minimum spanning trees does it have, and what is their weight?
- A. 1 MST of weight 10
- B. 4 MSTs of weight 10
- C. 3 MSTs of weight 10
- D. 24 MSTs of weight 10
Correct answer: C. 3 MSTs of weight 10
Every MST takes the same multiset of weights; process weight classes in increasing order and count how many ways each class can join the components left by lighter edges. Enumerating all 24 spanning trees confirms 3 reach the minimum 10.
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 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [56, 50, 20, 30, 4, 3, 9, 27, 5, 1]. After inserting…
- What does f(4) print? c void f(int n) { if (n <= 0) return; printf("%d", n); f(n - 2); printf("%d", n); f(n - 1); }
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [12, 2…
- DFS on the directed graph with adjacency lists A: –; B: ACF; C: FG; D: E; E: BC; F: A; G: A starts at A (scanning lists in the order…
- All suffixes of the string 'radar' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–2, 5–3, 6–3, 7–6, 8–6, 9–6. What are its diameter and radius, and which vertex/vertices form…