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

后端 未结 8 681
走了就别回头了
走了就别回头了 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:37

    A quick fix might be to use a Zobrist hash to spot cases where you go back to a prior order. That is, after each swap, calculate a hash based on the permutation you reach. Each hash maps to the shortest sequence of swaps found so far for that particular permutation.

    This can easily be extended with a bit of exploratory searching - the Zobrist hash was invented as a way to optimise game tree searches.

    It's easy to give a strict lower bound to the number of swaps, of course - the number of items that are not in their required locations. Whether that lower bound is actually achievable, though, is a more difficult problem.

提交回复
热议问题