Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Points A(8,5), B(3,9), C(3,5), D(2,7), E(3,2) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|. What is the minimum total cost of joining all points so that every point is connected to every other (minimum spanning tree)?
- A. 16
- B. 14
- C. 30
- D. 17
Correct answer: B. 14
Prim or Kruskal on these complete Manhattan distances gives 14. Connecting everything to one hub costs 30, and summing each point's nearest neighbour is not a spanning tree either.
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
- Directed weighted graph on vertices A, B, C, D, E with edges D→C (0); B→D (2); A→D (-1); E→A (-1); B→C (0); B→A (-2); C→E (4); D→E (-1)…
- Array A = [7, 4, 7, 14, 7, 6, 2]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 2–4, 2–5, 4–6, 5–7, 7–8, 0–9 (parent–child). Every edge has…
- Points A(4,4), B(3,6), C(2,6), D(2,3), E(3,5), F(8,4) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–C (1), B–D (1), B–G (1), C–D (1), C–E (1), D–E (1), E–F (1), E–G (1)…
- Keys [7, 34, 44, 32, 10, 49, 20] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…