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

后端 未结 9 1211
既然无缘
既然无缘 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 15:13

    I can do it given O(N) scratch space -- copy to new array and copy back.

    EDIT: I am aware of the existance of an algorithm that will proceed through. The idea is to perform the swaps on the array of integers 1..N while at the same time mirroring the swaps on your array of large objects. I just cannot find the algorithm right now.

提交回复
热议问题