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


I am surprised: Is a scugging algorithm possible that does not modify or copy the original list?

To illustrate this:

Imagine you have been given a list of items, the size of the list may be uncontrollable, but assume that it is too big (say, 10,000,000 items). You must print the items in the list in random order, and you have to do as quickly as possible. However, you should not do this:

  • Make a copy of the original list, because it is too large and copying will waste too much memory (maybe killing the available RAM borders);
  • Modify the original list, because it is sorted in some way and is sorted later on any other part.
  • Create an index list, because again, the list is too large and the copy is too much time and memory (explanation: this is the meaning of any other list, in which the number of elements similar to the original list is ).

Is this possible?

Added: More explanation.

  1. I want the list to be rotated randomly with all kinds of permutations (of course, assuming that we have the proper rend () function).
  2. I suggest that I make pointers, or a list of indices or any other list in the same number of elements similar to the original list, is clearly understood as inefficient by the original question. If you want you can create additional lists, but they should have serious orders of magnitude compared to the original list.
  3. The original list is like an array, and you can retrieve any item in its index in it (1). (That's why there is no double-linked list, where you need to iterate through the list to get the desired item.)

Added 2 : OK, Let's do it like this: You have 1 TB HDD filled with data items, each 512 bytes large (one sector). You want to copy this data into another 1 TB HDD while rotating all the items. You want to do as soon as possible (more than a single pass, etc.). You have 512 MB RAM, and do not trust swaps. (This is a theoretical scenario, I have nothing in practice, I just want to find the right algorithm. ITM.)

Here is a very simple proof that no PRNG scheme can be done:

There are two steps to considering PRNG: First of all, choose a PRNG and its initial position; Second, use PRNG to manipulate production. OK, it is possible that N! Possible permutations, you should at least N! In order to enter Step 2, different initial states should be required. This means that at the beginning of step 2 you should log 2 n! State bits, which are not allowed.

Although this does not cancel the plans, the algorithm receives new random bits of the environment as it goes. Maybe, a PRG, which reads its initial state lazy and still does not guarantee repetition, can we prove that it is not so?

Suppose we have the perfect shuffle algorithm, imagine that we start running it, and when it happens on halfway, we sleep on the computer. Now the complete status of the program has been saved elsewhere. Let s set all possible states, this halfway program can be done.

Since the algorithm is correct and guaranteed to terminate, a function is F , which is given saved string of state and bits for any long period of time. Creates a valid order of disks and completes the shuffle writes. The computer only executes this function. But consider it as a mathematical function:

f : (s & bar; bits) and rrr; f to some arbitrary string of bits Pass, then see the result.)

g : s and rarr;

The remainder of the evidence shows that at least in the domain of live Although it is true, at least s should have several elements, and if set aside in spite of the choice of algorithm, and c n / 2 Therefore, at least log 2 N C N / 2 on the path of the bits, the requirements of the program In violation

I'm not sure how to prove the last bit, however, because depending on the algorithm, or set-to-to-to-read Or can be set-to-to-right-low enterpp. I suspect that there are some clear principles of information theory that can cut a knot. Anyone marking this community wiki in the candidates will supply it.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -