Solution:
We use divide and conquer. The base case n=1 is clear. Let f(n) denote the number of moves required for n numbers. Let x=⌈n/2⌉ and y=⌊n/2⌋. Then, William can reach his goal by the following process:
- Use f(x) moves to make the first x numbers a strictly decreasing sequence.
- Use f(y) moves to make the last y numbers a strictly decreasing sequence.
- Add one to all the numbers, taking n moves. At this point, all the numbers are greater than 1.
- Take the reciprocal of all the numbers, using n moves. At this point, all the numbers are in (0,1). Moreover, the first x numbers and the last y numbers form a strictly increasing sequence.
- Finally, add one to the last y numbers.
Hence, we have
f(n)≤f(⌈2n⌉)+f(⌊2n⌋)+2n+2n
giving f(n)=O(nlogn).
Double Counting Solution to (b)
Take B=0.01, and assume n is sufficiently large. Assume for contradiction that William has an algorithm for all possible initial numbers. We first note that if William uses less than x moves, then he can keep adding one to the last number until he uses exactly x moves. We henceforth assume that William has an algorithm that uses x≤0.01nlogn moves.
Take arbitrary initial numbers. We claim that if William always has an algorithm that results in the final numbers being increasing after x moves, then he in fact has an algorithm which can result in the final numbers being in any given ordering after x moves. This is because he can permute the indices of the initial numbers, operate on the permuted numbers to be increasing, and then take the permutation back such that the final numbers are now in the specified ordering after applying x moves (note that each move only acts and depends on one of the values.) In particular, this implies that by applying x moves, William can produce ≥n! possible final states. We now claim this is impossible.
Indeed, there are (n−1x+n−1) ways to distribute x moves to each of the n numbers. Moreover, there are two options for each move, giving 2x choices across all the x moves. Thus, William has
2x(n−1x+n−1)
choices of moves. When n is sufficiently large, we have
2x(n−1x+n−1)≤20.01nlogn(n−1)!(x+n−1)n−1≤e0.01nlogn(10n)n(0.1nlogn)n=n0.01n(logn)n=n0.01nnloglogn<(10n)n<n!
which is a contradiction.
Constructive Solution to (b)
By shifting B it suffices to prove this for sufficiently large n (for the smaller ones just make sure Bnlogn<1.) We now prove the result when n=k2 is a perfect square; the general case follows by shifting B appropriately. Choose the xi such that
xk2−k+1>xk2−2k+1>…>x1>xk2−k+2>xk2−2k+2>…>x2…>xk2>xk2−k>…>xk.
One may check that there exists no strictly increasing or decreasing subsequence of the {xi} of length >k. Now, if William uses less than Bk2log(k2) moves, then evidently there exists at least k2/2 elements on which he applies at most 2Blog(k2) moves. Let ⌈2Blog(k2)⌉=N; note that the number of possible sequences of moves that can be applied to each of these ≤k2/2 elements is ≤2N+2N−1+…+1<2N+1. Note that N=Θ(logk2) and so 2N+1=kΘ(1); hence by choosing a sufficiently small B we can ensure that 2N+1<k/2. This now implies that there exists a set S of >k elements on which the same sequence of moves are applied. Note by our choice of {xi} we know that within S, there exists both a pair (xi,xj) for which i<j and xi<xj, and a pair where i<j yet xi>xj. But note that any composition of moves acts as a rational function which is monotonic on (0,∞) (as it has no roots or poles within the given domain.) Hence this implies that either the increasing or decreasing pair must become decreasing after being operated upon by the same sequence of moves, and hence William has not achieved his goal, a contradiction. This thus proves the problem for an appropriate choice of B.