6

There is an array with $n$ places. There is a stream of $n$ unique numbers that arrive at a random order (permutation selected uniformly at random).

Whenever a number arrives, we must put it somewhere in the array, and we are not allowed to move it later. The goal is to have as many numbers as possible (in expectation) in their correct location in the final array. The "correct location" is defined as the location where it would appear if the numbers were sorted.

What is known about this problem? What is the best expected success rate, and what algorithm attains it?

Notes:

  • A related question is: What is the fastest online sorting algorithm? . It discusses a situation in which items can be moved when new items arrive, and the goal is to minimize the running time.

  • I am mainly interested in maximizing the expected number of the correct positions. However, it is also interesting if there is a way to improve the probability that all numbers are in the correct position, above O(1/n!)

Erel Segal-Halevi
  • 5,994
  • 1
  • 23
  • 59
  • 2
  • Have you tried working through small cases ($n=2$, $n=3$, ...) to see what you can say for small values of $n$? 2. Should we assume the $n$ numbers are unique? If not, I suggest editing the question to define "correct location" more carefully.
  • – D.W. Jun 24 '16 at 16:45
  • 1
    Do you have distribution of data? The running time depends on more than just perfectly hitting the proper placement of elements. – Evil Jun 24 '16 at 17:09
  • My gut says that nothing can be done if you can not estimate ranks. For the first element you have no chance. Knowing some elements already, better estimates may possible. – Raphael Jun 26 '16 at 11:50
  • Maybe minimizing the number of inversions is easier than maximizing the number of correct positions. – adrianN Jun 27 '16 at 09:26
  • Do your original numbers (before the permutation) come from some random process, e.g., some particular distribution? Or are they arbitrary (i.e., they could be chosen by an adversary, and we want to know about worst-case performance for the worst possible set of numbers)? This will lead to different answers. – D.W. Jun 27 '16 at 18:03
  • @D.w. The original numbers are arbitrary. – Erel Segal-Halevi Jun 29 '16 at 09:33