Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Points A(5,6), B(6,6), C(4,5), D(7,8), E(7,6) 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. 8
- B. 7
- C. 6
- D. 9
Correct answer: C. 6
Prim or Kruskal on these complete Manhattan distances gives 6. Connecting everything to one hub costs 9, 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
- Dictionary D = {bdc, bds, cat, gce, lpb, nig, pgm, rmm, seg, tgm, tgs, tms} (all words have 3 letters). Starting from the word 'pmm', a…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: C–D (1), B–C (1), C–E (1), C–F (1), A–D (1), A–C (1)…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [12, 16, 8, 10, 7, 10], where Mi has size p[i−1] × p[i]…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 8, 2, 10, 19, 2, 7], where Mi has size p[i−1] × p[i]…
- A trie keeps a counter at each node, and every word of the list W = ['a', 'c', 'a', 'a', 'cac', 'caa', 'bc', 'bcb'] is inserted once per…
- Tree with vertices 0 to 8, root 0, edges 0–1, 0–2, 1–3, 3–4, 2–5, 1–6, 1–7, 3–8 (parent–child). Vertex weights (vertex:weight) 0:10, 1:9…