Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Connected undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (1), A–D (4), B–C (1), B–D (2), C–D (6). Among all spanning trees whose total weight is strictly greater than the minimum spanning tree weight, what is the smallest possible total weight?
- A. 6
- B. 4
- C. 13
- D. 17
Correct answer: A. 6
The MST is A–C 1, B–C 1, B–D 2 = 4. The cheapest heavier tree swaps in A–B 3 for one of the weight-1 edges: 4 + 2 = 6. 4 is the MST itself, 13 the maximum spanning tree (6 + 4 + 3) and 17 the sum of all edges.
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
- Array A = [2, 24, 11, 16, 9, 22, 23, 10, 19]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- Strings a = "ccbab" and b = "bbbcaa". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→B, B→F, C→D, A→G, F→D, G→F, D→C, G→B, C→G (no weights). What is the number of…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (1), A–C (2), A–D (2), B–C (1), B–D (3), C–D (2). How many distinct…
- Directed acyclic graph on vertices A, B, C, D, E, F, G, H (every edge goes from a smaller to a larger letter) with weighted edges A→C (4)…
- Array A = [2, 1, 2, 3, 3, 4, 1, 5]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…