Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Points A(1,7), B(2,4), C(4,9), D(8,8), E(2,7) 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. 18
- B. 15
- C. 13
- D. 14
Correct answer: C. 13
Prim or Kruskal on these complete Manhattan distances gives 13. Connecting everything to one hub costs 18, 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
- An undirected graph has the vertices G, Q, R, U, Y, Z and the edges Q–Z, Y–Q, G–Z, R–Z, G–R, Y–R. How many simple cycles does it contain…
- A directed acyclic graph has the vertices F, H, J, K, L, N, R and the arcs H→J, H→R, H→N, K→J, K→F, K→N, L→R, L→F, J→R, J→F, J→N, R→F. Two…
- A directed acyclic graph has the vertices B, H, K, O, W and the arcs K→B, K→W, K→O, B→H, B→O, W→O. Two players alternately move a single…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- A connected undirected graph has the vertices E, F, J, K, L, W, Y, Z and the edges Y–E, Y–W, E–Z, E–L, E–W, E–J, Z–L, Z–F, W–K. Parallel…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→C (7), B→E (5), D→B (7), D→C (2), C→B (9), C→E…