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 3288186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:34:43+00:00 2026-05-17T20:34:43+00:00

I have a two-dimensional array of ints, for example: int [][] board= { {23,17,3,29,12,10},

  • 0

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!

  • 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-17T20:34:44+00:00Added an answer on May 17, 2026 at 8:34 pm

    This question reduces to the traveling salesman problem. If you think of each row as being a city and then define some distance function which computes the distance between two rows. The question is how to order the rows so that the distance is minimized. This problem is NP-Complete and cannot be solved in a reasonable amount of time for 100 rows. The brute-force solution for this would require O(N!) computations. There are heuristic algorithms (algorithms that get close to the best answer) that will solve this in a reasonable time.

    Traveling Salesman Problem (Wikipedia)

    One example is to use a greedy algorithm. Choose one row at random, this is row 1. Then choose the closest row to row 1 as row 2. Then choose the closest row to row 2 as row 3. Run until all the rows are chosen. This is not a very optimal solution.

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

Sidebar

Related Questions

I have a two-dimensional array. When I print/dump this I get the following My
I have a simple, two dimensional array like this: Array ( [0] => Array
I have a two dimensional array that I need to load data into. I
I have a two-dimensional array (of Strings) which make up my data table (of
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have a two-dimensional array, say 0 0 0 0 0 0 2 3
I have a two dimensional array that I need to rotate 90 degrees clockwise,
I have a two-dimensional array: function getMatrix(size) { var matrix = []; for (var
If I have a two-dimensional array in C# - how can I convert it

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.