Is it possible to rearrange an array in place in O(N)?

后端 未结 9 1210
既然无缘
既然无缘 2020-12-24 14:17

If I have a size N array of objects, and I have an array of unique numbers in the range 1...N, is there any algorithm to rearrange the object array in-place in the or

9条回答
  •  攒了一身酷
    2020-12-24 14:51

    The problem is one of applying a permutation in place with minimal O(1) extra storage: "in-situ permutation".

    It is solvable, but an algorithm is not obvious beforehand.

    It is described briefly as an exercise in Knuth, and for work I had to decipher it and figure out how it worked. Look at 5.2 #13.

    For some more modern work on this problem, with pseudocode:

    http://www.fernuni-hagen.de/imperia/md/content/fakultaetfuermathematikundinformatik/forschung/berichte/bericht_273.pdf

提交回复
热议问题