Another “Wall Street” Brain Teaser

Another “Wall Street” Brain Teaser

You have a printer that randomly shuffles the order of pages of your papers. To put your work back in order, you proceed through the stack on the printer as follows:

Given a page pp, if neither p±1p\pm1 have been seen, create a new pile. If one of p+1p+1 or p1p-1 have been seen, add pp to the front of p+1p+1’s pile or the end of p1p-1’s pile. If both p±1p\pm1 have been seen, merge the two piles into one. What’s an upper bound on the maximum number of piles you’ll have at any moment while reconstructing an nn page document?

We can think of this process as a series of binary strings. Each step can be represented by St{0,1}nS_t \in \{0, 1\}^n with the bit at index pp set if that page has been seen. If we count the expected instances of “0101” as a function of t[0,1]t \in [0, 1]. Without too much effort, we see that E[f(t)]n(tt2)E[f\big(t)] \approx n(t - t^2). This is maximized around n/4n/4 when t=n/2t = n/2. When nn is large, the maximum exceeds its expectation by Θ(n1/2)\mathcal{\Theta}\big(n^{1/2}).