Alejandro
Alejandro

Reputation: 1159

Sort or partial sort minimizing comparisons

I'm looking to sort or partially sort a list of colors. From the most beautiful to the ugliest. The comparison of TWO colors at a time, is made by a human in a screen. I have 10 colors, I need to sort or partially sort them asking the less possible questions to the human. I’m open to use any data structures. I just need to ask for the least number of comparisons possible from the human. How can I do this? How many questions would I need to do a full sort? If it’s a partial sort what would the result look like? What can I expect from the result? Thank you

+1 for a javascript example ;)

EDIT: I can use concepts like (if a>b and b>c then a>c) so I can use complex sorting algorithms. I'm open to include as many concepts like that as possible

I need to able to sort 10 elements with less than 15 comparisons. Is it possible?

Upvotes: 1

Views: 129

Answers (1)

Trinadh Yerra
Trinadh Yerra

Reputation: 11

I do not understand the idea of beautiful and ugly color. But you got 10 colors, comparing two at once would be 10C2 = 45(no less, no more) number of combinations.

var colors = [color1, color2, ....];
var i = 0, j = 0, temp = "";
while (i < 10) {
   j = i + 1;
   while (j < 10) {
      if {user_chooses_color2} {
         temp = colors[j];
         colors[j] = colors[i];
         colors[i] = temp;
      }
      j++;
   }
   i++;
}

Upvotes: 1

Related Questions