Connect all points with minimum total cost. Cost = Manhattan distance. Prim's MST: pick min-dist non-MST point, add to MST, update minDist.
[[0,0],[2,2],[3,10],[5,2],[7,0]]20Complete graph (all pairs). minDist[v]=cheapest edge from v to current MST. Greedy pick gives MST.
Trying every set of n −1 edges is exponential. Connecting everything as cheaply as possible is a minimum spanning tree.
Use Prim’s algorithm, which grows one tree from a starting point. Keep, for every point outside the tree, the cheapest edge that connects it to the tree. Each step, add the outside point with the smallest such cost. Then update the costs of the remaining points using the new tree point. After n steps, the sum of the chosen costs is the answer.
Connect everything cheaply means minimum spanning tree. On a dense graph, array based Prim beats sorting all edges.
Run the animation above on your own input, or watch the 1:50 video explanation of Min Cost to Connect All Points with a dry run and Java code.