Random sequence iteration in O(1) memory?

前端 未结 6 1517
[愿得一人]
[愿得一人] 2021-02-19 07:58

Say you want to iterate over a sequence [0 to n] in a random order, visiting every element exactly once. Is there any way to do this in O(1) memory, i.e. without creati

6条回答
  •  旧时难觅i
    2021-02-19 08:14

    No there is not, think about it, somewhere the program has to remember the places it has visited. If there is an iterator that can randomly access them all, the iterators internals would have to keep track of this somehow and you would still be using the memory.

提交回复
热议问题