As input I have a 2D array PointXY[][] clusters
, which looks like this:
[[23.237633,53.78671], [69.15293,17.138134], [23.558687,45.70517]] . . .
[[47
Create a temporary float/double array of size [n][(n-1) * n] where input matrix is of the size [n][n-1].
Compute the euclidean distances of all the points in the lower part of the matrix with all the points in the first row and store them at their respective positions in the temporary array.
Create a copy of each temporary sub-array.
Perform any sorting operation on the copy, preferably selection sort as you only need to sort the array partially until the lowest n-1 elements are found.
Finally, create a new output array of size [n][n-1], correspond the lowest euclidean distances to their points, and store the sorted (n-1) element groups of (n-1) points right below their closest reference points.