Algorithm to print out a shuffled list, in-place and with O(1) memory

后端 未结 10 1391
野趣味
野趣味 2020-12-09 11:51

After reading this question I started to wonder: is it possible to have a shuffling algorithm which does not modify or copy the original list?

To make it clear:

10条回答
  •  独厮守ぢ
    2020-12-09 12:27

    You're not allowed to make a copy, modify it, or keep track of which elements you've visited? I'm gonna say it's not possible. Unless I'm misunderstanding your third criteria.

    I take it to mean you're not allowed to say, make an array of 10,000,000 corresponding booleans, set to true when you've printed the corresponding element. And you're not allowed to make a list of the 10,000,000 indices, shuffle the list, and print out the elements in that order.

提交回复
热议问题