What is the fastest algorithm for circle shifting array for M positions? For example, [3 4 5 2 3 1 4] shift M = 2 positions should be [1 4 3 4 5 2 3
[3 4 5 2 3 1 4]
[1 4 3 4 5 2 3
See this if you are interested in a Java implementation:
Programming Pearls: Circular Left/Right Shift Operation