I have 2 sets of integers, A and B, not necessarily of the same size. For my needs, I take the distance between each 2 elements a and b (integers) to be just abs(a-b)
.
I am defining the distance between the two sets as follows:
My question is, is the following algorithm (just an intuitive guess) gives the right answer, according to the definition written above.
D
of size m X n
, with D(i,j) = abs(A(i)-B(j))
D
, accumulate it, and delete the row and the column of that element. Accumulate the next smallest entry, and keep accumulating until all rows and columns are deleted.for example, if A={0,1,4}
and B={3,4}
, then D
is (with the elements above and to the left):
3 4
0
3 4
1
2 3
4
1 0
And the distance is 0 + 2 = 2
, coming from pairing 4
with 4
and 3
with 1
.