Assume two lists of comparable items: u and s. Let INV(u) be the number of inversions in u.
I am looking for an efficient algorithm to insert the items of s into u with a minimal increase of INV(u).
Basically I would like to insert objects into a list while keeping it "as sorted as possible" while keeping the order of the first list.
Example:
u = [4,6,2,9,7]
INV(u) = 3 ((4, 2), (6, 2) and (9, 7)
s = [8,3,10]
one optimal solution u' = [3, 4, 6, 2, 8, 9, 7, 10]
INV(u') = 5 ((4, 2), (7, 2) and (9, 7) + (3,2), (8,7))
different optimal solution u' = [3, 4, 6, 2, 9, 7, 8, 10]
INV(u') = 5 ((4, 2), (7, 2) and (9, 7) + (3,2), (9,8))
As you can see there is no unique optimal solution.
I'd be glad for any sort of ideas or direction to look into.