0

I have a question about ranking algorithm that might hasn't exist so far:

I have a list ordered by a score, for example a following list (denotes list-a):

enter image description here

Now I have new information to know that the list should be ranked as follow (denotes list-b):

enter image description here

The question in here is: How to construct a new ranking for the list-a follow restriction in list-b?

We can say that the new list must:

  1. It must follow the rank in the list-b
  2. Try to have less conflict with the rank in the list-a. (e.g about conflict: list-a says a>b, but now we say b>a => conflict).

The problem in here is the list-b doesn't have information about c, e, g (marked by red color in list-a). Now we need to construct a new ranking for list-a follow restriction in list-b.

My current solution:

Sure that we can solve it by using a brute force strategy as follow: add to the list-b the missing items c, e, g one by one and find the best place for it by:

  • Select one place for it in list-b (e.g: a > c > d > b > f)
  • Next check number of conflict with list-a, then select a position that have less conflict.

For example with c, we can do as follow:

enter image description here

When we have equal number of conflict for different position, then we select the first position (i guess). Just follow this way, we can add up to the final item.

This is my "bad way" to do it, so do you have any better idea for this problem? Because my list is really long (about 1 million items), if follow this way, it must be too expensive for computation.

Looking forward to hearing your suggestion.

sonvx
  • 411
  • 4
  • 7
  • How to determine where to put c when _every_ position is a conflict? Why did you pick that first choice rather than the last? (Also your terminology is super confusing. I know algorithms for if there are many possible unconflicted solutions, but I'm unsure how to handle if there are no unconflicted solutions. – Mooing Duck Jul 23 '14 at 23:18
  • Since items b and f swapped relative positions (b>f then f>b), you know that every element previously between them will have 2+ conflicts, and the best way to handle that is to put them just barely outside of between b and f. Is that right? – Mooing Duck Jul 23 '14 at 23:21

1 Answers1

0

Interesting problem. I am assuming that List B is going to also have the updated scores. So what you could do is make List A into a dictionary where item is the key and value is the score. Then you could iterate through list B and look up the items in constant time and update the score. You could then make the dictionary back into a collection and use built in sort. This would run in O(nlogn). Hope this helps

Maxqueue
  • 2,194
  • 2
  • 23
  • 55