I have a two-dimensional array of ints, for example:
int [][] board=
{
{23,17,3,29,12,10},
{17,4,11,12,10,19},
{32,33,25,25,28,35},
{27,29,24,25,23,37},
{29,40,34,26,24,39},
{23,37,29,36,31,3}
}
I don't want to change the columns of this array at all; however, I would like to swap the rows so that the most similar rows are grouped together. Similar in this case means most number of equal elements.
Edit: Similar rows means, if one row has 1,2,3,4,5,6 and another has 1,2,3,4,9,10 They have 4 similarities.
What's the best way to do this?
Note: the most number of rows I will have in my array is around 100 and the most number of elements in each row will be 10 so the complexity does matter as pointed out!