Fastest algorithm for circle shift N sized array for M position
If you want O(n) time and no extra memory usage (since array was specified), use the algorithm from Jon Bentley’s book, “Programming Pearls 2nd Edition”. It swaps all the elements twice. Not as fast as using linked lists but uses less memory and is conceptually simple. shiftArray( theArray, M ): size = len( theArray ) … Read more