Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between vertices i and j, with A = row 0): 0 9 6 13 9 9; 9 0 12 7 8 12; 6 12 0 12 2 12; 13 7 12 0 5 15; 9 8 2 5 0 2; 9 12 12 15 2 0. A tour visits every vertex exactly once and returns to the start. What is the minimum total weight of such a tour?
- A. 69
- B. 41
- C. 42
- D. 49
Correct answer: B. 41
Brute force over all 120 orders of the remaining vertices gives a minimum of 41. The greedy nearest-neighbour tour gives 42, and the largest tour weight 69 is a maximisation mistake.
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 = [29, 1, 24, 26, 13, 6, 8] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: A→D (7); C→E (0); D→B (2); F→A (2); C→D (5)…
- Keys are inserted in the order 56 88 11 17 79 25 68 into an empty binary search tree. Then the key 56 (which has two children) is deleted…
- Array A = [3, 1, 2, 3, 4, 1, 4, 1, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–H (1), C–D (1), D–E (1), D–H (1), E–G (1)…
- Weighted tree on vertices 0 to 6 with edges 0–1 (7), 1–2 (8), 0–3 (7), 0–4 (2), 0–5 (1), 1–6 (8). What is the largest possible sum of edge…