How to compute the absolute minimum amount of changes to convert one sortorder into another?

后端 未结 8 836
走了就别回头了
走了就别回头了 2021-02-04 06:04

Goal

How to encode the data that describes how to re-order a static list from a one order to another order using the minimum amount of data possible?

8条回答
  •  半阙折子戏
    2021-02-04 06:47

    I am not sure that analyzing the swaps gets you anything; as you say they can undo each other, and lead to confusing results.

    I believe that your best option is to identify, in the re-ordered list, the segments of that list that are not-reordered with respect to the original list, even if they start in a new location. In your example, this is the segment from 30 to 60. So in a sort of run length encoding, I would send back a segment map that describes locations and lengths.

    Again, using your example data : a list of ordered start index, length :

    { (9, 1) , (3, 4) , (1, 1) , (8, 1) , (7, 1) , (2, 1) }

    seems like the smallest amount of info you can send back. The compressability of the data depends on the number and size of segments held in common.

    (Edit) Actually, it occurs to me that there are going to be some data sets where a swap list will be shorter, if the number of swaps is small. But there will probably be some cutover point where run length encoding does better; in that case I would say compute both and pick the smaller one.

提交回复
热议问题