Data Structures & AlgorithmsHardGATE CS · ICPC regional
Points A(9,0), B(1,7), C(9,9), D(2,1), E(5,5), F(4,3) 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. 49
- B. 29
- C. 31
- D. 32
Correct answer: B. 29
Prim or Kruskal on these complete Manhattan distances gives 29. Connecting everything to one hub costs 49, 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 with edges A→C (-2); B→A (3); D→C (0); B→D (5); A→D (2); D→B (-4); C→B (-3). Source A. Run…
- Array A = [3, 4, 4, 1, 4, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); D→C (-2); D→E (-2); C→B (2); A→D (-2); C→A (2); B→E (-1). Source A…
- Directed weighted graph on vertices C, F, E, D, A (source C, target A) with edges: C→F (5); C→E (7); E→F (-4); F→A (1); E→A (1); C→A (7)…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 5 / 1 3 4. Goal board: 1 2 3 / 4 5 . A move slides a…
- Array [10, 28, 18, 27, 13, 14] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…