Why does array size have to be 3^k+1 for cycle leader iteration algorithm to work?
The cycle leader iteration algorithm is an algorithm for shuffling an array by moving all even-numbered entries to the front and all odd-numbered entries to the back while preserving their relative order. For example, given this input: a 1 b 2 c 3 d 4 e 5 the output would be a b c d e 1 2 3 4 5 This algorithm runs in O(n) time and uses only O(1) space. One unusual detail of the algorithm is that it works by splitting the array up into blocks of size 3 k +1. Apparently this is critical for the algorithm to work correctly, but I have no idea why this is. Why is the choice of 3 k + 1 necessary in