Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:44:18+00:00 2026-05-13T16:44:18+00:00

Given 2N-points in a 2D-plane , you have to group them into N pairs

  • 0

Given 2N-points in a 2D-plane, you have to group them into N pairs such that the overall sum of distances between the points of all of the pairs is the minimum possible value.The desired output is only the sum.

In other words, if a1,a2,..an are the distances between points of first, second…and nth pair respectively, then (a1+a2+…an) should be minimum.

Let us consider this test-case, if the 2*5 points are :
{20,20},
{40, 20},
{10, 10},
{2, 2},
{240, 6},
{12, 12},
{100, 120},
{6, 48},
{12, 18},
{0, 0}

The desired output is 237.

This is not my homework,I am inquisitive about different approaches rather than brute-force.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:44:18+00:00Added an answer on May 13, 2026 at 4:44 pm

    You seem to be looking for Minimum weight perfect matching.

    There are algorithms to exploit the fact that these are points in a plane. This paper: Mincost Perfect Matching in the Plane has an algorithm and also mentions some previous work on it.


    As requested, here is a brief description of a “simple” algorithm for minimum weighted perfect matching in a graph. This is a short summary of parts of the chapter on weighted matching in the book Combinatorial Optimization, Algorithms and Complexity by Papadimitriou & Steiglitz.

    Say you are given a weighted undirected graph G(with an even number of nodes). The graph can be considered a complete weighted graph, by adding the missing edges and assigning them very large weights.

    Suppose the vertices are labelled 1 to n and the weight of edge between vertices i and j is c(i,j).

    We have n(n-1)/2 variables x(i,j) which denote a matching of G. x(i,j) = 1 if the edge between i and j is in the matching and x(i,j) = 0 if it isn’t.

    Now the matching problem can be written as the Linear Programming Problem:

    minimize Sum c(i,j) * x(i,j)

    subject to the condition that

    Sum x(1,j) = 1, where j ranges from 1 to n.

    Sum x(2,j) = 1, where j ranges from 1 to n.
    .
    .
    .

    Sum x(n,j) = 1, where j ranges from 1 to n.

    (Sum x(1,j) = 1 basically means that we are selecting exactly one edge incident the vertex labelled 1.)

    And the final condition that

    x(i,j) >= 0

    (we could have said x(i,j) = 0 or 1, but that would not make this a Linear Programming Problem as the constraints are either linear equations or inequalities)

    There is a method called the Simplex method which can solve this Linear Programming problem to give an optimal solution in polynomial time in the number of variables.

    Now, if G were bipartite, it can be shown that we can obtain an optimal solution such that x(i,j) = 0 or 1. Thus by solving this linear programming problem for a bipartite graph, we get a set of assignments to each x(i,j), each being 0 or 1. We can now get a matching by picking those edges (i,j) for which x(i,j) = 1. The constraints guarantee that it will be a matching with smallest weight.

    Unfortunately, this is not true for general graphs (i.e x(i,j) being 0 or 1). Edmonds figured out that this was because of the presence of odd cycles in the graph.

    So in addition to the above contraints, Edmonds added the additional constraint that in any subset of vertices of size 2k+1 (i.e of odd size), the number of matched edges is no more than k

    Enumerate each odd subset of vertices to get a list of sets S(1), S(2), …, S(2^n – n). Let size of S(r) be 2*s(r) + 1.

    Then the above constraints are, for each set S(r)

    Sum x(i,j) + y(r) = s(r), for i, j in S(r).

    Edmonds then proved that this was enough to guarantee that each x(i,j) is 0 or 1, thus giving us a minimum weight perfect matching.

    Unfortunately, now the number of variables has become exponential in size. So the simplex algorithm, if just run on this as it is, will lead to an exponential time algorithm.

    To get past this, Edmonds considers the dual of this linear programming problem (I won’t go into details here), and shows that primal-dual algorithm when run on the dual takes only O(n^4) steps to reach a solution, thus giving us a polynomial time algorithm! He shows this by showing that at most O(n) of the y(r) are non-zero at any step of the algorithm (which he calls blossoms).

    Here is a link which should explain it in a little more detail: http://www.cs.ucl.ac.uk/staff/V.Kolmogorov/papers/blossom5.pdf , Section 2.

    The book I mentioned before is worth reading (though it can be a bit dry) to get a deeper understanding.

    Phew. Hope that helps!


    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You are given a list of distances between various points on a single line.
There is a points given in two dimensional plane and I want to count
Given N points in a 3D space, how to find the smallest sphere that
I've run simulations which have given me data points corresponding to X number of
Given n points on the plane. No 3 are collinear. Given the number k.
Let's imagine we have a plane with some points on it. We also have
I have a set of points on the infinite (well, double precision) 2D plane.
I have a set of point (x,y) on a 2d plane. Given a point
So, I have this algorithm to calculate cross-section of 3D shape with plane given
Given a set of points in the plane T={a1,a2,...,an} then Graphics[Polygon[T]] will plot the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.