Firstly, it was one of four problems that we had to solve last year, and I could not find a suitable algorithm, so we can cope with a brute force solution.
Problem: Numbers are in a list that is not sorted and supports only one type of operation. The operation is defined as follows:
Given position i and position j, the operation moves the number at position i to position j without changing the relative order of the other numbers. If i> j, then the positions of numbers between positions j and i-1 increase by 1, otherwise, if i <j the positions of numbers between positions i + 1 and j decrease by 1. This operation requires i steps to find the number for move and j steps to find the position you want to move it to. Then the number of steps required to move a number of positions i to position j is equal to i + j.
We need to develop an algorithm that sets up a list of numbers, determine the optimal (in terms of cost) sequence of moves for rearranging the sequence.
Attempts:
Part of our research was devoted to NP-completeness, we make it a problem to solve and try to find a suitable transformation for any of the problems listed in Gary and Johnson's book “Computers and Inexorability” without any results. There is no direct reference (from our point of view) to such a variation in the book of Donald E. Knuth: "The Art of Programming". 3 Sort and search. We also analyzed sorting algorithms for linked lists, but none of them provide a good opportunity to find the optimal sequence of movements.
, , , , , , , , , , 1 n, , , .
, , , , , .
j, , , , , 8 .
:
n n + 1 ( , O (1)).
j: - , - , j.
n-1 ( ).
, .