| > Looking at the tail sequence starting at s_i, we know it must end in 1. That means s_i is N+1 below the tail. I think the first sentence is very confusing, as the two most obvious ways to interpret it are wrong: 1. The tail sequence beginning at s_i consists of just 1 and -1 values, and it's certainly not the case that the "end" (last element) of that sequence must be 1 -- indeed, in the example it's -1. 2. What if we interpret "the end of the tail sequence beginning at s_i" as the sum of that sequence? But then this is also not always true: You can easily construct a tail sequence where this sum is much higher than 1. I think the intended meaning is: "We know that the last element in the sequence of all partial sums must be 1 [because there is in total one more 1 than -1 in the original sequence, and the rest cancel in pairs]." I.e., with no mention of s_i at all (yet). But even this is not enough to establish that the partial sums in just the tail sequence never dip below 1, which is required for the next step (rotating it to the front) to go through. I think there's a much clearer way to prove this, which actually makes use of the "rightmost lowest" choice of i: Suppose to the contrary that some j > i exists such that the sum of elements at positions i+1, i+2, ..., j is N' <= 0. Then this contradicts the "rightmost lowest" choice of i, since the sum of the first j elements of the entire sequence is N+N' <= N (at least as low) and j > i (strictly to the right). That contradiction establishes that the tail sequence is itself free of dangerous dips. To establish that the sum of all elements in the sequence is 1-N (which is needed to show that rotating it to the start will be enough to boost the original "head" sequence to safety), it's enough to observe that the entire sequence sums to 1, and the head sequence sums to N, so what's left (which is exactly the elements of the tail sequence) must sum to 1-N. |
Fair. You clearly engage with my article on a real level. More comments like yours will probably make my writing better. So, thanks!
That said, the code does precisely define s_i, which is s[i] in linearized notation. I scribbled the article together at 2am after a long day at work because a colleague asked for it and assume that you know APL or are at least willing try reading the code blocks.
> I think there's a much clearer way to prove this...
Honestly, I'm not a fan of arguments by contradiction when a clear constructive proof is available: The sequence of partial sums ends in 1; there is a rightmost partial sum that achieves the minimum partial sum, -N, say at index i. The remaining 1s and ¯1s, from index i+1 to the end, clearly must sum to N+1. Thus, left-rotating the sequence by i elements results in a strict ballot sequence. This is procedural and directly translates to the code.